Order.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\store\shopapi\controller;
  13. use addon\store\model\order\Order as OrderCommonModel;
  14. use app\model\order\OrderLog;
  15. /**
  16. * 订单控制器
  17. * Class Sysorder
  18. * @package addon\shop\siteapi\controller
  19. */
  20. class Order extends BaseStoreApi
  21. {
  22. /**
  23. * 列表
  24. * @return false|string
  25. */
  26. public function lists()
  27. {
  28. $order_common_model = new OrderCommonModel();
  29. $page = $this->params[ 'page' ] ?? 1;
  30. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  31. $search_text = $this->params[ 'search_text' ] ?? '';
  32. $order_status = $this->params[ 'order_status' ] ?? 'all';
  33. $start_time = $this->params[ 'start_time' ] ?? '';
  34. $end_time = $this->params[ 'end_time' ] ?? '';
  35. $trade_type = $this->params[ 'trade_type' ] ?? '';
  36. $order_from = $this->params[ 'order_from' ] ?? '';
  37. $pay_type = $this->params[ 'pay_type' ] ?? '';
  38. $condition = [
  39. [ 'site_id', '=', $this->site_id ],
  40. [ 'store_id', '=', $this->store_id ],
  41. [ 'is_delete', '=', 0 ],
  42. [ 'order_type', '=', 'o2o' ],
  43. ];
  44. //订单状态
  45. if ($order_status != 'all' && !empty($order_status)) {
  46. if ($order_status == $order_common_model::ORDER_REFUNDING) {
  47. $condition[] = [ 'is_exist_refund', '=', 1 ];
  48. } else {
  49. $condition[] = [ 'order_status', '=', $order_status ];
  50. }
  51. }
  52. //订单时间
  53. if (!empty($start_time) && empty($end_time)) {
  54. $condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
  55. } elseif (empty($start_time) && !empty($end_time)) {
  56. $condition[] = [ 'create_time', '<=', date_to_time($end_time) ];
  57. } elseif (!empty($start_time) && !empty($end_time)) {
  58. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  59. }
  60. //订单内容
  61. if ($search_text != '') {
  62. $condition[] = [ 'order_no|out_trade_no|order_name|nickname', 'like', '%' . $search_text . '%' ];
  63. }
  64. //收货方式
  65. if ($trade_type != '') {
  66. $condition[] = [ 'trade_type', '=', $trade_type ];
  67. }
  68. //订单来源
  69. if ($order_from != '') {
  70. $condition[] = [ 'order_from', '=', $order_from ];
  71. }
  72. //订单支付
  73. if ($pay_type != '') {
  74. $condition[] = [ 'pay_type', '=', $pay_type ];
  75. }
  76. $order = 'create_time desc';
  77. $field = '*';
  78. $list = $order_common_model->getOrderPageList($condition, $page, $page_size, $order, $field);
  79. return $this->response($list);
  80. }
  81. /**
  82. * 获取支付方式
  83. */
  84. public function getOrderPayType()
  85. {
  86. $order_common_model = new OrderCommonModel();
  87. $pay_type_list = $order_common_model->getPayType('o2o');
  88. return $this->response($this->success($pay_type_list));
  89. }
  90. /**
  91. * 获取订单状态
  92. */
  93. public function getOrderStatus()
  94. {
  95. $trade_type = $this->params[ 'trade_type' ] ?? 'service';
  96. $order_common_model = new OrderCommonModel();
  97. $list = $order_common_model->getOrderStatusList([
  98. 'trade_type' => $trade_type,
  99. ]);
  100. return $this->response($this->success($list));
  101. }
  102. /**
  103. * 获取订单来源
  104. */
  105. public function getOrderFromType()
  106. {
  107. $order_common_model = new OrderCommonModel();
  108. $list = $order_common_model->getOrderFromList('o2o');
  109. return $this->response($this->success($list));
  110. }
  111. /**
  112. * 获取订单信息
  113. */
  114. public function info()
  115. {
  116. $order_id = $this->params[ 'order_id' ] ?? 0;
  117. //订单信息
  118. $order_common_model = new OrderCommonModel();
  119. $condition = array (
  120. [ 'order_id', '=', $order_id ],
  121. [ 'site_id', '=', $this->site_id ],
  122. [ 'store_id', '=', $this->store_id ],
  123. );
  124. $res = $order_common_model->getOrderInfo($condition)[ 'data' ];
  125. return $this->response($res);
  126. }
  127. /**
  128. * 订单详情
  129. */
  130. public function detail()
  131. {
  132. $order_id = $this->params[ 'order_id' ] ?? 0;
  133. //订单详情
  134. $order_common_model = new OrderCommonModel();
  135. $order_detail = $order_common_model->getOrderDetail($order_id, $this->site_id)[ 'data' ];
  136. if (empty($order_detail)) return $this->response($this->error(null, '无法获取订单数据'));
  137. //查询订单日志
  138. $order_log_model = new OrderLog();
  139. $log_condition = [
  140. [ 'order_id', '=', $order_id ],
  141. ];
  142. $order_detail[ 'order_log_list' ] = $order_log_model->getOrderLogList($log_condition, '*', 'action_time desc,id desc')[ 'data' ];
  143. return $this->response($this->success($order_detail));
  144. }
  145. /**
  146. * 卖家备注
  147. */
  148. public function orderRemark()
  149. {
  150. $order_id = $this->params[ 'order_id' ] ?? 0;
  151. $remark = $this->params[ 'remark' ] ?? '';
  152. $order_common_model = new OrderCommonModel();
  153. $data = array (
  154. "remark" => $remark,
  155. "order_id" => $order_id,
  156. "site_id" => $this->site_id,
  157. "uid" => $this->uid
  158. );
  159. $result = $order_common_model->orderUpdateRemark($data);
  160. return $this->response($result);
  161. }
  162. /**
  163. * 订单调价
  164. * @return mixed
  165. */
  166. public function adjustPrice()
  167. {
  168. $order_id = $this->params[ 'order_id' ] ?? 0;
  169. $adjust_money = $this->params[ 'adjust_money' ] ?? 0;
  170. $shipping_money = $this->params[ 'shipping_money' ] ?? 0;
  171. $order_common_model = new OrderCommonModel();
  172. $params = array (
  173. 'order_id' => $order_id,
  174. 'adjust_money' => $adjust_money,
  175. 'shipping_money' => $shipping_money,
  176. 'site_id' => $this->site_id,
  177. 'uid' => $this->uid
  178. );
  179. $result = $order_common_model->orderAdjustMoney($params);
  180. return $this->response($result);
  181. }
  182. /**
  183. * 订单关闭
  184. * @return mixed
  185. */
  186. public function close()
  187. {
  188. $order_id = $this->params[ 'order_id' ] ?? 0;
  189. $order_common_model = new OrderCommonModel();
  190. $order_close_params = array (
  191. 'order_id' => $order_id,
  192. 'site_id' => $this->site_id,
  193. 'uid' => $this->uid
  194. );
  195. $result = $order_common_model->orderClose($order_close_params);
  196. return $this->response($result);
  197. }
  198. /**
  199. * 订单删除
  200. */
  201. public function delete()
  202. {
  203. $order_id = $this->params[ 'order_id' ] ?? 0;
  204. $order_common_model = new OrderCommonModel();
  205. $result = $order_common_model->orderDelete($order_id, $this->site_id);
  206. return $this->response($result);
  207. }
  208. }