CashierOrder.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\cashier\model\order;
  11. use addon\memberconsume\model\Consume;
  12. use addon\store\model\settlement\OrderSettlement;
  13. use app\model\order\OrderCommon;
  14. use app\model\order\OrderLog;
  15. /**
  16. * 订单创建(收银订单)
  17. *
  18. * @author Administrator
  19. *
  20. */
  21. class CashierOrder extends OrderCommon
  22. {
  23. //待付款
  24. const ORDER_CREATE = 0;
  25. // 订单已支付
  26. const ORDER_PAY = 1;
  27. // 订单已完成
  28. const ORDER_COMPLETE = 10;
  29. // 订单已关闭
  30. const ORDER_CLOSE = -1;
  31. /**
  32. * 订单类型
  33. *
  34. * @var int
  35. */
  36. public $order_type = 5;
  37. //订单来源
  38. public $order_from_list = [ 'cashier' => [ 'name' => '收银台' ] ];
  39. public $order_status = [
  40. self::ORDER_CREATE => [
  41. 'status' => self::ORDER_CREATE,
  42. 'name' => '待支付',
  43. 'is_allow_refund' => 0,
  44. 'icon' => 'public/uniapp/order/order-icon.png',
  45. 'action' => [
  46. [
  47. 'action' => 'orderClose',
  48. 'title' => '关闭订单',
  49. 'color' => ''
  50. ]
  51. ],
  52. 'member_action' => [
  53. [
  54. 'action' => 'orderClose',
  55. 'title' => '关闭订单',
  56. 'color' => ''
  57. ],
  58. ],
  59. 'color' => ''
  60. ],
  61. self::ORDER_COMPLETE => [
  62. 'status' => self::ORDER_COMPLETE,
  63. 'name' => '已完成',
  64. 'is_allow_refund' => 1,
  65. 'icon' => 'public/uniapp/order/order-icon-received.png',
  66. 'action' => [
  67. ],
  68. 'member_action' => [
  69. ],
  70. 'color' => ''
  71. ],
  72. self::ORDER_CLOSE => [
  73. 'status' => self::ORDER_CLOSE,
  74. 'name' => '已关闭',
  75. 'is_allow_refund' => 0,
  76. 'icon' => 'public/uniapp/order/order-icon-close.png',
  77. 'action' => [
  78. ],
  79. 'member_action' => [
  80. ],
  81. 'color' => ''
  82. ],
  83. ];
  84. public $pay_type = array (
  85. 'cash' => '现金支付',
  86. 'BALANCE' => '余额支付',
  87. 'own_wechatpay' => '个人微信',
  88. 'own_alipay' => '个人支付宝',
  89. 'own_pos' => '个人pos刷卡',
  90. 'ONLINE_PAY' => '在线支付',
  91. );
  92. public $cashier_order_type = [
  93. 'goods' => '消费',
  94. 'card' => '售卡',
  95. 'recharge' => '充值',
  96. ];
  97. //todo 切勿调用,占位
  98. public $delivery_status_list = array (
  99. 0 => '待发货',
  100. 1 => '已发货',
  101. 2 => '已收货'
  102. );
  103. public function getPayType($params = [])
  104. {
  105. return $this->pay_type;
  106. }
  107. public function getCashierOrderType()
  108. {
  109. return $this->cashier_order_type;
  110. }
  111. public function orderPay()
  112. {
  113. }
  114. public function refund($params)
  115. {
  116. return $this->success();
  117. }
  118. public function orderDetail($order_info)
  119. {
  120. return [];
  121. }
  122. /**
  123. * 订单完成
  124. * @param $params
  125. */
  126. public function complete($params)
  127. {
  128. $site_id = $params[ 'site_id' ];
  129. $order_id = $params[ 'order_id' ];
  130. $cashier_order_model = new CashierOrder();
  131. $cashier_data = array (
  132. 'order_status' => 10,
  133. 'finish_time' => time(),
  134. 'order_status_name' => $cashier_order_model->order_status[ 10 ][ 'name' ],
  135. 'order_status_action' => json_encode($cashier_order_model->order_status[ 10 ], JSON_UNESCAPED_UNICODE)
  136. );
  137. $cashier_condition = array (
  138. [ 'order_id', '=', $order_id ],
  139. );
  140. model('order')->update($cashier_data, $cashier_condition);
  141. //收银台的订单因部分不可抗力不能进行公共的订单完成事件,所以主动调用门店订单分成结算
  142. if (addon_is_exit('store')) {
  143. ( new OrderSettlement() )->orderSettlementAccount([ 'order_id' => $order_id ]);
  144. }
  145. //模拟订单支付后操作钩子
  146. if (addon_is_exit('memberconsume')) {
  147. $consume_model = new Consume();
  148. $consume_model->memberConsume([ 'out_trade_no' => $params[ 'out_trade_no' ], 'status' => 'complete' ]);
  149. }
  150. $log_data = array (
  151. 'order_id' => $order_id,
  152. 'action' => 'complete',
  153. 'site_id' => $site_id,
  154. 'is_auto' => 1
  155. );
  156. ( new OrderLog() )->addLog($log_data);
  157. return $this->success();
  158. }
  159. }