Delivery.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\express\Config as ConfigModel;
  12. use app\model\express\ExpressPackage;
  13. use app\model\order\OrderCommon as OrderCommonModel;
  14. use app\model\order\Order as OrderModel;
  15. use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
  16. use app\model\web\Config as WebConfig;
  17. use addon\electronicsheet\model\ElectronicsheetDelivery;
  18. use phpoffice\phpexcel\Classes\PHPExcel;
  19. use phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007;
  20. /**
  21. * 配送
  22. * Class Express
  23. * @package app\shop\controller
  24. */
  25. class Delivery extends BaseShop
  26. {
  27. /**
  28. * 发货列表
  29. */
  30. public function lists()
  31. {
  32. $order_label_list = array (
  33. 'order_no' => '订单号',
  34. 'out_trade_no' => '外部单号',
  35. 'name' => '收货人姓名',
  36. 'order_name' => '商品名称',
  37. "mobile" => "收货人电话",
  38. );
  39. $order_model = new OrderModel();
  40. $order_status_list = $order_model->delivery_order_status;
  41. $order_status = input('order_status', '');//订单状态
  42. $order_name = input('order_name', '');
  43. $pay_type = input('pay_type', '');
  44. $order_from = input('order_from', '');
  45. $start_time = input('start_time', '');
  46. $end_time = input('end_time', '');
  47. $order_label = !empty($order_label_list[ input('order_label') ]) ? input('order_label') : '';
  48. $search_text = input('search', '');
  49. $promotion_type = input('promotion_type', '');//订单类型
  50. $order_type = input('order_type', 'all');//营销类型
  51. $order_common_model = new OrderCommonModel();
  52. if (request()->isAjax()) {
  53. $page_index = input('page', 1);
  54. $page_size = input('page_size', PAGE_LIST_ROWS);
  55. $condition = [
  56. [ 'order_type', '=', 1 ],
  57. [ 'site_id', '=', $this->site_id ],
  58. [ 'is_delete', '=', 0 ]
  59. ];
  60. //订单状态
  61. if ($order_status != "") {
  62. $condition[] = [ "order_status", "=", $order_status ];
  63. } else {
  64. $condition[] = [ 'order_status', 'in', array_keys($order_status_list) ];
  65. }
  66. //订单内容 模糊查询
  67. if ($order_name != "") {
  68. $condition[] = [ "order_name", 'like', "%$order_name%" ];
  69. }
  70. //订单来源
  71. if ($order_from != "") {
  72. $condition[] = [ "order_from", "=", $order_from ];
  73. }
  74. //订单支付
  75. if ($pay_type != "") {
  76. $condition[] = [ "pay_type", "=", $pay_type ];
  77. }
  78. //订单类型
  79. if ($order_type != 'all') {
  80. $condition[] = [ "order_type", "=", $order_type ];
  81. }
  82. //营销类型
  83. if ($promotion_type != "") {
  84. if ($promotion_type == 'empty') {
  85. $condition[] = [ "promotion_type", "=", '' ];
  86. } else {
  87. $condition[] = [ "promotion_type", "=", $promotion_type ];
  88. }
  89. }
  90. if (!empty($start_time) && empty($end_time)) {
  91. $condition[] = [ "create_time", ">=", date_to_time($start_time) ];
  92. } elseif (empty($start_time) && !empty($end_time)) {
  93. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  94. } elseif (!empty($start_time) && !empty($end_time)) {
  95. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  96. }
  97. if ($search_text != "") {
  98. $condition[] = [ $order_label, 'like', "%$search_text%" ];
  99. }
  100. $list = $order_common_model->getOrderPageList($condition, $page_index, $page_size, 'create_time desc');
  101. return $list;
  102. } else {
  103. $this->assign('order_label_list', $order_label_list);
  104. //订单来源 (支持端口)
  105. $order_from = $order_common_model->getOrderFromList();
  106. $this->assign('order_from_list', $order_from);
  107. $pay_type = $order_common_model->getPayType();
  108. $this->assign('pay_type_list', $pay_type);
  109. $this->assign('http_type', get_http_type());
  110. $config_model = new WebConfig();
  111. $mp_config = $config_model->getMapConfig($this->site_id);
  112. $this->assign('tencent_map_key', $mp_config[ 'data' ][ 'value' ][ 'tencent_map_key' ] ?? '');
  113. $this->assign('delivery_order_status', $order_status_list);//订单状态
  114. return $this->fetch('delivery/lists');
  115. }
  116. }
  117. /**
  118. * 配送方式
  119. */
  120. public function express()
  121. {
  122. $config_model = new ConfigModel();
  123. $config_result = $config_model->getExpressConfig($this->site_id);
  124. $express_config = $config_result[ 'data' ];
  125. $this->assign('express_config', $express_config);
  126. $config_result = $config_model->getStoreConfig($this->site_id);
  127. $store_config = $config_result[ 'data' ];
  128. $this->assign('store_config', $store_config);
  129. $config_result = $config_model->getLocalDeliveryConfig($this->site_id);
  130. $local_delivery_config = $config_result[ 'data' ];
  131. $this->assign('local_delivery_config', $local_delivery_config);
  132. $deliver_type = $config_model->getDeliverTypeSort($this->site_id);
  133. $this->assign('deliver_type', explode(',', $deliver_type[ 'data' ][ 'value' ][ 'deliver_type' ]));
  134. return $this->fetch('delivery/delivery');
  135. }
  136. /**
  137. * 物流开关配置
  138. * @return \multitype
  139. */
  140. public function modifyExpressStatus()
  141. {
  142. $config_model = new ConfigModel();
  143. if (request()->isAjax()) {
  144. $is_use = input('is_use', 0);
  145. $data = array (
  146. 'express_name' => input('express_name')
  147. );
  148. $result = $config_model->setExpressConfig($data, $is_use, $this->site_id);
  149. return $result;
  150. }
  151. }
  152. /**
  153. * 自提配置开关
  154. * @return \multitype
  155. */
  156. public function modifyStoreStatus()
  157. {
  158. $config_model = new ConfigModel();
  159. if (request()->isAjax()) {
  160. $is_use = input('is_use', 0);
  161. $data = array (
  162. 'store_name' => input('store_name')
  163. );
  164. $result = $config_model->setStoreConfig($data, $is_use, $this->site_id);
  165. return $result;
  166. }
  167. }
  168. /**
  169. * 外卖配送配置开关
  170. * @return \multitype
  171. */
  172. public function modifyLocalStatus()
  173. {
  174. $config_model = new ConfigModel();
  175. if (request()->isAjax()) {
  176. $is_use = input('is_use', 0);
  177. $data = array (
  178. 'local_name' => input('local_name')
  179. );
  180. $result = $config_model->setLocalDeliveryConfig($data, $is_use, $this->site_id);
  181. return $result;
  182. }
  183. }
  184. /**
  185. * 外卖配送
  186. */
  187. public function localConfig()
  188. {
  189. $config_model = new ConfigModel();
  190. if (request()->isAjax()) {
  191. $is_use = input('is_use', 0);
  192. $data = array ();
  193. $result = $config_model->setLocalDeliveryConfig($data, $is_use, $this->site_id);
  194. return $result;
  195. } else {
  196. $config_result = $config_model->getLocalDeliveryConfig($this->site_id);
  197. $config = $config_result[ 'data' ];
  198. $this->assign('config', $config);
  199. return $this->fetch('delivery/local_config');
  200. }
  201. }
  202. /**
  203. * 获取电子面单模板列表
  204. */
  205. public function getExpressElectronicsheetList()
  206. {
  207. //电子面单插件
  208. $addon_is_exit = addon_is_exit('electronicsheet', $this->site_id);
  209. if ($addon_is_exit == 1) {
  210. //获取电子面单模板
  211. $electronicsheet_model = new ExpressElectronicsheetModel();
  212. $condition[] = [ 'site_id', '=', $this->site_id ];
  213. $electronicsheet_list = $electronicsheet_model->getExpressElectronicsheetList($condition, '', 'is_default desc');
  214. return $electronicsheet_list;
  215. } else {
  216. return success(0, 'success', []);
  217. }
  218. }
  219. /**
  220. * 批量发货
  221. */
  222. public function batchDelivery()
  223. {
  224. if (request()->isAjax()) {
  225. $order_model = new OrderModel();
  226. $data = array (
  227. 'type' => input('type', 'manual'),//发货方式(手动发货、电子面单)
  228. 'express_company_id' => input('express_company_id', 0),//物流公司
  229. 'delivery_type' => input('delivery_type', 0),//是否需要物流
  230. 'site_id' => $this->site_id,
  231. 'template_id' => input('template_id', 0),//电子面单模板id
  232. );
  233. $order_list = input('order_list', '');
  234. $result = $order_model->orderBatchDelivery($data, $order_list);
  235. return $result;
  236. }
  237. }
  238. /**
  239. * 打印电子面单
  240. */
  241. public function printElectronicsheet()
  242. {
  243. if (request()->isAjax()) {
  244. $addon_is_exit = addon_is_exit('electronicsheet', $this->site_id);
  245. if ($addon_is_exit != 1) {
  246. return [
  247. 'code' => -1001,
  248. 'message' => '电子面单插件不存在',
  249. 'data' => ''
  250. ];
  251. }
  252. $order_model = new OrderModel();
  253. $data = array (
  254. 'type' => 'electronicsheet',//电子面单
  255. 'express_company_id' => 0,//物流公司
  256. 'delivery_type' => 1,
  257. 'site_id' => $this->site_id,
  258. 'template_id' => input('template_id', 0),//电子面单模板id
  259. 'is_delivery' => input('is_delivery', 0),//是否发货
  260. 'order_id' => input('order_id'),//订单id
  261. 'order_goods_ids' => '',
  262. 'delivery_no' => ''
  263. );
  264. $electronicsheet_model = new ElectronicsheetDelivery();
  265. $result = $electronicsheet_model->delivery($data);
  266. if ($result[ 'code' ] >= 0) {
  267. if ($data[ 'is_delivery' ] == 1) {//发货
  268. $data[ 'delivery_no' ] = $result[ 'data' ][ 'Order' ][ 'LogisticCode' ];
  269. $res = $order_model->orderGoodsDelivery($data, 2);
  270. if ($res[ 'code' ] < 0) {
  271. return $res;
  272. }
  273. }
  274. }
  275. return $result;
  276. }
  277. }
  278. /**
  279. * 获取单个订单的物流信息(电子面单的除外)
  280. */
  281. public function getOrderDelivery()
  282. {
  283. if (request()->isAjax()) {
  284. $order_id = input('order_id', '');
  285. $condition = [
  286. [ 'order_id', '=', $order_id ],
  287. [ 'site_id', '=', $this->site_id ],
  288. [ 'type', '=', 'manual' ]
  289. ];
  290. $express_package_model = new ExpressPackage();
  291. $list = $express_package_model->getExpressDeliveryPackageList($condition);
  292. return $list;
  293. }
  294. }
  295. /**
  296. * 修改单个订单的物流信息(电子面单的除外)
  297. */
  298. public function editOrderDelivery()
  299. {
  300. if (request()->isAjax()) {
  301. $delivery_json = array (
  302. 'site_id' => $this->site_id,
  303. 'order_id' => input('order_id', ''),//订单id
  304. 'package_id' => input('package_id', 0),//包裹id
  305. 'delivery_type' => input('delivery_type', 0),//是否需要物流
  306. 'express_company_id' => input('express_company_id', 0),//物流公司
  307. 'delivery_no' => input('delivery_no', ''),//物流单号
  308. );
  309. $express_package_model = new ExpressPackage();
  310. $res = $express_package_model->editOrderExpressDeliveryPackage($delivery_json);
  311. return $res;
  312. }
  313. }
  314. /**
  315. * 配送方式排序
  316. */
  317. public function deliverTypeSort()
  318. {
  319. if (request()->isAjax()) {
  320. $config_model = new ConfigModel();
  321. $deliver_type = input('deliver_type', '');
  322. $result = $config_model->setDeliverTypeSort([ 'deliver_type' => $deliver_type ], $this->site_id);
  323. return $result;
  324. }
  325. }
  326. }