StoreOrder.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\order;
  13. use app\model\goods\GoodsStock;
  14. use app\model\message\Message;
  15. use app\model\verify\Verify;
  16. /**
  17. * 门店自提订单
  18. *
  19. * @author Administrator
  20. *
  21. */
  22. class StoreOrder extends OrderCommon
  23. {
  24. /*****************************************************************************************订单状态***********************************************/
  25. // 订单创建
  26. const ORDER_CREATE = 0;
  27. // 订单已支付
  28. const ORDER_PAY = 1;
  29. // 订单待提货
  30. const ORDER_PENDING_DELIVERY = 2;
  31. // 订单已发货(配货)
  32. const ORDER_DELIVERY = 3;
  33. // 订单已收货
  34. const ORDER_TAKE_DELIVERY = 4;
  35. // 订单已结算完成
  36. const ORDER_COMPLETE = 10;
  37. // 订单已关闭
  38. const ORDER_CLOSE = -1;
  39. /**
  40. * 订单类型
  41. *
  42. * @var int
  43. */
  44. public $order_type = 2;
  45. /**
  46. */
  47. public $order_status = [
  48. self::ORDER_CREATE => [
  49. 'status' => self::ORDER_CREATE,
  50. 'name' => '待支付',
  51. 'is_allow_refund' => 0,
  52. 'action' =>[
  53. [
  54. 'action' => 'orderClose',
  55. 'title'=> '关闭订单',
  56. 'color'=> ''
  57. ],
  58. [
  59. 'action' => 'orderAdjustMoney',
  60. 'title'=> '调整价格',
  61. 'color'=> ''
  62. ],
  63. ],
  64. 'member_action' => [
  65. [
  66. 'action' => 'orderClose',
  67. 'title'=> '关闭订单',
  68. 'color'=> ''
  69. ],
  70. [
  71. 'action' => 'orderPay',
  72. 'title'=> '支付',
  73. 'color'=> ''
  74. ],
  75. ],
  76. 'color' => ''
  77. ],
  78. self::ORDER_PENDING_DELIVERY => [
  79. 'status' => self::ORDER_PENDING_DELIVERY,
  80. 'name' => '待提货',
  81. 'is_allow_refund' => 0,
  82. 'action' =>[
  83. // [
  84. // 'action' => 'orderDelivery',
  85. // 'title'=> '提货',
  86. // 'color'=> ''
  87. // ],
  88. ],
  89. 'member_action' => [
  90. ],
  91. 'color' => ''
  92. ],
  93. self::ORDER_TAKE_DELIVERY => [
  94. 'status' => self::ORDER_TAKE_DELIVERY,
  95. 'name' => '已提货',
  96. 'is_allow_refund' => 1,
  97. 'action' =>[
  98. ],
  99. 'member_action' => [
  100. ],
  101. 'color' => ''
  102. ],
  103. self::ORDER_COMPLETE => [
  104. 'status' => self::ORDER_COMPLETE,
  105. 'name' => '已完成',
  106. 'is_allow_refund' => 1,
  107. 'action' =>[
  108. ],
  109. 'member_action' => [
  110. ],
  111. 'color' => ''
  112. ],
  113. self::ORDER_CLOSE => [
  114. 'status' => self::ORDER_CLOSE,
  115. 'name' => '已关闭',
  116. 'is_allow_refund' => 0,
  117. 'action' =>[
  118. ],
  119. 'member_action' => [
  120. ],
  121. 'color' => ''
  122. ],
  123. ];
  124. /**
  125. * 订单支付
  126. * @param unknown $order_info
  127. */
  128. public function orderPay($order_info, $pay_type)
  129. {
  130. if($order_info['order_status'] != 0)
  131. {
  132. return $this->error();
  133. }
  134. $condition = array(
  135. ["order_id", "=", $order_info["order_id"]],
  136. ["order_status", "=", self::ORDER_CREATE],
  137. );
  138. $verify = new Verify();
  139. $order_goods_list = model("order_goods")->getList([["order_id", "=", $order_info["order_id"]]], "sku_image,sku_name,price,num");
  140. $item_array = [];
  141. foreach($order_goods_list as $k => $v){
  142. $item_array[] = [
  143. "img" => $v["sku_image"],
  144. "name" => $v["sku_name"],
  145. "price" => $v["price"],
  146. "num" => $v["num"],
  147. "remark_array" => [
  148. ]
  149. ];
  150. }
  151. $pay_time = time();
  152. $remark_array = array(
  153. ["title" => '订单金额', "value" => $order_info["order_money"]],
  154. ["title" => '订单编号', "value" => $order_info["order_no"]],
  155. ["title" => '创建时间', "value" => time_to_date($order_info["create_time"])],
  156. ["title" => '付款时间', "value" => time_to_date($pay_time)],
  157. ["title" => '收货地址', "value" => $order_info["full_address"]],
  158. ["title" => '选择门店', "value" => $order_info["delivery_store_name"]],
  159. );
  160. $verify_content_json = $verify->getVerifyJson($item_array, $remark_array);
  161. $code = $verify->addVerify("pickup", $order_info['site_id'], $order_info['site_name'], $verify_content_json);
  162. $pay_type_list = $this->getPayType();
  163. $data = array(
  164. "order_status" => self::ORDER_PENDING_DELIVERY,
  165. "order_status_name" => $this->order_status[self::ORDER_PENDING_DELIVERY]["name"],
  166. "pay_status" => 1,
  167. "order_status_action" => json_encode($this->order_status[self::ORDER_PENDING_DELIVERY], JSON_UNESCAPED_UNICODE),
  168. "delivery_code" => $code['data']['verify_code'],
  169. "pay_time" => $pay_time,
  170. "is_enable_refund" => 1,
  171. "pay_type" => $pay_type,
  172. "pay_type_name" => $pay_type_list[$pay_type]
  173. );
  174. $res = model('order')->update($data, $condition);
  175. $result = $verify->qrcode($code['data']['verify_code'], "all","pickup", "create");
  176. return $this->success($res);
  177. }
  178. /**
  179. * 主动提货
  180. * @param $delivery_code
  181. * @return \multitype
  182. */
  183. public function verify($delivery_code){
  184. $order_info = model("order")->getInfo([['delivery_code', '=', $delivery_code]], 'order_id, order_type, sign_time, order_status, delivery_code');
  185. if(empty($order_info))
  186. return $this->error([], "ORDER_EMPTY");
  187. $result = $this->orderCommonTakeDelivery($order_info["order_id"]);
  188. if($result["code"] < 0){
  189. return $result;
  190. }
  191. //核销发送通知
  192. $message_model = new Message();
  193. $message_model->sendMessage([ 'keywords' => "VERIFY", 'order_id' => $order_info['order_id'] ]);
  194. return $result;
  195. }
  196. /**
  197. * 订单提货
  198. * @param unknown $order_id
  199. * @param unknown $delivery_code
  200. */
  201. public function orderTakeDelivery($order_id)
  202. {
  203. $res = model('order_goods')->update(['delivery_status' => 1, 'delivery_status_name' => "已发货"], ['order_id' => $order_id]);
  204. return $this->success($res);
  205. }
  206. /**
  207. * 退款完成操作
  208. * @param $order_info
  209. */
  210. public function refund($order_goods_info){
  211. //是否入库
  212. if($order_goods_info["is_refund_stock"] == 1){
  213. $goods_stock_model = new GoodsStock();
  214. $item_param = array(
  215. "sku_id" => $order_goods_info["sku_id"],
  216. "num" => $order_goods_info["num"],
  217. );
  218. //返还库存
  219. $goods_stock_model->incStock($item_param);
  220. }
  221. }
  222. /**
  223. * 订单详情
  224. * @param $order_info
  225. */
  226. public function orderDetail($order_info){
  227. return [];
  228. }
  229. }