Cashier.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cashier\storeapi\controller;
  11. use addon\printer\model\PrinterOrder;
  12. use app\storeapi\controller\BaseStoreApi;
  13. use addon\cashier\model\Cashier as CashierModel;
  14. class Cashier extends BaseStoreApi
  15. {
  16. /**
  17. * 交接班
  18. */
  19. public function changeShifts()
  20. {
  21. $res = (new CashierModel())->changeShifts($this->user_info, $this->site_id, $this->store_id);
  22. return $this->response($res);
  23. }
  24. /**
  25. * 班次数据
  26. */
  27. public function shiftsData()
  28. {
  29. $data = [
  30. 'shifts_data' => (new CashierModel())->getShiftsData($this->site_id, $this->store_id),
  31. 'userinfo' => [
  32. 'username' => $this->user_info['username']
  33. ]
  34. ];
  35. return $this->response($this->success($data));
  36. }
  37. /**
  38. * 交接班记录
  39. */
  40. public function changeShiftsRecord(){
  41. $page = $this->params[ 'page' ] ?? 1;
  42. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  43. $uid = $this->params['uid'] ?? 0;
  44. $start_time = $this->params['start_time'] ?? '';
  45. $end_time = $this->params['end_time'] ?? '';
  46. if (!empty($start_time)) $start_time = strtotime($start_time);
  47. if (!empty($end_time)) $end_time = strtotime($end_time);
  48. $condition = [
  49. [ 'csr.site_id', '=', $this->site_id ],
  50. [ 'csr.store_id', '=', $this->store_id ],
  51. ];
  52. if ($uid != 0) $condition[] = ['csr.uid', '=', $uid];
  53. if ($start_time && $end_time) {
  54. $condition[] = [ 'csr.end_time', 'between', [ $start_time, $end_time ] ];
  55. } elseif (!$start_time && $end_time) {
  56. $condition[] = [ 'csr.end_time', '<=', $end_time ];
  57. } elseif ($start_time && !$end_time) {
  58. $condition[] = [ 'csr.end_time', '>=', $start_time ];
  59. }
  60. $join = [ ['user u', 'u.uid = csr.uid', 'left'] ];
  61. $list = (new CashierModel())->getchangeShiftsPageList($condition, 'csr.*,u.username', 'csr.id desc', $page, $page_size, 'csr', $join);
  62. return $this->response($list);
  63. }
  64. /**
  65. * 交班打印
  66. * @return false|string
  67. */
  68. public function printTicket()
  69. {
  70. $record_id = $this->params['record_id'] ?? 0;
  71. $printer_order_model = new PrinterOrder();
  72. $res = $printer_order_model->printer([
  73. 'type' => 'change_shifts',
  74. 'site_id' => $this->site_id,
  75. 'store_id' => $this->store_id,
  76. 'userinfo' => $this->user_info,
  77. 'record_id' => $record_id
  78. ]);
  79. return $this->response($res);
  80. }
  81. /**
  82. * 获取收银台收款设置
  83. * @return false|string
  84. */
  85. public function getCashierCollectMoneyConfig(){
  86. $res = (new CashierModel())->getCashierCollectMoneyConfig($this->site_id, $this->store_id);
  87. return $this->response($res);
  88. }
  89. /**
  90. * 收银台收款设置
  91. * @return false|string
  92. */
  93. public function setCashierCollectMoneyConfig(){
  94. $data = [
  95. 'reduction' => $this->params['reduction'] ?? 1,
  96. 'point' => $this->params['point'] ?? 1,
  97. 'balance' => $this->params['balance'] ?? 1,
  98. 'balance_safe' => $this->params['balance_safe'] ?? 0,
  99. 'sms_verify' => $this->params['sms_verify'] ?? 0,
  100. 'pay_type' => json_decode($this->params['pay_type'] ?? '[]', true),
  101. ];
  102. $res = (new CashierModel())->setCashierCollectMoneyConfig($this->site_id, $this->store_id, $data);
  103. return $this->response($res);
  104. }
  105. }