Sellerdeliver.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Sellerdeliver extends BaseSeller {
  22. public function initialize() {
  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. $order_model = model('order');
  32. $state = input('state');
  33. if (!in_array($state, array('deliverno', 'delivering', 'delivered'))) {
  34. $state = 'deliverno';
  35. }
  36. $order_state = str_replace(array('deliverno', 'delivering', 'delivered'), array(ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS), $state);
  37. $condition = array();
  38. $condition[] = array('store_id', '=', session('store_id'));
  39. $condition[] = array('order_state', '=', $order_state);
  40. $buyer_name = input('buyer_name');
  41. if ($buyer_name != '') {
  42. $condition[] = array('buyer_name', '=', $buyer_name);
  43. }
  44. $order_sn = input('order_sn');
  45. if ($order_sn != '') {
  46. $condition[] = array('order_sn', '=', $order_sn);
  47. }
  48. $query_start_date = input('query_start_date');
  49. $query_end_date = input('query_end_date');
  50. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_start_date);
  51. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $query_end_date);
  52. $start_unixtime = $if_start_date ? strtotime($query_start_date) : null;
  53. $end_unixtime = $if_end_date ? (strtotime($query_end_date) + 86399) : null;
  54. if ($start_unixtime) {
  55. $condition[] = array('add_time', '>=', $start_unixtime);
  56. }
  57. if ($end_unixtime) {
  58. $condition[] = array('add_time', '<=', $end_unixtime);
  59. }
  60. $order_list = $order_model->getOrderList($condition, '15', '*', 'order_id desc', 0, array('order_goods', 'order_common', 'ppintuanorder', 'member'));
  61. foreach ($order_list as $key => $order_info) {
  62. if (isset($order_info['extend_order_goods'])) {
  63. foreach ($order_info['extend_order_goods'] as $value) {
  64. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  65. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  66. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  67. if ($value['goods_type'] == 5) {
  68. $order_info['zengpin_list'][] = $value;
  69. } else {
  70. $order_info['goods_list'][] = $value;
  71. }
  72. }
  73. if (empty($order_info['zengpin_list'])) {
  74. $order_info['goods_count'] = count($order_info['goods_list']);
  75. } else {
  76. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  77. }
  78. }
  79. $order_list[$key] = $order_info;
  80. }
  81. View::assign('order_list', $order_list);
  82. View::assign('show_page', $order_model->page_info->render());
  83. /* 设置卖家当前菜单 */
  84. $this->setSellerCurMenu('sellerdeliver');
  85. /* 设置卖家当前栏目 */
  86. $this->setSellerCurItem(input('param.state'));
  87. return View::fetch($this->template_dir . 'index');
  88. }
  89. /**
  90. * 批量发货
  91. */
  92. public function batch_send() {
  93. $order_id = ds_delete_param(input('param.order_id'));
  94. $order_model = model('order');
  95. $daddress_model = model('daddress');
  96. $condition = array();
  97. $condition[] = array('order_id', 'in', $order_id);
  98. $condition[] = array('store_id', '=', session('store_id'));
  99. $condition[] = array('lock_state', '=', 0);
  100. $condition[] = array('order_state', 'in', array(ORDER_STATE_PAY));
  101. $order_list = $order_model->getOrderList($condition, '', '*', 'order_id desc', 0, array('order_common'));
  102. if (request()->isPost()) {
  103. if (empty($order_list)) {
  104. ds_json_encode(10001, lang('order_send_message'));
  105. }
  106. $send = input('param.send/a');
  107. $daddress_id = input('param.daddress_id');
  108. $express_id = input('param.express_id');
  109. $shipping_type = input('param.shipping_type');
  110. $logic_order = model('order', 'logic');
  111. if ($shipping_type == 3) {
  112. $express_id = 0;
  113. }
  114. $express_model = model('express');
  115. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  116. $daddress_list = array();
  117. $express_list = array();
  118. $expresscf_kdn_config_list = array();
  119. foreach ($order_list as $order_info) {
  120. if (empty($send[$order_info['order_id']])) {
  121. ds_json_encode(10001, lang('param_error'));
  122. }
  123. if (!$daddress_id) {
  124. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_confirm_daddress'));
  125. }
  126. if ($shipping_type != 3 && !$express_id) {
  127. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_express_select'));
  128. }
  129. if ($shipping_type == 2 && !$send[$order_info['order_id']]['shipping_code']) {
  130. ds_json_encode(10001, lang('store_order_order_sn') . $order_info['order_sn'] . ':' . lang('store_deliver_shipping_code_pl'));
  131. }
  132. if ($shipping_type == 1) {
  133. if (!isset($express_list[$express_id])) {
  134. $express_list[$express_id] = $express_model->getExpressInfo($express_id);
  135. }
  136. $express_info = $express_list[$express_id];
  137. if (!$express_info) {
  138. ds_json_encode(10001, '快递公司不存在');
  139. }
  140. if (!isset($expresscf_kdn_config_list[$express_info['express_code']])) {
  141. $condition = array();
  142. $condition[] = array('express_code', '=', $express_info['express_code']);
  143. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  144. $expresscf_kdn_config_list[$express_info['express_code']] = $expresscf_kdn_config_model->getExpresscfKdnConfigInfo($condition);
  145. }
  146. $expresscf_kdn_config_info = $expresscf_kdn_config_list[$express_info['express_code']];
  147. if (!$expresscf_kdn_config_info) {
  148. ds_json_encode(10001, '电子面单不存在');
  149. }
  150. $area_array1 = preg_split("/\s+/", $order_info['extend_order_common']['reciver_info']['area']);
  151. if (count($area_array1) < 3) {
  152. ds_json_encode(10001, '收货地区必须选到3级');
  153. }
  154. if (!isset($daddress_list[$daddress_id])) {
  155. $condition = array();
  156. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  157. $condition[] = array('daddress_id', '=', $daddress_id);
  158. $daddress_list[$daddress_id] = $daddress_model->getAddressInfo($condition);
  159. }
  160. $daddress_info = $daddress_list[$daddress_id];
  161. if (empty($daddress_info)) {
  162. ds_json_encode(10001, '发货地址必填');
  163. }
  164. $area_array2 = preg_split("/\s+/", $daddress_info['area_info']);
  165. if (count($area_array2) < 3) {
  166. ds_json_encode(10001, '发货地区必须选到3级');
  167. }
  168. if(in_array($area_array1[0],['北京市','天津市','上海市','重庆市'])){
  169. $area_array1[1]=$area_array1[0];
  170. $area_array1[0]=str_replace('市','',$area_array1[0]);
  171. }
  172. if(in_array($area_array2[0],['北京市','天津市','上海市','重庆市'])){
  173. $area_array2[1]=$area_array2[0];
  174. $area_array2[0]=str_replace('市','',$area_array2[0]);
  175. }
  176. $goods_count = Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->count();
  177. $requestData = array(
  178. 'MemberID' => (String)$this->store_info['store_id'],
  179. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  180. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  181. 'SendSite' => $expresscf_kdn_config_info['expresscf_kdn_config_send_site'],
  182. 'SendStaff' => $expresscf_kdn_config_info['expresscf_kdn_config_send_staff'],
  183. 'MonthCode' => $expresscf_kdn_config_info['expresscf_kdn_config_month_code'],
  184. 'ShipperCode' => $express_info['express_code'],
  185. 'OrderCode' => $order_info['order_sn'],
  186. 'PayType' => $expresscf_kdn_config_info['expresscf_kdn_config_pay_type'],
  187. 'ExpType' => '1',
  188. 'Receiver' => array(
  189. 'Name' => $order_info['extend_order_common']['reciver_name'],
  190. 'Tel' => $order_info['extend_order_common']['reciver_info']['tel_phone'],
  191. 'Mobile' => $order_info['extend_order_common']['reciver_info']['mob_phone'],
  192. 'ProvinceName' => $area_array1[0],
  193. 'CityName' => $area_array1[1],
  194. 'ExpAreaName' => $area_array1[2],
  195. 'Address' => $order_info['extend_order_common']['reciver_info']['street'],
  196. ),
  197. 'Sender' => array(
  198. 'Name' => $daddress_info['seller_name'],
  199. 'Mobile' => $daddress_info['daddress_telphone'],
  200. 'ProvinceName' => $area_array2[0],
  201. 'CityName' => $area_array2[1],
  202. 'ExpAreaName' => $area_array2[2],
  203. 'Address' => $daddress_info['daddress_detail'],
  204. ),
  205. 'Quantity' => 1,
  206. 'Commodity' => array(array(
  207. 'GoodsName' => Db::name('ordergoods')->where(array(array('order_id', '=', $order_info['order_id'])))->value('goods_name') . ($goods_count > 1 ? '等' : '')
  208. ))
  209. );
  210. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1007', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  211. if ($result['Success'] != true) {
  212. ds_json_encode(10001, $result['Reason']);
  213. }
  214. $send[$order_info['order_id']]['shipping_code'] = $result['Order']['LogisticCode'];
  215. }
  216. $result = $logic_order->changeOrderSend($order_info, 'seller', session('seller_name'), array_merge($send[$order_info['order_id']], array(
  217. 'reciver_info' => serialize($order_info['extend_order_common']['reciver_info']),
  218. 'daddress_id' => $daddress_id,
  219. 'shipping_express_id' => $express_id,
  220. 'reciver_name' => $order_info['extend_order_common']['reciver_name'],
  221. 'reciver_area' => $order_info['extend_order_common']['reciver_info']['area'],
  222. 'reciver_street' => $order_info['extend_order_common']['reciver_info']['street'],
  223. 'reciver_mob_phone' => $order_info['extend_order_common']['reciver_info']['mob_phone'],
  224. 'reciver_tel_phone' => $order_info['extend_order_common']['reciver_info']['tel_phone'],
  225. 'deliver_explain' => $order_info['extend_order_common']['deliver_explain'],
  226. )));
  227. if (!$result['code']) {
  228. if ($shipping_type == 1) {
  229. $requestData = array(
  230. 'ShipperCode' => $express_info['express_code'],
  231. 'OrderCode' => $order_info['order_sn'],
  232. 'ExpNo' => $send[$order_info['order_id']]['shipping_code'],
  233. 'CustomerName' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_name'],
  234. 'CustomerPwd' => $expresscf_kdn_config_info['expresscf_kdn_config_customer_pwd'],
  235. );
  236. $result = $expresscf_kdn_config_model->requestExpresscfKdnApi($requestData, '1147', $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  237. if ($result['Success'] != true) {
  238. ds_json_encode(10001, $result['Reason']);
  239. }
  240. }
  241. ds_json_encode(10001, $result['msg']);
  242. }
  243. }
  244. ds_json_encode(10000, $result['msg']);
  245. } else {
  246. if (!empty($order_list)) {
  247. $daddress_list = $daddress_model->getAddressList(array('store_id' => session('store_id')), '*', 'daddress_isdefault desc');
  248. View::assign('daddress_list', $daddress_list);
  249. $express_list = rkcache('express', true);
  250. //快递公司
  251. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', session('store_id'), 'express');
  252. if (!empty($my_express_list)) {
  253. $my_express_list = explode(',', $my_express_list);
  254. foreach ($express_list as $k => $v) {
  255. if (!in_array($v['express_id'], $my_express_list))
  256. unset($express_list[$k]);
  257. }
  258. }else {
  259. $express_list = array();
  260. }
  261. View::assign('my_express_list', array_values($express_list));
  262. }
  263. View::assign('order_list', $order_list);
  264. View::assign('expresscf_kdn_if_open', $this->store_info['expresscf_kdn_if_open']);
  265. return View::fetch($this->template_dir . 'batch_send');
  266. }
  267. }
  268. /**
  269. * 发货
  270. */
  271. public function send() {
  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. $order_id = input('param.order_id');
  432. if ($order_id <= 0) {
  433. return false;
  434. }
  435. $order_model = model('order');
  436. $condition = array();
  437. $condition[] = array('order_id', '=', $order_id);
  438. $condition[] = array('store_id', '=', session('store_id'));
  439. $order_common_info = $order_model->getOrdercommonInfo($condition);
  440. if (!$order_common_info) {
  441. return false;
  442. }
  443. $order_common_info['reciver_info'] = @unserialize($order_common_info['reciver_info']);
  444. View::assign('address_info', $order_common_info);
  445. return View::fetch($this->template_dir . 'buyer_address_edit');
  446. }
  447. /**
  448. * 收货地址保存
  449. */
  450. public function buyer_address_save() {
  451. $order_model = model('order');
  452. $data = array();
  453. $data['reciver_name'] = input('post.reciver_name');
  454. $data['reciver_info'] = $this->_get_reciver_info();
  455. $condition = array();
  456. $condition[] = array('order_id', '=', intval(input('post.order_id')));
  457. $condition[] = array('store_id', '=', session('store_id'));
  458. $result = $order_model->editOrdercommon($data, $condition);
  459. if ($result) {
  460. echo 'true';
  461. } else {
  462. echo 'flase';
  463. }
  464. }
  465. /**
  466. * 组合reciver_info
  467. */
  468. private function _get_reciver_info() {
  469. $reciver_info = array(
  470. 'address' => input('post.reciver_area') . ' ' . input('post.reciver_street'),
  471. 'phone' => trim(input('post.reciver_mob_phone') . ',' . input('post.reciver_tel_phone'), ','),
  472. 'area' => input('post.reciver_area'),
  473. 'street' => input('post.reciver_street'),
  474. 'mob_phone' => input('post.reciver_mob_phone'),
  475. 'tel_phone' => input('post.reciver_tel_phone'),
  476. 'chain' => input('post.reciver_chain'),
  477. );
  478. return serialize($reciver_info);
  479. }
  480. /**
  481. * 选择发货地址
  482. * @return boolean
  483. */
  484. public function send_address_select() {
  485. $address_list = model('daddress')->getAddressList(array('store_id' => session('store_id')));
  486. View::assign('address_list', $address_list);
  487. View::assign('order_id', input('param.order_id'));
  488. return View::fetch($this->template_dir . 'send_address_select');
  489. }
  490. /**
  491. * 保存发货地址修改
  492. */
  493. public function send_address_save() {
  494. $result = $this->_edit_order_daddress(input('post.daddress_id'), input('post.order_id'));
  495. if ($result >= 0) {
  496. echo 'true';
  497. } else {
  498. echo 'flase';
  499. }
  500. }
  501. /**
  502. * 修改发货地址
  503. */
  504. private function _edit_order_daddress($daddress_id, $order_id) {
  505. $order_model = model('order');
  506. $data = array();
  507. $data['daddress_id'] = intval($daddress_id);
  508. $condition = array();
  509. $condition[] = array('order_id', '=', $order_id);
  510. $condition[] = array('store_id', '=', session('store_id'));
  511. return $order_model->editOrdercommon($data, $condition);
  512. }
  513. /**
  514. * 物流跟踪
  515. */
  516. public function search_deliver() {
  517. $order_sn = input('param.order_sn');
  518. if (!is_numeric($order_sn)) {
  519. $this->error(lang('param_error'));
  520. }
  521. $order_model = model('order');
  522. $condition = array();
  523. $condition[] = array('order_sn', '=', $order_sn);
  524. $condition[] = array('store_id', '=', session('store_id'));
  525. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  526. if (empty($order_info) || $order_info['shipping_code'] == '') {
  527. $this->error(lang('no_information_found'));
  528. }
  529. $order_info['state_info'] = get_order_state($order_info);
  530. View::assign('order_info', $order_info);
  531. //卖家发货信息
  532. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  533. View::assign('daddress_info', $daddress_info);
  534. //取得配送公司代码
  535. $express = rkcache('express', true);
  536. 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'] : '');
  537. 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'] : '');
  538. 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'] : '');
  539. View::assign('shipping_code', $order_info['shipping_code']);
  540. /* 设置卖家当前菜单 */
  541. $this->setSellerCurMenu('sellerdeliver');
  542. /* 设置卖家当前栏目 */
  543. $this->setSellerCurItem('');
  544. return View::fetch($this->template_dir . 'search_deliver');
  545. }
  546. /**
  547. * 延迟收货
  548. */
  549. public function delay_receive() {
  550. $order_id = input('param.order_id');
  551. $order_model = model('order');
  552. $condition = array();
  553. $condition[] = array('order_id', '=', $order_id);
  554. $condition[] = array('store_id', '=', session('store_id'));
  555. $condition[] = array('lock_state', '=', 0);
  556. $order_info = $order_model->getOrderInfo($condition);
  557. //取目前系统最晚收货时间
  558. $delay_time = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 3600 * 24;
  559. if (request()->isPost()) {
  560. $delay_date = intval(input('post.delay_date'));
  561. if (!in_array($delay_date, array(5, 10, 15))) {
  562. ds_json_encode(10001, lang('param_error'));
  563. }
  564. $update = $order_model->editOrder(array('delay_time' => Db::raw('delay_time+' . $delay_date * 3600 * 24)), $condition);
  565. if ($update) {
  566. //新的最晚收货时间
  567. $dalay_date = date('Y-m-d H:i:s', $delay_time + $delay_date * 3600 * 24);
  568. ds_json_encode(10000, lang('successful_delivery_deadline') . $dalay_date . '&emsp;');
  569. } else {
  570. ds_json_encode(10000, lang('delayed_failure'));
  571. }
  572. } else {
  573. $order_info['delay_time'] = $delay_time;
  574. View::assign('order_info', $order_info);
  575. return View::fetch($this->template_dir . 'delay_receive');
  576. }
  577. }
  578. /**
  579. * 从第三方取快递信息
  580. *
  581. */
  582. public function get_express() {
  583. $result = model('express')->queryExpress(input('param.express_code'), input('param.shipping_code'), input('param.phone'));
  584. if ($result['Success'] != true) {
  585. exit(json_encode(false));
  586. }
  587. $content['Traces'] = array_reverse($result['Traces']);
  588. $output = array();
  589. if (is_array($content['Traces'])) {
  590. foreach ($content['Traces'] as $k => $v) {
  591. if ($v['AcceptTime'] == '') {
  592. continue;
  593. }
  594. $output[] = '<li>' . $v['AcceptTime'] . '&nbsp;&nbsp;' . $v['AcceptStation'] . '</li>';
  595. }
  596. }
  597. if ($output == '')
  598. exit(json_encode(false));
  599. echo json_encode($output);
  600. }
  601. /**
  602. * 用户中心右边,小导航
  603. *
  604. * @param string $menu_type 导航类型
  605. * @param string $name 当前导航的name
  606. * @return
  607. */
  608. protected function getSellerItemList() {
  609. $menu_array = array();
  610. $menu_type = request()->action();
  611. switch ($menu_type) {
  612. case 'index':
  613. $menu_array = array(
  614. array('name' => 'deliverno', 'text' => lang('ds_member_path_deliverno'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'deliverno'])),
  615. array('name' => 'delivering', 'text' => lang('ds_member_path_delivering'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'delivering'])),
  616. array('name' => 'delivered', 'text' => lang('ds_member_path_delivered'), 'url' => (string) url('Sellerdeliver/index', ['state' => 'delivered'])),
  617. );
  618. break;
  619. case 'search':
  620. $menu_array = array(
  621. array('name' => 'nodeliver', 'text' => lang('ds_member_path_deliverno'), 'url' => (string) url('Sellerdeliver/index/state/nodeliver')),
  622. array('name' => 'delivering', 'text' => lang('ds_member_path_delivering'), 'url' => (string) url('Sellerdeliver/index/state/delivering')),
  623. array('name' => 'delivered', 'text' => lang('ds_member_path_delivered'), 'url' => (string) url('Sellerdeliver/index/state/delivered')),
  624. array('name' => 'search', 'text' => lang('ds_member_path_deliver_info'), 'url' => '###'),
  625. );
  626. break;
  627. }
  628. return $menu_array;
  629. }
  630. }