Order.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shopapi\controller;
  13. use app\model\express\ExpressDeliver;
  14. use app\model\express\ExpressPackage;
  15. use app\model\order\Config as ConfigModel;
  16. use app\model\order\Order as OrderModel;
  17. use app\model\order\OrderCommon as OrderCommonModel;
  18. use think\facade\Config;
  19. use think\facade\Db;
  20. /**
  21. * 订单
  22. * Class Order
  23. * @package app\shop\controller
  24. */
  25. class Order extends BaseApi
  26. {
  27. public function __construct()
  28. {
  29. //执行父类构造函数
  30. parent::__construct();
  31. $token = $this->checkToken();
  32. if ($token[ 'code' ] < 0) {
  33. echo $this->response($token);
  34. exit;
  35. }
  36. }
  37. /**
  38. * 获取订单查询条件
  39. */
  40. public function condition()
  41. {
  42. $data = [];
  43. $order_common_model = new OrderCommonModel();
  44. $order_type_list = $order_common_model->getOrderTypeStatusList();
  45. if (array_key_exists('all', $order_type_list)) {
  46. array_unshift($order_type_list, $order_type_list[ 'all' ]);
  47. unset($order_type_list[ 'all' ]);
  48. }
  49. $data[ 'order_type_list' ] = $order_type_list;
  50. $data[ 'order_status_list' ] = $order_type_list[ 1 ][ 'status' ];//订单状态
  51. //订单来源 (支持端口)
  52. $order_from = Config::get("app_type");
  53. $data[ 'order_from_list' ] = $order_from;
  54. $pay_type = $order_common_model->getPayType();
  55. $data[ 'pay_type_list' ] = $pay_type;
  56. //营销活动类型
  57. $order_promotion_type = event('OrderPromotionType');
  58. $data[ 'promotion_type' ] = $order_promotion_type;
  59. $data[ 'http_type' ] = get_http_type();
  60. return $this->response($this->success($data));
  61. }
  62. /**
  63. * 订单列表
  64. */
  65. public function lists()
  66. {
  67. $order_status = isset($this->params[ 'order_status' ]) ? $this->params[ 'order_status' ] : '';//订单状态
  68. $order_name = isset($this->params[ 'order_name' ]) ? $this->params[ 'order_name' ] : '';
  69. $pay_type = isset($this->params[ 'pay_type' ]) ? $this->params[ 'pay_type' ] : '';
  70. $order_from = isset($this->params[ 'order_from' ]) ? $this->params[ 'order_from' ] : '';
  71. $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
  72. $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
  73. $search_text = isset($this->params[ 'search' ]) ? $this->params[ 'search' ] : '';
  74. $promotion_type = isset($this->params[ 'promotion_type' ]) ? $this->params[ 'promotion_type' ] : '';//订单类型
  75. $order_type = isset($this->params[ 'order_type' ]) ? $this->params[ 'order_type' ] : 'all';//营销类型
  76. $settlement_state = isset($this->params[ 'settlement_state' ]) ? $this->params[ 'settlement_state' ] : '';//结算状态
  77. $page_index = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  78. $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  79. $alias = 'o';
  80. $join = null;
  81. $condition = [
  82. [ "o.site_id", "=", $this->site_id ],
  83. [ 'o.is_delete', '=', 0 ]
  84. ];
  85. //订单状态
  86. if ($order_status != "") {
  87. if ($order_status != 'refunding') {
  88. if ($order_status == 0) {
  89. $condition[] = [ "o.order_status", "=", $order_status ];
  90. $condition[] = [ 'o.order_scene', '=', 'online' ];
  91. } else {
  92. $condition[] = [ "o.order_status", "=", $order_status ];
  93. }
  94. } else {
  95. $join = [
  96. [
  97. 'order_goods og',
  98. 'og.order_id = o.order_id',
  99. 'left'
  100. ]
  101. ];
  102. $condition[] = [ "og.refund_status", "not in", [ 0, 3 ] ];
  103. }
  104. } else {
  105. $condition[] = [ '', 'exp', Db::raw("o.order_scene = 'online' OR (o.order_scene = 'cashier' AND o.pay_status = 1)") ];
  106. }
  107. //订单内容 模糊查询
  108. if ($order_name != "") {
  109. $condition[] = [ "o.order_name", 'like', "%$order_name%" ];
  110. }
  111. //订单来源
  112. if ($order_from != "") {
  113. $condition[] = [ "o.order_from", "=", $order_from ];
  114. }
  115. //订单支付
  116. if ($pay_type != "") {
  117. $condition[] = [ "o.pay_type", "=", $pay_type ];
  118. }
  119. //订单类型
  120. if ($order_type != 'all') {
  121. $condition[] = [ "o.order_type", "=", $order_type ];
  122. }
  123. //结算状态
  124. if ($settlement_state == 1) {
  125. $condition[] = [ "o.is_settlement", "=", '1' ];
  126. } elseif ($settlement_state == 2) {
  127. $condition[] = [ "o.is_settlement", "=", '0' ];
  128. }
  129. //营销类型
  130. if ($promotion_type != "") {
  131. if ($promotion_type == 'empty') {
  132. $condition[] = [ "o.promotion_type", "=", '' ];
  133. } else {
  134. $condition[] = [ "o.promotion_type", "=", $promotion_type ];
  135. }
  136. }
  137. if (!empty($start_time) && empty($end_time)) {
  138. $condition[] = [ "o.create_time", ">=", date_to_time($start_time . ' 00:00:00') ];
  139. } elseif (empty($start_time) && !empty($end_time)) {
  140. $condition[] = [ "o.create_time", "<=", date_to_time($end_time . ' 23:59:59') ];
  141. } elseif (!empty($start_time) && !empty($end_time)) {
  142. $condition[] = [ 'o.create_time', 'between', [ date_to_time($start_time . ' 00:00:00'), date_to_time($end_time . ' 23:59:59') ] ];
  143. }
  144. //订单内容
  145. if ($search_text != '') {
  146. $condition[] = [ 'o.order_no|o.out_trade_no|o.order_name|o.name|o.mobile', 'like', '%' . $search_text . '%' ];
  147. }
  148. $order_common_model = new OrderCommonModel();
  149. $field = 'o.order_id, o.order_no, o.order_type, o.order_type_name, o.order_status, o.order_status_name, o.order_status_action, o.pay_type_name, o.name, o.mobile, o.address, o.full_address, o.order_money, o.create_time, o.remark, o.promotion_type_name, o.promotion_status_name, o.buyer_message, o.is_enable_refund, o.promotion_type, o.order_scene,o.buyer_ask_delivery_time';
  150. $list = $order_common_model->getOrderPageList($condition, $page_index, $page_size, "o.create_time desc", $field, $alias, $join);
  151. foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
  152. // 2:自提提货,3:本地配送外卖
  153. if ($v[ 'order_type' ] == 2 || $v[ 'order_type' ] == 3) {
  154. if ($list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time' ] == 0) {
  155. $list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time_str' ] = '立即送达';
  156. } elseif (strpos($list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time' ], '-') !== false) {
  157. $list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time_str' ] = $list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time' ];
  158. } else {
  159. $list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time_str' ] = date("H:i:s", $list[ 'data' ][ 'list' ][ $k ][ 'buyer_ask_delivery_time' ]);
  160. }
  161. }
  162. }
  163. return $this->response($list);
  164. }
  165. /**
  166. * 快递订单详情
  167. */
  168. public function detail()
  169. {
  170. $order_id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  171. $order_common_model = new OrderCommonModel();
  172. $order_detail_result = $order_common_model->getOrderDetail($order_id);
  173. if (empty($order_detail_result[ 'data' ])) {
  174. return $this->response($this->error('查询不到此订单信息!'));
  175. }
  176. if ($order_detail_result[ 'data' ][ 'site_id' ] != $this->site_id) {
  177. return $this->response($this->error('查询不到此订单信息!'));
  178. }
  179. $order_log_condition = array (
  180. [ 'order_id', '=', $order_id ]
  181. );
  182. $order_log_count = $order_common_model->getOrderLogCount($order_log_condition);
  183. if ($order_detail_result[ 'data' ][ 'buyer_ask_delivery_time' ] == 0) {
  184. $order_detail_result[ 'data' ][ 'buyer_ask_delivery_time_str' ] = '立即送达';
  185. } elseif (strpos($order_detail_result[ 'data' ][ 'buyer_ask_delivery_time' ], '-') !== false) {
  186. $order_detail_result[ 'data' ][ 'buyer_ask_delivery_time_str' ] = $order_detail_result[ 'data' ][ 'buyer_ask_delivery_time' ];
  187. } else {
  188. $order_detail_result[ 'data' ][ 'buyer_ask_delivery_time_str' ] = date("H:i:s", $order_detail_result[ 'data' ][ 'buyer_ask_delivery_time' ]);
  189. }
  190. $order_detail_result[ 'data' ][ 'log_count' ] = $order_log_count[ 'data' ];
  191. return $this->response($order_detail_result);
  192. }
  193. /**
  194. * 订单日志列表
  195. * @return false|string
  196. */
  197. public function log()
  198. {
  199. $order_id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  200. $order_common_model = new OrderCommonModel();
  201. $order_log_condition = array (
  202. [ 'order_id', '=', $order_id ]
  203. );
  204. $order_log_list = $order_common_model->getOrderLogList($order_log_condition);
  205. return $this->response($order_log_list);
  206. }
  207. /**
  208. * 订单关闭
  209. * @return mixed
  210. */
  211. public function close()
  212. {
  213. $order_id = isset($this->params[ 'order_id' ]) ? $this->params[ 'order_id' ] : 0;
  214. $order_common_model = new OrderCommonModel();
  215. $log_data = [
  216. 'uid' => $this->user_info[ 'uid' ],
  217. 'nick_name' => $this->user_info[ 'username' ],
  218. 'action_way' => 2
  219. ];
  220. $result = $order_common_model->orderClose($order_id, $log_data);
  221. return $this->response($result);
  222. }
  223. /**
  224. * 订单调价
  225. * @return mixed
  226. */
  227. public function adjustPrice()
  228. {
  229. $order_id = $this->params[ 'order_id' ] ?? 0;
  230. $adjust_money = isset($this->params[ 'adjust_money' ]) ? $this->params[ 'adjust_money' ] : 0;
  231. $delivery_money = isset($this->params[ 'delivery_money' ]) ? $this->params[ 'delivery_money' ] : 0;
  232. $order_common_model = new OrderCommonModel();
  233. $result = $order_common_model->orderAdjustMoney($order_id, $adjust_money, $delivery_money);
  234. return $this->response($result);
  235. }
  236. /**
  237. * 订单发货
  238. * @return mixed
  239. */
  240. public function delivery()
  241. {
  242. $order_id = $this->params[ 'order_id' ] ?? 0;
  243. $order_goods_ids = isset($this->params[ 'order_goods_ids' ]) ? $this->params[ 'order_goods_ids' ] : '';
  244. $express_company_id = isset($this->params[ 'express_company_id' ]) ? $this->params[ 'express_company_id' ] : 0;
  245. $delivery_no = isset($this->params[ 'delivery_no' ]) ? $this->params[ 'delivery_no' ] : '';
  246. $delivery_type = isset($this->params[ 'delivery_type' ]) ? $this->params[ 'delivery_type' ] : 0;
  247. $order_model = new OrderModel();
  248. $data = array (
  249. "type" => isset($this->params[ 'type' ]) ? $this->params[ 'type' ] : 'manual',//发货方式(手动发货、电子面单)
  250. "order_goods_ids" => $order_goods_ids,
  251. "express_company_id" => $express_company_id,
  252. "delivery_no" => $delivery_no,
  253. "order_id" => $order_id,
  254. "delivery_type" => $delivery_type,
  255. "site_id" => $this->site_id,
  256. "template_id" => isset($this->params[ 'template_id' ]) ? $this->params[ 'template_id' ] : '0'//电子面单模板id
  257. );
  258. $log_data = [
  259. 'uid' => $this->user_info[ 'uid' ],
  260. 'nick_name' => $this->user_info[ 'username' ],
  261. 'action' => '商家对订单进行了发货',
  262. 'action_way' => 2
  263. ];
  264. $result = $order_model->orderGoodsDelivery($data, 1, $log_data);
  265. return $this->response($result);
  266. }
  267. /**
  268. * 获取订单项列表
  269. */
  270. public function getOrderGoodsList()
  271. {
  272. $order_id = $this->params[ 'order_id' ] ?? 0;
  273. $delivery_status = $this->params[ 'delivery_status' ] ?? '';
  274. $order_common_model = new OrderCommonModel();
  275. $condition = array (
  276. [ "order_id", "=", $order_id ],
  277. [ "site_id", "=", $this->site_id ],
  278. [ "refund_status", "<>", 3 ],
  279. );
  280. if ($delivery_status != '') {
  281. $condition[] = [ "delivery_status", "=", $delivery_status ];
  282. }
  283. $field = "order_goods_id, order_id, site_id, sku_name, sku_image, sku_no, is_virtual, price, cost_price, num, goods_money, cost_money, delivery_status, delivery_no, goods_id, delivery_status_name,refund_status,refund_status_name";
  284. $result = $order_common_model->getOrderGoodsList($condition, $field, '', null, "");
  285. return $this->response($result);
  286. }
  287. /**
  288. * 订单修改收货地址
  289. * @return mixed
  290. */
  291. public function editAddress()
  292. {
  293. $order_id = $this->params[ 'order_id' ] ?? 0;
  294. $order_model = new OrderModel();
  295. $province_id = isset($this->params[ 'province_id' ]) ? $this->params[ 'province_id' ] : '';
  296. $city_id = isset($this->params[ 'city_id' ]) ? $this->params[ 'city_id' ] : '';
  297. $district_id = isset($this->params[ 'district_id' ]) ? $this->params[ 'district_id' ] : '';
  298. $community_id = isset($this->params[ 'community_id' ]) ? $this->params[ 'community_id' ] : '';
  299. $address = isset($this->params[ 'address' ]) ? $this->params[ 'address' ] : '';
  300. $full_address = isset($this->params[ 'full_address' ]) ? $this->params[ 'full_address' ] : '';
  301. $longitude = isset($this->params[ 'longitude' ]) ? $this->params[ 'longitude' ] : '';
  302. $latitude = isset($this->params[ 'latitude' ]) ? $this->params[ 'latitude' ] : '';
  303. $mobile = isset($this->params[ 'mobile' ]) ? $this->params[ 'mobile' ] : '';
  304. $telephone = isset($this->params[ 'telephone' ]) ? $this->params[ 'telephone' ] : '';
  305. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  306. $data = array (
  307. "province_id" => $province_id,
  308. "city_id" => $city_id,
  309. "district_id" => $district_id,
  310. "community_id" => $community_id,
  311. "address" => $address,
  312. "full_address" => $full_address,
  313. "longitude" => $longitude,
  314. "latitude" => $latitude,
  315. "mobile" => $mobile,
  316. "telephone" => $telephone,
  317. "name" => $name,
  318. );
  319. $condition = array (
  320. [ "order_id", "=", $order_id ],
  321. [ "site_id", "=", $this->site_id ]
  322. );
  323. $log_data = [
  324. 'uid' => $this->user_info[ 'uid' ],
  325. 'nick_name' => $this->user_info[ 'username' ],
  326. 'action' => '商家修改了收货地址',
  327. 'action_way' => '2',
  328. 'order_id' => $order_id
  329. ];
  330. $result = $order_model->orderAddressUpdate($data, $condition, $log_data);
  331. return $this->response($result);
  332. }
  333. /**
  334. * 获取订单信息
  335. */
  336. public function getOrderInfo()
  337. {
  338. $order_id = $this->params[ 'order_id' ] ?? 0;
  339. $order_common_model = new OrderCommonModel();
  340. $condition = array (
  341. [ "order_id", "=", $order_id ],
  342. [ "site_id", "=", $this->site_id ],
  343. );
  344. $result = $order_common_model->getOrderInfo($condition);
  345. // 获取配送员信息
  346. $deliver_model = new ExpressDeliver();
  347. $deliver_list = $deliver_model->getDeliverLists([ [ 'site_id', '=', $this->site_id ] ], 'deliver_id,deliver_name,deliver_mobile');
  348. if (!empty($deliver_list[ 'data' ])) {
  349. $result[ 'data' ][ 'deliver_list' ] = $deliver_list[ 'data' ];
  350. }
  351. return $this->response($result);
  352. }
  353. /**
  354. * 获取订单 订单项内容
  355. */
  356. public function getOrderDetail()
  357. {
  358. $order_id = $this->params[ 'order_id' ] ?? 0;
  359. $order_common_model = new OrderCommonModel();
  360. $result = $order_common_model->getOrderDetail($order_id);
  361. return $this->response($result);
  362. }
  363. /**
  364. * 卖家备注
  365. */
  366. public function orderRemark()
  367. {
  368. $order_id = $this->params[ 'order_id' ] ?? 0;
  369. $remark = $this->params[ 'remark' ] ?? '';
  370. $order_common_model = new OrderCommonModel();
  371. $condition = array (
  372. [ "order_id", "=", $order_id ],
  373. [ "site_id", "=", $this->site_id ],
  374. );
  375. $data = array (
  376. "remark" => $remark
  377. );
  378. $log_data = [
  379. 'action' => '商家备注了订单,备注内容:' . $remark,
  380. 'action_way' => 2,
  381. 'uid' => $this->user_info[ 'uid' ],
  382. 'nick_name' => $this->user_info[ 'username' ],
  383. 'order_id' => $order_id
  384. ];
  385. $result = $order_common_model->orderUpdate($data, $condition, $log_data);
  386. return $this->response($result);
  387. }
  388. /**
  389. * 延长收货时间
  390. */
  391. public function extendTakeDelivery()
  392. {
  393. $order_id = $this->params[ 'order_id' ] ?? 0;
  394. $condition = array (
  395. [ 'order_id', '=', $order_id ],
  396. [ 'site_id', '=', $this->site_id ],
  397. );
  398. $order_common_model = new OrderCommonModel();
  399. $log_data = [
  400. 'uid' => $this->uid,
  401. 'username' => $this->user_info[ 'username' ],
  402. 'module' => 'shop'
  403. ];
  404. $result = $order_common_model->extendTakeDelivery($condition, $log_data);
  405. return $this->response($result);
  406. }
  407. /**
  408. * 线下支付
  409. */
  410. public function offlinePay()
  411. {
  412. $order_id = $this->params[ 'order_id' ] ?? 0;
  413. $order_common_model = new OrderCommonModel();
  414. $log_data = [
  415. 'uid' => $this->user_info[ 'uid' ],
  416. 'nick_name' => $this->user_info[ 'username' ],
  417. 'action_way' => 2
  418. ];
  419. $order_detail_result = $order_common_model->orderOfflinePay($order_id, $log_data);
  420. return $this->response($order_detail_result);
  421. }
  422. /**
  423. * 订单列表(发票)
  424. */
  425. public function invoicelist()
  426. {
  427. $order_common_model = new OrderCommonModel();
  428. $page_index = $this->params[ 'page' ] ?? 1;
  429. $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
  430. $invoice_status = input("invoice_status", '');
  431. $order_type = $this->params[ 'order_type' ] ?? '';//营销类型
  432. $order_status = $this->params[ 'order_status' ] ?? '';
  433. $start_time = $this->params[ 'start_time' ] ?? '';
  434. $end_time = $this->params[ 'end_time' ] ?? '';
  435. //订单编号
  436. $order_no = $this->params[ 'search_text' ] ?? '';
  437. $alias = 'o';
  438. $join = null;
  439. $condition = [
  440. [ "o.site_id", "=", $this->site_id ],
  441. [ 'o.is_invoice', '=', 1 ]
  442. ];
  443. //发票状态
  444. if ($invoice_status != '') {
  445. $condition[] = [ 'o.invoice_status', '=', $invoice_status ];
  446. }
  447. if ($order_no) {
  448. $condition[] = [ "o.order_no", "like", "%" . $order_no . "%" ];
  449. }
  450. //订单状态
  451. if ($order_status != "") {
  452. if ($order_status != 'refunding') {
  453. $condition[] = [ "o.order_status", "=", $order_status ];
  454. } else {
  455. $join = [
  456. [
  457. 'order_goods og',
  458. 'og.order_id = o.order_id',
  459. 'left'
  460. ]
  461. ];
  462. $condition[] = [ "og.refund_status", "not in", [ 0, 3 ] ];
  463. }
  464. }
  465. //订单类型
  466. if (!empty($order_type)) {
  467. $condition[] = [ "o.order_type", "=", $order_type ];
  468. }
  469. if (!empty($start_time) && empty($end_time)) {
  470. $condition[] = [ "o.create_time", ">=", date_to_time($start_time . ' 00:00:00') ];
  471. } elseif (empty($start_time) && !empty($end_time)) {
  472. $condition[] = [ "o.create_time", "<=", date_to_time($end_time . ' 23:59:59') ];
  473. } elseif (!empty($start_time) && !empty($end_time)) {
  474. $condition[] = [ 'o.create_time', 'between', [ date_to_time($start_time . ' 00:00:00'), date_to_time($end_time . ' 23:59:59') ] ];
  475. }
  476. $list = $order_common_model->getOrderPageList($condition, $page_index, $page_size, "o.create_time desc", 'o.*', $alias, $join);
  477. return $this->response($list);
  478. }
  479. /**
  480. * 订单列表(发票编辑)
  481. */
  482. public function invoiceEdit()
  483. {
  484. //接收数据
  485. $order_id = $this->params[ 'order_id' ] ?? '';
  486. $invoice_status = $this->params[ 'invoice_status' ] ?? '';
  487. $invoice_code = $this->params[ 'invoice_code' ] ?? '';
  488. $invoice_remark = $this->params[ 'invoice_remark' ] ?? '';
  489. $condition = [
  490. [ "order_id", "=", $order_id ]
  491. ];
  492. $data[ 'invoice_status' ] = $invoice_status;
  493. $data[ 'invoice_code' ] = $invoice_code;
  494. $data[ 'invoice_remark' ] = $invoice_remark;
  495. $data[ 'invoice_time' ] = time();
  496. $order_common_model = new OrderCommonModel();
  497. $res = $order_common_model->orderUpdate($data, $condition);
  498. return $this->response($res);
  499. }
  500. /**
  501. * 订单包裹信息
  502. */
  503. public function package()
  504. {
  505. $order_id = $this->params[ 'order_id' ] ?? '';//订单id
  506. $express_package_model = new ExpressPackage();
  507. $condition = array (
  508. [ "order_id", "=", $order_id ],
  509. );
  510. $order_model = new OrderCommonModel();
  511. $order_info = $order_model->getOrderInfo($condition)[ 'data' ] ?? [];
  512. $condition[] = [ 'site_id', '=', $order_info[ 'site_id' ] ];
  513. $package = $express_package_model->package($condition, $order_info[ 'mobile' ]);
  514. if ($package) {
  515. $result = [
  516. 'package' => $package,
  517. 'order_status' => $order_info[ 'order_status' ]
  518. ];
  519. return $this->response($this->success($result));
  520. } else {
  521. return $this->response($this->error());
  522. }
  523. }
  524. /**
  525. * 修改单个订单的物流信息(电子面单的除外)
  526. */
  527. public function editOrderDelivery()
  528. {
  529. $order_id = $this->params[ 'order_id' ] ?? 0;// 订单id
  530. $package_id = $this->params[ 'package_id' ] ?? 0;// 包裹id
  531. $delivery_type = $this->params[ 'delivery_type' ] ?? 0;// 是否需要物流
  532. $express_company_id = $this->params[ 'express_company_id' ] ?? '';// 物流公司
  533. $delivery_no = $this->params[ 'delivery_no' ] ?? '';// 物流单号
  534. $delivery_json = array (
  535. 'site_id' => $this->site_id,
  536. 'order_id' => $order_id,
  537. 'package_id' => $package_id,
  538. 'delivery_type' => $delivery_type,
  539. 'express_company_id' => $express_company_id,
  540. 'delivery_no' => $delivery_no
  541. );
  542. $express_package_model = new ExpressPackage();
  543. $res = $express_package_model->editOrderExpressDeliveryPackage($delivery_json);
  544. return $this->response($res);
  545. }
  546. /**
  547. * 确认收货
  548. */
  549. public function takeDelivery()
  550. {
  551. $order_id = $this->params[ 'order_id' ] ?? 0;// 订单id
  552. $order_model = new OrderCommonModel();
  553. $log_data = [
  554. 'uid' => $this->user_info[ 'uid' ],
  555. 'nick_name' => $this->user_info[ 'username' ],
  556. 'action_way' => 2
  557. ];
  558. $result = $order_model->orderCommonTakeDelivery($order_id, $log_data);
  559. return $this->response($result);
  560. }
  561. /**
  562. * 交易配置
  563. */
  564. public function config()
  565. {
  566. $config_model = new ConfigModel();
  567. //订单事件时间设置
  568. $order_event_time_config = $config_model->getOrderEventTimeConfig($this->site_id, $this->app_module);
  569. $order_event_time_config[ 'data' ][ 'value' ][ 'invoice_content' ] = explode(',', $order_event_time_config[ 'data' ][ 'value' ][ 'invoice_content' ]);
  570. $order_event_time_config[ 'data' ][ 'value' ][ 'invoice_type' ] = explode(',', $order_event_time_config[ 'data' ][ 'value' ][ 'invoice_type' ]);
  571. //订单评价设置
  572. $order_evaluate_config = $config_model->getOrderEvaluateConfig($this->site_id, $this->app_module);
  573. //余额支付配置
  574. $balance_config = $config_model->getBalanceConfig($this->site_id, $this->app_module);
  575. $data[ 'balance_config' ] = $balance_config[ 'data' ][ 'value' ];
  576. $data[ 'order_event_time_config' ] = $order_event_time_config[ 'data' ][ 'value' ];
  577. $data[ 'order_evaluate_config' ] = $order_evaluate_config[ 'data' ][ 'value' ];
  578. return $this->response($this->success($data));
  579. }
  580. public function setConfig()
  581. {
  582. $config_model = new ConfigModel();
  583. //订单事件时间设置数据
  584. $order_event_time_config_data = [
  585. 'auto_close' => $this->params[ 'order_auto_close_time' ] ?? 0,//订单未付款自动关闭时间 数字 单位(分钟)
  586. 'auto_take_delivery' => $this->params[ 'order_auto_take_delivery_time' ] ?? 0,//订单发货后自动收货时间 数字 单位(天)
  587. 'auto_complete' => $this->params[ 'order_auto_complete_time' ] ?? 0,//订单收货后自动完成时间 数字 单位(天)
  588. 'after_sales_time' => $this->params[ 'after_sales_time' ] ?? 0,//订单完成后可维权时间 数字 单位(天)
  589. 'invoice_status' => $this->params[ 'invoice_status' ] ?? 0,
  590. 'invoice_rate' => $this->params[ 'invoice_rate' ] ?? 0,
  591. 'invoice_content' => implode(',', explode(',', isset($this->params[ 'invoice_content' ]) && !empty($this->params[ 'invoice_content' ]) ? $this->params[ 'invoice_content' ] : '')),
  592. 'invoice_money' => $this->params[ 'invoice_money' ] ?? 0,
  593. 'invoice_type' => implode(',', explode(',', isset($this->params[ 'invoice_type' ]) && !empty($this->params[ 'invoice_type' ]) ? $this->params[ 'invoice_type' ] : ''))
  594. ];
  595. //订单评价设置数据
  596. $order_evaluate_config_data = [
  597. 'evaluate_status' => $this->params[ 'evaluate_status' ] ?? 0,//订单评价状态(0关闭 1开启)
  598. 'evaluate_show' => $this->params[ 'evaluate_show' ] ?? 0,//显示评价(0关闭 1开启)
  599. 'evaluate_audit' => $this->params[ 'evaluate_audit' ] ?? 0,//评价审核状态(0关闭 1开启)
  600. ];
  601. $res = $config_model->setOrderEventTimeConfig($order_event_time_config_data, $this->site_id, $this->app_module);
  602. $config_model->setOrderEvaluateConfig($order_evaluate_config_data, $this->site_id, $this->app_module);
  603. return $this->response($res);
  604. }
  605. }