Sellerdeliver.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. /**
  3. * 发货
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. *
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * 控制器
  15. */
  16. class Sellerdeliver extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeliver.lang.php');
  22. }
  23. /**
  24. * 发货列表
  25. *
  26. */
  27. public function index()
  28. {
  29. $order_model = model('order');
  30. $state = input('state');
  31. if (!in_array($state, array('deliverno', 'delivering', 'delivered'))) {
  32. $state = 'deliverno';
  33. }
  34. $order_state = str_replace(array('deliverno', 'delivering', 'delivered'), array(ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS), $state);
  35. $condition = array();
  36. $condition[] = array('store_id', '=', session('store_id'));
  37. $condition[] = array('order_state', '=', $order_state);
  38. $buyer_name = input('buyer_name');
  39. if ($buyer_name != '') {
  40. $condition[] = array('buyer_name', '=', $buyer_name);
  41. }
  42. $order_sn = input('order_sn');
  43. if ($order_sn != '') {
  44. $condition[] = array('order_sn', '=', $order_sn);
  45. }
  46. $query_start_date = input('query_start_date');
  47. $query_end_date = input('query_end_date');
  48. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  49. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  50. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  51. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  52. if ($start_unixtime) {
  53. $condition[] = array('add_time', '>=', $start_unixtime);
  54. }
  55. if ($end_unixtime) {
  56. $condition[] = array('add_time', '<=', $end_unixtime);
  57. }
  58. $order_list = $order_model->getOrderList($condition, '15', '*', 'order_id desc', 0, array('order_goods', 'order_common', 'ppintuanorder', 'member'));
  59. foreach ($order_list as $key => $order_info) {
  60. if (isset($order_info['extend_order_goods'])) {
  61. foreach ($order_info['extend_order_goods'] as $value) {
  62. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  63. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  64. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  65. if ($value['goods_type'] == 5) {
  66. $order_info['zengpin_list'][] = $value;
  67. } else {
  68. $order_info['goods_list'][] = $value;
  69. }
  70. }
  71. if (empty($order_info['zengpin_list'])) {
  72. $order_info['goods_count'] = count($order_info['goods_list']);
  73. } else {
  74. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  75. }
  76. }
  77. $order_list[$key] = $order_info;
  78. }
  79. View::assign('order_list', $order_list);
  80. View::assign('show_page', $order_model->page_info->render());
  81. /* 设置卖家当前菜单 */
  82. $this->setSellerCurMenu('sellerdeliver');
  83. /* 设置卖家当前栏目 */
  84. $this->setSellerCurItem(input('param.state'));
  85. return View::fetch($this->template_dir . 'index');
  86. }
  87. /**
  88. * 批量发货
  89. */
  90. public function batch_send()
  91. {
  92. $order_id = ds_delete_param(input('param.order_id'));
  93. $order_model = model('order');
  94. $daddress_model = model('daddress');
  95. $condition = array();
  96. $condition[] = array('order_id', 'in', $order_id);
  97. $condition[] = array('store_id', '=', session('store_id'));
  98. $condition[] = array('lock_state', '=', 0);
  99. $condition[] = array('order_state', 'in', array(ORDER_STATE_PAY));
  100. $order_list = $order_model->getOrderList($condition, '', '*', 'order_id desc', 0, array('order_common'));
  101. if (request()->isPost()) {
  102. if (empty($order_list)) {
  103. ds_json_encode(10001, lang('order_send_message'));
  104. }
  105. $send = input('param.send/a');
  106. $daddress_id = input('param.daddress_id');
  107. $express_id = input('param.express_id');
  108. $shipping_type = input('param.shipping_type');
  109. $logic_order = model('order', 'logic');
  110. if ($shipping_type == 3) {
  111. $express_id = 0;
  112. }
  113. $express_model = model('express');
  114. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  115. $daddress_list = array();
  116. $express_list = array();
  117. $expresscf_kdn_config_list = array();
  118. foreach ($order_list as $order_info) {
  119. if (empty($send[$order_info['order_id']])) {
  120. ds_json_encode(10001, lang('param_error'));
  121. }
  122. if (!$daddress_id) {
  123. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_confirm_daddress'));
  124. }
  125. if ($shipping_type != 3 && !$express_id) {
  126. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_express_select'));
  127. }
  128. if ($shipping_type == 2 && !$send[$order_info['order_id']]['shipping_code']) {
  129. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_shipping_code_pl'));
  130. }
  131. if ($shipping_type == 1) {
  132. if (!isset($express_list[$express_id])) {
  133. $express_list[$express_id] = $express_model->getExpressInfo($express_id);
  134. }
  135. $express_info = $express_list[$express_id];
  136. if (!$express_info) {
  137. ds_json_encode(10001, '快递公司不存在');
  138. }
  139. if (!isset($expresscf_kdn_config_list[$express_info['express_code']])) {
  140. $condition = array();
  141. $condition[] = array('express_code', '=', $express_info['express_code']);
  142. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  143. $expresscf_kdn_config_list[$express_info['express_code']] = $expresscf_kdn_config_model->getExpresscfKdnConfigInfo($condition);
  144. }
  145. $expresscf_kdn_config_info = $expresscf_kdn_config_list[$express_info['express_code']];
  146. if (!$expresscf_kdn_config_info) {
  147. ds_json_encode(10001, '电子面单不存在');
  148. }
  149. $area_array1 = preg_split("/\s+/", $order_info['extend_order_common']['reciver_info']['area']);
  150. if (count($area_array1) < 3) {
  151. ds_json_encode(10001, '收货地区必须选到3级');
  152. }
  153. if (!isset($daddress_list[$daddress_id])) {
  154. $condition = array();
  155. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  156. $condition[] = array('daddress_id', '=', $daddress_id);
  157. $daddress_list[$daddress_id] = $daddress_model->getAddressInfo($condition);
  158. }
  159. $daddress_info = $daddress_list[$daddress_id];
  160. if (empty($daddress_info)) {
  161. ds_json_encode(10001, '发货地址必填');
  162. }
  163. $area_array2 = preg_split("/\s+/", $daddress_info['area_info']);
  164. if (count($area_array2) < 3) {
  165. ds_json_encode(10001, '发货地区必须选到3级');
  166. }
  167. if (in_array($area_array1[0], ['北京市', '天津市', '上海市', '重庆市'])) {
  168. $area_array1[1] = $area_array1[0];
  169. $area_array1[0] = str_replace('市', '', $area_array1[0]);
  170. }
  171. if (in_array($area_array2[0], ['北京市', '天津市', '上海市', '重庆市'])) {
  172. $area_array2[1] = $area_array2[0];
  173. $area_array2[0] = str_replace('市', '', $area_array2[0]);
  174. }
  175. $goods_count = Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->count();
  176. $requestData = array(
  177. 'MemberID' => (string)$this->store_info['store_id'],
  178. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  179. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  180. 'SendSite' => $expresscf_kdn_config_info['expresscf_kdn_config_send_site'],
  181. 'SendStaff' => $expresscf_kdn_config_info['expresscf_kdn_config_send_staff'],
  182. 'MonthCode' => $expresscf_kdn_config_info['expresscf_kdn_config_month_code'],
  183. 'ShipperCode' => $express_info['express_code'],
  184. 'OrderCode' => $order_info['order_sn'],
  185. 'PayType' => $expresscf_kdn_config_info['expresscf_kdn_config_pay_type'],
  186. 'ExpType' => '1',
  187. 'Receiver' => array(
  188. 'Name' => $order_info['extend_order_common']['reciver_name'],
  189. 'Tel' => $order_info['extend_order_common']['reciver_info']['tel_phone'],
  190. 'Mobile' => $order_info['extend_order_common']['reciver_info']['mob_phone'],
  191. 'ProvinceName' => $area_array1[0],
  192. 'CityName' => $area_array1[1],
  193. 'ExpAreaName' => $area_array1[2],
  194. 'Address' => $order_info['extend_order_common']['reciver_info']['street'],
  195. ),
  196. 'Sender' => array(
  197. 'Name' => $daddress_info['seller_name'],
  198. 'Mobile' => $daddress_info['daddress_telphone'],
  199. 'ProvinceName' => $area_array2[0],
  200. 'CityName' => $area_array2[1],
  201. 'ExpAreaName' => $area_array2[2],
  202. 'Address' => $daddress_info['daddress_detail'],
  203. ),
  204. 'Quantity' => 1,
  205. 'Commodity' => array(array(
  206. 'GoodsName' => Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->value('goods_name') . ($goods_count > 1 ? '等' : '')
  207. ))
  208. );
  209. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1007', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  210. if ($result['Success'] != true) {
  211. ds_json_encode(10001, $result['Reason']);
  212. }
  213. $send[$order_info['order_id']]['shipping_code'] = $result['Order']['LogisticCode'];
  214. }
  215. $result = $logic_order->changeOrderSend($order_info, 'seller', session('seller_name'), array_merge($send[$order_info['order_id']], array(
  216. 'reciver_info' => serialize($order_info['extend_order_common']['reciver_info']),
  217. 'daddress_id' => $daddress_id,
  218. 'shipping_express_id' => $express_id,
  219. 'reciver_name' => $order_info['extend_order_common']['reciver_name'],
  220. 'reciver_area' => $order_info['extend_order_common']['reciver_info']['area'],
  221. 'reciver_street' => $order_info['extend_order_common']['reciver_info']['street'],
  222. 'reciver_mob_phone' => $order_info['extend_order_common']['reciver_info']['mob_phone'],
  223. 'reciver_tel_phone' => $order_info['extend_order_common']['reciver_info']['tel_phone'],
  224. 'deliver_explain' => $order_info['extend_order_common']['deliver_explain'],
  225. )));
  226. if (!$result['code']) {
  227. if ($shipping_type == 1) {
  228. $requestData = array(
  229. 'ShipperCode' => $express_info['express_code'],
  230. 'OrderCode' => $order_info['order_sn'],
  231. 'ExpNo' => $send[$order_info['order_id']]['shipping_code'],
  232. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  233. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  234. );
  235. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1147', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  236. if ($result['Success'] != true) {
  237. ds_json_encode(10001, $result['Reason']);
  238. }
  239. }
  240. ds_json_encode(10001, $result['msg']);
  241. }
  242. }
  243. ds_json_encode(10000, $result['msg']);
  244. } else {
  245. if (!empty($order_list)) {
  246. $daddress_list = $daddress_model->getAddressList(array('store_id' => session('store_id')), '*', 'daddress_isdefault desc');
  247. View::assign('daddress_list', $daddress_list);
  248. $express_list = rkcache('express', true);
  249. //快递公司
  250. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  251. if (!empty($my_express_list)) {
  252. $my_express_list = explode(',', $my_express_list);
  253. foreach ($express_list as $k => $v) {
  254. if (!in_array($v['express_id'], $my_express_list))
  255. unset($express_list[$k]);
  256. }
  257. } else {
  258. $express_list = array();
  259. }
  260. View::assign('my_express_list', array_values($express_list));
  261. }
  262. View::assign('order_list', $order_list);
  263. View::assign('expresscf_kdn_if_open', $this->store_info['expresscf_kdn_if_open']);
  264. return View::fetch($this->template_dir . 'batch_send');
  265. }
  266. }
  267. /**
  268. * 发货
  269. */
  270. public function send()
  271. {
  272. $order_id = input('param.order_id');
  273. if ($order_id <= 0) {
  274. ds_json_encode(10001, lang('param_error'));
  275. }
  276. $order_model = model('order');
  277. $condition = array();
  278. $condition[] = array('order_id', '=', $order_id);
  279. $condition[] = array('store_id', '=', session('store_id'));
  280. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  281. $if_allow_send = intval($order_info['lock_state']) || !in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND));
  282. if ($if_allow_send) {
  283. ds_json_encode(10001, lang('param_error'));
  284. }
  285. //取发货地址
  286. $daddress_model = model('daddress');
  287. $daddress_info = array();
  288. if ($order_info['extend_order_common']['daddress_id'] > 0) {
  289. $condition = array();
  290. $condition[] = array('store_id', '=', session('store_id'));
  291. $condition[] = array('daddress_id', '=', $order_info['extend_order_common']['daddress_id']);
  292. $daddress_info = $daddress_model->getAddressInfo($condition);
  293. }
  294. if (empty($daddress_info)) {
  295. //取默认地址
  296. $condition = array();
  297. $condition[] = array('store_id', '=', session('store_id'));
  298. $condition[] = array('daddress_isdefault', '=', 1);
  299. $daddress_info = $daddress_model->getAddressInfo($condition);
  300. }
  301. if (!request()->isPost()) {
  302. View::assign('expresscf_kdn_if_open', $this->store_info['expresscf_kdn_if_open']);
  303. View::assign('order_info', $order_info);
  304. if (!empty($daddress_info)) {
  305. //写入发货地址编号
  306. $this->_edit_order_daddress($daddress_info['daddress_id'], $order_id);
  307. } else {
  308. //写入发货地址编号
  309. $this->_edit_order_daddress(0, $order_id);
  310. }
  311. View::assign('daddress_info', $daddress_info);
  312. $express_list = rkcache('express', true);
  313. //快递公司
  314. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  315. if (!empty($my_express_list)) {
  316. $my_express_list = explode(',', $my_express_list);
  317. }
  318. View::assign('my_express_list', $my_express_list);
  319. View::assign('express_list', $express_list);
  320. /* 设置卖家当前菜单 */
  321. $this->setSellerCurMenu('sellerdeliver');
  322. /* 设置卖家当前栏目 */
  323. $this->setSellerCurItem('');
  324. return View::fetch($this->template_dir . 'send');
  325. } else {
  326. $logic_order = model('order', 'logic');
  327. $post = input('post.');
  328. $post['reciver_info'] = $this->_get_reciver_info();
  329. $express_model = model('express');
  330. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  331. if (input('param.shipping_type') == 'eorder') {
  332. if ($post['shipping_express_id'] == 0) {
  333. ds_json_encode(10001, '快递公司必填');
  334. }
  335. $express_info = $express_model->getExpressInfo(intval($post['shipping_express_id']));
  336. if (!$express_info) {
  337. ds_json_encode(10001, '快递公司不存在');
  338. }
  339. $condition = array();
  340. $condition[] = array('express_code', '=', $express_info['express_code']);
  341. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  342. $expresscf_kdn_config_info = $expresscf_kdn_config_model->getExpresscfKdnConfigInfo($condition);
  343. if (!$expresscf_kdn_config_info) {
  344. ds_json_encode(10001, '电子面单不存在');
  345. }
  346. $area_array1 = preg_split("/\s+/", input('post.reciver_area'));
  347. if (count($area_array1) < 3) {
  348. ds_json_encode(10001, '收货地区必须选到3级');
  349. }
  350. if (empty($daddress_info)) {
  351. ds_json_encode(10001, '发货地址必填');
  352. }
  353. $area_array2 = preg_split("/\s+/", $daddress_info['area_info']);
  354. if (count($area_array2) < 3) {
  355. ds_json_encode(10001, '发货地区必须选到3级');
  356. }
  357. if (in_array($area_array1[0], ['北京市', '天津市', '上海市', '重庆市'])) {
  358. $area_array1[1] = $area_array1[0];
  359. $area_array1[0] = str_replace('市', '', $area_array1[0]);
  360. }
  361. if (in_array($area_array2[0], ['北京市', '天津市', '上海市', '重庆市'])) {
  362. $area_array2[1] = $area_array2[0];
  363. $area_array2[0] = str_replace('市', '', $area_array2[0]);
  364. }
  365. $goods_count = Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->count();
  366. $requestData = array(
  367. 'MemberID' => (string)$this->store_info['store_id'],
  368. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  369. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  370. 'SendSite' => $expresscf_kdn_config_info['expresscf_kdn_config_send_site'],
  371. 'SendStaff' => $expresscf_kdn_config_info['expresscf_kdn_config_send_staff'],
  372. 'MonthCode' => $expresscf_kdn_config_info['expresscf_kdn_config_month_code'],
  373. 'ShipperCode' => $express_info['express_code'],
  374. 'OrderCode' => $order_info['order_sn'],
  375. 'PayType' => $expresscf_kdn_config_info['expresscf_kdn_config_pay_type'],
  376. 'ExpType' => '1',
  377. 'Receiver' => array(
  378. 'Name' => input('post.reciver_name'),
  379. 'Tel' => input('post.reciver_tel_phone'),
  380. 'Mobile' => input('post.reciver_mob_phone'),
  381. 'ProvinceName' => $area_array1[0],
  382. 'CityName' => $area_array1[1],
  383. 'ExpAreaName' => $area_array1[2],
  384. 'Address' => input('post.reciver_street'),
  385. ),
  386. 'Sender' => array(
  387. 'Name' => $daddress_info['seller_name'],
  388. 'Mobile' => $daddress_info['daddress_telphone'],
  389. 'ProvinceName' => $area_array2[0],
  390. 'CityName' => $area_array2[1],
  391. 'ExpAreaName' => $area_array2[2],
  392. 'Address' => $daddress_info['daddress_detail'],
  393. ),
  394. 'Quantity' => 1,
  395. 'Commodity' => array(array(
  396. 'GoodsName' => Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->value('goods_name') . ($goods_count > 1 ? '等' : '')
  397. ))
  398. );
  399. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1007', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  400. if ($result['Success'] != true) {
  401. ds_json_encode(10001, $result['Reason']);
  402. }
  403. $post['shipping_code'] = $result['Order']['LogisticCode'];
  404. }
  405. $result = $logic_order->changeOrderSend($order_info, 'seller', session('seller_name'), $post);
  406. if (!$result['code']) {
  407. if (input('param.shipping_type') == 'eorder') {
  408. $requestData = array(
  409. 'ShipperCode' => $express_info['express_code'],
  410. 'OrderCode' => $order_info['order_sn'],
  411. 'ExpNo' => $post['shipping_code'],
  412. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  413. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  414. );
  415. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1147', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  416. if ($result['Success'] != true) {
  417. ds_json_encode(10001, $result['Reason']);
  418. }
  419. }
  420. ds_json_encode(10001, $result['msg']);
  421. } else {
  422. ds_json_encode(10000, $result['msg']);
  423. }
  424. }
  425. }
  426. /**
  427. * 编辑收货地址
  428. * @return boolean
  429. */
  430. public function buyer_address_edit()
  431. {
  432. $order_id = input('param.order_id');
  433. if ($order_id <= 0) {
  434. return false;
  435. }
  436. $order_model = model('order');
  437. $condition = array();
  438. $condition[] = array('order_id', '=', $order_id);
  439. $condition[] = array('store_id', '=', session('store_id'));
  440. $order_common_info = $order_model->getOrdercommonInfo($condition);
  441. if (!$order_common_info) {
  442. return false;
  443. }
  444. $order_common_info['reciver_info'] = @unserialize($order_common_info['reciver_info']);
  445. View::assign('address_info', $order_common_info);
  446. return View::fetch($this->template_dir . 'buyer_address_edit');
  447. }
  448. /**
  449. * 收货地址保存
  450. */
  451. public function buyer_address_save()
  452. {
  453. $order_model = model('order');
  454. $data = array();
  455. $data['reciver_name'] = input('post.reciver_name');
  456. $data['reciver_info'] = $this->_get_reciver_info();
  457. $condition = array();
  458. $condition[] = array('order_id', '=', intval(input('post.order_id')));
  459. $condition[] = array('store_id', '=', session('store_id'));
  460. $result = $order_model->editOrdercommon($data, $condition);
  461. if ($result) {
  462. echo 'true';
  463. } else {
  464. echo 'flase';
  465. }
  466. }
  467. /**
  468. * 组合reciver_info
  469. */
  470. private function _get_reciver_info()
  471. {
  472. $reciver_info = array(
  473. 'address' => input('post.reciver_area') . ' ' . input('post.reciver_street'),
  474. 'phone' => trim(input('post.reciver_mob_phone') . ',' . input('post.reciver_tel_phone'), ','),
  475. 'area' => input('post.reciver_area'),
  476. 'street' => input('post.reciver_street'),
  477. 'mob_phone' => input('post.reciver_mob_phone'),
  478. 'tel_phone' => input('post.reciver_tel_phone'),
  479. 'chain' => input('post.reciver_chain'),
  480. );
  481. return serialize($reciver_info);
  482. }
  483. /**
  484. * 选择发货地址
  485. * @return boolean
  486. */
  487. public function send_address_select()
  488. {
  489. $address_list = model('daddress')->getAddressList(array('store_id' => session('store_id')));
  490. View::assign('address_list', $address_list);
  491. View::assign('order_id', input('param.order_id'));
  492. return View::fetch($this->template_dir . 'send_address_select');
  493. }
  494. /**
  495. * 保存发货地址修改
  496. */
  497. public function send_address_save()
  498. {
  499. $result = $this->_edit_order_daddress(input('post.daddress_id'), input('post.order_id'));
  500. if ($result >= 0) {
  501. echo 'true';
  502. } else {
  503. echo 'flase';
  504. }
  505. }
  506. /**
  507. * 修改发货地址
  508. */
  509. private function _edit_order_daddress($daddress_id, $order_id)
  510. {
  511. $order_model = model('order');
  512. $data = array();
  513. $data['daddress_id'] = intval($daddress_id);
  514. $condition = array();
  515. $condition[] = array('order_id', '=', $order_id);
  516. $condition[] = array('store_id', '=', session('store_id'));
  517. return $order_model->editOrdercommon($data, $condition);
  518. }
  519. /**
  520. * 物流跟踪
  521. */
  522. public function search_deliver()
  523. {
  524. $order_sn = input('param.order_sn');
  525. if (!is_numeric($order_sn)) {
  526. $this->error(lang('param_error'));
  527. }
  528. $order_model = model('order');
  529. $condition = array();
  530. $condition[] = array('order_sn', '=', $order_sn);
  531. $condition[] = array('store_id', '=', session('store_id'));
  532. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  533. if (empty($order_info) || $order_info['shipping_code'] == '') {
  534. $this->error(lang('no_information_found'));
  535. }
  536. $order_info['state_info'] = get_order_state($order_info);
  537. View::assign('order_info', $order_info);
  538. //卖家发货信息
  539. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  540. View::assign('daddress_info', $daddress_info);
  541. //取得配送公司代码
  542. $express = rkcache('express', true);
  543. View::assign('express_code', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'] : '');
  544. View::assign('express_name', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'] : '');
  545. View::assign('express_url', isset($express[$order_info['extend_order_common']['shipping_express_id']]) ? $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'] : '');
  546. View::assign('shipping_code', $order_info['shipping_code']);
  547. /* 设置卖家当前菜单 */
  548. $this->setSellerCurMenu('sellerdeliver');
  549. /* 设置卖家当前栏目 */
  550. $this->setSellerCurItem('');
  551. return View::fetch($this->template_dir . 'search_deliver');
  552. }
  553. /**
  554. * 延迟收货
  555. */
  556. public function delay_receive()
  557. {
  558. $order_id = input('param.order_id');
  559. $order_model = model('order');
  560. $condition = array();
  561. $condition[] = array('order_id', '=', $order_id);
  562. $condition[] = array('store_id', '=', session('store_id'));
  563. $condition[] = array('lock_state', '=', 0);
  564. $order_info = $order_model->getOrderInfo($condition);
  565. //取目前系统最晚收货时间
  566. $delay_time = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 3600 * 24;
  567. if (request()->isPost()) {
  568. $delay_date = intval(input('post.delay_date'));
  569. if (!in_array($delay_date, array(5, 10, 15))) {
  570. ds_json_encode(10001, lang('param_error'));
  571. }
  572. $update = $order_model->editOrder(array('delay_time' => Db::raw('delay_time+' . $delay_date * 3600 * 24)), $condition);
  573. if ($update) {
  574. //新的最晚收货时间
  575. $dalay_date = date('Y-m-d H:i:s', $delay_time + $delay_date * 3600 * 24);
  576. ds_json_encode(10000, lang('successful_delivery_deadline') . $dalay_date . '&emsp;');
  577. } else {
  578. ds_json_encode(10000, lang('delayed_failure'));
  579. }
  580. } else {
  581. $order_info['delay_time'] = $delay_time;
  582. View::assign('order_info', $order_info);
  583. return View::fetch($this->template_dir . 'delay_receive');
  584. }
  585. }
  586. /**
  587. * 从第三方取快递信息
  588. *
  589. */
  590. public function get_express()
  591. {
  592. $result = model('express')->queryExpress(input('param.express_code'), input('param.shipping_code'), input('param.phone'));
  593. if ($result['Success'] != true) {
  594. exit(json_encode(false));
  595. }
  596. $content['Traces'] = array_reverse($result['Traces']);
  597. $output = array();
  598. if (is_array($content['Traces'])) {
  599. foreach ($content['Traces'] as $k => $v) {
  600. if ($v['AcceptTime'] == '') {
  601. continue;
  602. }
  603. $output[] = '<li>' . $v['AcceptTime'] . '&nbsp;&nbsp;' . $v['AcceptStation'] . '</li>';
  604. }
  605. }
  606. if ($output == '')
  607. exit(json_encode(false));
  608. echo json_encode($output);
  609. }
  610. /**
  611. * 用户中心右边,小导航
  612. *
  613. * @param string $menu_type 导航类型
  614. * @param string $name 当前导航的name
  615. * @return
  616. */
  617. protected function getSellerItemList()
  618. {
  619. $menu_array = array();
  620. $menu_type = request()->action();
  621. switch ($menu_type) {
  622. case 'index':
  623. $menu_array = array(
  624. array('name' => 'deliverno', 'text' => lang('ds_member_path_deliverno'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'deliverno'])),
  625. array('name' => 'delivering', 'text' => lang('ds_member_path_delivering'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'delivering'])),
  626. array('name' => 'delivered', 'text' => lang('ds_member_path_delivered'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'delivered'])),
  627. );
  628. break;
  629. case 'search':
  630. $menu_array = array(
  631. array('name' => 'nodeliver', 'text' => lang('ds_member_path_deliverno'), 'url' => (string) url('Sellerdeliver/index/state/nodeliver')),
  632. array('name' => 'delivering', 'text' => lang('ds_member_path_delivering'), 'url' => (string) url('Sellerdeliver/index/state/delivering')),
  633. array('name' => 'delivered', 'text' => lang('ds_member_path_delivered'), 'url' => (string) url('Sellerdeliver/index/state/delivered')),
  634. array('name' => 'search', 'text' => lang('ds_member_path_deliver_info'), 'url' => '###'),
  635. );
  636. break;
  637. }
  638. return $menu_array;
  639. }
  640. }