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