LocalOrder.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. /**
  15. * 外卖订单
  16. *
  17. * @author Administrator
  18. *
  19. */
  20. class LocalOrder extends OrderCommon
  21. {
  22. /*****************************************************************************************订单基础状态(其他使用)********************************/
  23. // 订单待付款
  24. const ORDER_CREATE = 0;
  25. // 订单已支付(待发货)
  26. const ORDER_PAY = 1;
  27. // 订单备货中
  28. const ORDER_PENDING_DELIVERY = 2;
  29. // 订单已发货(配货)
  30. const ORDER_DELIVERY = 3;
  31. // 订单已收货
  32. const ORDER_TAKE_DELIVERY = 4;
  33. // 订单已结算完成
  34. const ORDER_COMPLETE = 10;
  35. // 订单已关闭
  36. const ORDER_CLOSE = -1;
  37. /***********************************************************************************订单项 配送状态**************************************************/
  38. // 待发货
  39. const DELIVERY_WAIT = 0;
  40. // 已发货
  41. const DELIVERY_DOING = 1;
  42. // 已收货
  43. const DELIVERY_FINISH = 2;
  44. /**
  45. * 订单类型
  46. *
  47. * @var int
  48. */
  49. public $order_type = 3;
  50. /**
  51. * 基础订单状态(不同类型的订单可以不使用这些状态,但是不能冲突)
  52. * @var unknown
  53. */
  54. public $order_status = [
  55. self::ORDER_CREATE => [
  56. 'status' => self::ORDER_CREATE,
  57. 'name' => '待支付',
  58. 'is_allow_refund' => 0,
  59. 'action' => [
  60. [
  61. 'action' => 'orderClose',
  62. 'title' => '关闭订单',
  63. 'color' => ''
  64. ],
  65. [
  66. 'action' => 'orderAddressUpdate',
  67. 'title' => '修改地址',
  68. 'color' => ''
  69. ],
  70. [
  71. 'action' => 'orderAdjustMoney',
  72. 'title' => '调整价格',
  73. 'color' => ''
  74. ],
  75. ],
  76. 'member_action' => [
  77. [
  78. 'action' => 'orderClose',
  79. 'title' => '关闭订单',
  80. 'color' => ''
  81. ],
  82. [
  83. 'action' => 'orderPay',
  84. 'title' => '支付',
  85. 'color' => ''
  86. ],
  87. ],
  88. 'color' => ''
  89. ],
  90. self::ORDER_PAY => [
  91. 'status' => self::ORDER_PAY,
  92. 'name' => '待发货',
  93. 'is_allow_refund' => 0,
  94. 'action' => [
  95. [
  96. 'action' => 'orderLocalDelivery',
  97. 'title' => '发货',
  98. 'color' => ''
  99. ],
  100. ],
  101. 'member_action' => [
  102. ],
  103. 'color' => ''
  104. ],
  105. self::ORDER_DELIVERY => [
  106. 'status' => self::ORDER_DELIVERY,
  107. 'name' => '已发货',
  108. 'is_allow_refund' => 1,
  109. 'action' => [
  110. ],
  111. 'member_action' => [
  112. [
  113. 'action' => 'memberTakeDelivery',
  114. 'title' => '确认收货',
  115. 'color' => ''
  116. ],
  117. ],
  118. 'color' => ''
  119. ],
  120. self::ORDER_TAKE_DELIVERY => [
  121. 'status' => self::ORDER_TAKE_DELIVERY,
  122. 'name' => '已收货',
  123. 'is_allow_refund' => 1,
  124. 'action' => [
  125. ],
  126. 'member_action' => [
  127. ],
  128. 'color' => ''
  129. ],
  130. self::ORDER_COMPLETE => [
  131. 'status' => self::ORDER_COMPLETE,
  132. 'name' => '已完成',
  133. 'is_allow_refund' => 1,
  134. 'action' => [
  135. ],
  136. 'member_action' => [
  137. ],
  138. 'color' => ''
  139. ],
  140. self::ORDER_CLOSE => [
  141. 'status' => self::ORDER_CLOSE,
  142. 'name' => '已关闭',
  143. 'is_allow_refund' => 0,
  144. 'action' => [
  145. ],
  146. 'member_action' => [
  147. ],
  148. 'color' => ''
  149. ],
  150. ];
  151. /**
  152. * 配送状态
  153. */
  154. public $delivery_status = [
  155. self::DELIVERY_WAIT => [
  156. 'status' => self::DELIVERY_WAIT,
  157. 'name' => '待发货',
  158. 'color' => ''
  159. ],
  160. self::DELIVERY_DOING => [
  161. 'status' => self::DELIVERY_DOING,
  162. 'name' => '已发货',
  163. 'color' => ''
  164. ],
  165. self::DELIVERY_FINISH => [
  166. 'status' => self::DELIVERY_FINISH,
  167. 'name' => '已收货',
  168. 'color' => ''
  169. ]
  170. ];
  171. /**
  172. * 订单支付
  173. * @param unknown $order_info
  174. */
  175. public function orderPay($order_info, $pay_type)
  176. {
  177. if ($order_info['order_status'] != 0) {
  178. return $this->error();
  179. }
  180. $condition = array(
  181. [ "order_id", "=", $order_info["order_id"] ],
  182. [ "order_status", "=", self::ORDER_CREATE ],
  183. );
  184. $pay_type_list = $this->getPayType();
  185. $data = array(
  186. "order_status" => self::ORDER_PAY,
  187. "order_status_name" => $this->order_status[ self::ORDER_PAY ]["name"],
  188. "pay_status" => 1,
  189. "order_status_action" => json_encode($this->order_status[ self::ORDER_PAY ], JSON_UNESCAPED_UNICODE),
  190. "pay_time" => time(),
  191. "is_enable_refund" => 1,
  192. "pay_type" => $pay_type,
  193. "pay_type_name" => $pay_type_list[ $pay_type ]
  194. );
  195. $result = model("order")->update($data, $condition);
  196. return $this->success($result);
  197. }
  198. /**
  199. * 订单发货
  200. *
  201. * @param array $condition
  202. */
  203. public function orderDelivery($order_id)
  204. {
  205. $res = model('order_goods')->update([ 'delivery_status' => 1, 'delivery_status_name' => "已发货" ], [ 'order_id' => $order_id ]);
  206. $order_data = array(
  207. 'order_status' => self::ORDER_DELIVERY,
  208. 'order_status_name' => $this->order_status[ self::ORDER_DELIVERY ]["name"],
  209. 'delivery_status' => self::DELIVERY_FINISH,
  210. 'delivery_status_name' => $this->delivery_status[ self::DELIVERY_FINISH ]["name"],
  211. 'order_status_action' => json_encode($this->order_status[ self::ORDER_DELIVERY ], JSON_UNESCAPED_UNICODE),
  212. );
  213. $res = model('order')->update($order_data, [ [ 'order_id', "=", $order_id ] ]);
  214. return $this->success($res);
  215. }
  216. /**
  217. * 订单收货
  218. *
  219. * @param int $order_id
  220. */
  221. public function orderTakeDelivery($order_id)
  222. {
  223. return $this->success();
  224. }
  225. /**
  226. * 退款完成操作
  227. * @param $order_info
  228. */
  229. public function refund($order_goods_info)
  230. {
  231. //是否入库
  232. if ($order_goods_info["is_refund_stock"] == 1) {
  233. $goods_stock_model = new GoodsStock();
  234. $item_param = array(
  235. "sku_id" => $order_goods_info["sku_id"],
  236. "num" => $order_goods_info["num"],
  237. );
  238. //返还库存
  239. $goods_stock_model->incStock($item_param);
  240. }
  241. }
  242. /**
  243. * 订单详情
  244. * @param $order_info
  245. */
  246. public function orderDetail($order_info)
  247. {
  248. return [];
  249. }
  250. }