Sellerorder.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Sellerorder extends BaseSeller
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerorder.lang.php');
  19. }
  20. /**
  21. * 订单列表
  22. *
  23. */
  24. public function index()
  25. {
  26. $order_model = model('order');
  27. $condition = array();
  28. $condition[] = array('store_id', '=', session('store_id'));
  29. $order_sn = input('get.order_sn');
  30. if ($order_sn != '') {
  31. $condition[] = array('order_sn', '=', $order_sn);
  32. }
  33. $buyer_name = input('get.buyer_name');
  34. if ($buyer_name != '') {
  35. $condition[] = array('buyer_name', '=', $buyer_name);
  36. }
  37. $allow_state_array = array('state_new', 'state_pay', 'state_send', 'state_success', 'state_cancel');
  38. $state_type = input('param.state_type');
  39. if (in_array($state_type, $allow_state_array)) {
  40. $condition[] = array('order_state', '=', str_replace($allow_state_array, array(ORDER_STATE_NEW, ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS, ORDER_STATE_CANCEL), $state_type));
  41. } else {
  42. $state_type = 'store_order';
  43. }
  44. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('get.query_start_date'));
  45. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('get.query_end_date'));
  46. $start_unixtime = $if_start_date ? strtotime(input('get.query_start_date')) : null;
  47. $end_unixtime = $if_end_date ? (strtotime(input('get.query_end_date')) + 86399) : null;
  48. if ($start_unixtime) {
  49. $condition[] = array('add_time', '>=', $start_unixtime);
  50. }
  51. if ($end_unixtime) {
  52. $condition[] = array('add_time', '<=', $end_unixtime);
  53. }
  54. $skip_off = input('get.buyer_name');
  55. if ($skip_off == 1) {
  56. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  57. }
  58. $order_list = $order_model->getOrderList($condition, 10, '*', 'order_id desc', 0, array('order_goods', 'order_common', 'ppintuanorder', 'member'));
  59. View::assign('show_page', $order_model->page_info->render());
  60. View::assign('expresscf_kdn_if_open', $this->store_info['expresscf_kdn_if_open']);
  61. //页面中显示那些操作
  62. foreach ($order_list as $key => $order_info) {
  63. //显示取消订单
  64. $order_info['if_cancel'] = $order_model->getOrderOperateState('store_cancel', $order_info);
  65. //显示调整运费
  66. $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
  67. //显示修改价格
  68. $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
  69. //显示发货
  70. $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
  71. //显示锁定中
  72. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  73. //显示物流跟踪
  74. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  75. foreach ($order_info['extend_order_goods'] as $value) {
  76. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  77. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  78. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  79. if ($value['goods_type'] == 5) {
  80. $order_info['zengpin_list'][] = $value;
  81. } else {
  82. $order_info['goods_list'][] = $value;
  83. }
  84. }
  85. if (empty($order_info['zengpin_list'])) {
  86. $order_info['goods_count'] = count($order_info['goods_list']);
  87. } else {
  88. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  89. }
  90. $order_list[$key] = $order_info;
  91. }
  92. View::assign('order_list', $order_list);
  93. /* 设置卖家当前菜单 */
  94. $this->setSellerCurMenu('sellerorder');
  95. /* 设置卖家当前栏目 */
  96. $this->setSellerCurItem($state_type);
  97. return View::fetch($this->template_dir . 'index');
  98. }
  99. /**
  100. * 卖家订单详情
  101. *
  102. */
  103. public function show_order()
  104. {
  105. $order_id = intval(input('param.order_id'));
  106. if ($order_id <= 0) {
  107. $this->error(lang('param_error'));
  108. }
  109. $order_model = model('order');
  110. $condition = array();
  111. $condition[] = array('order_id', '=', $order_id);
  112. $condition[] = array('store_id', '=', session('store_id'));
  113. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods', 'member', 'ppintuanorder'));
  114. if (empty($order_info)) {
  115. $this->error(lang('store_order_none_exist'));
  116. }
  117. $refundreturn_model = model('refundreturn');
  118. $order_list = array();
  119. $order_list[$order_id] = $order_info;
  120. $order_list = $refundreturn_model->getGoodsRefundList($order_list, 1); //订单商品的退款退货显示
  121. $order_info = $order_list[$order_id];
  122. $refund_all = isset($order_info['refund_list'][0]) ? $order_info['refund_list'][0] : '';
  123. if (!empty($refund_all) && $refund_all['seller_state'] < 3) { //订单全部退款商家审核状态:1为待审核,2为同意,3为不同意
  124. View::assign('refund_all', $refund_all);
  125. }
  126. //显示锁定中
  127. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  128. //显示调整运费
  129. $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
  130. //显示调整价格
  131. $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
  132. //显示取消订单
  133. $order_info['if_cancel'] = $order_model->getOrderOperateState('store_cancel', $order_info);
  134. //显示发货
  135. $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
  136. //显示物流跟踪
  137. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  138. //显示系统自动取消订单日期
  139. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  140. $order_info['order_cancel_day'] = $order_info['add_time'] + config('ds_config.order_auto_cancel_day') * 24 * 3600;
  141. }
  142. //显示快递信息
  143. $express = rkcache('express', true);
  144. if ($order_info['shipping_code'] != '' && isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
  145. $order_info['express_info']['express_code'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
  146. $order_info['express_info']['express_name'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
  147. $order_info['express_info']['express_url'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'];
  148. } else {
  149. $order_info['express_info']['express_code'] = '';
  150. $order_info['express_info']['express_name'] = '';
  151. $order_info['express_info']['express_url'] = '';
  152. }
  153. //显示系统自动收获时间
  154. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  155. $order_info['order_confirm_day'] = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 24 * 3600;
  156. }
  157. //如果订单已取消,取得取消原因、时间,操作人
  158. if ($order_info['order_state'] == ORDER_STATE_CANCEL) {
  159. $order_info['close_info'] = $order_model->getOrderlogInfo(array('order_id' => $order_info['order_id']), 'log_id desc');
  160. }
  161. $order_info['chain_order_type'] = 0;
  162. //如果是待自提则获取提货码
  163. $chain_order_model = model('chain_order');
  164. $chain_order_info = $chain_order_model->getChainOrderInfo(array(array('order_id', '=', $order_info['order_id'])));
  165. if ($chain_order_info) {
  166. $order_info['chain_order_type'] = $chain_order_info['chain_order_type'];
  167. }
  168. foreach ($order_info['extend_order_goods'] as $value) {
  169. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  170. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  171. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  172. if ($value['goods_type'] == 5) {
  173. $order_info['zengpin_list'][] = $value;
  174. } else {
  175. $order_info['goods_list'][] = $value;
  176. }
  177. }
  178. if (empty($order_info['zengpin_list'])) {
  179. $order_info['goods_count'] = count($order_info['goods_list']);
  180. } else {
  181. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  182. }
  183. View::assign('order_info', $order_info);
  184. //发货信息
  185. if (!empty($order_info['extend_order_common']['daddress_id'])) {
  186. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  187. View::assign('daddress_info', $daddress_info);
  188. }
  189. /* 设置卖家当前菜单 */
  190. $this->setSellerCurMenu('sellerorder');
  191. /* 设置卖家当前栏目 */
  192. $this->setSellerCurItem();
  193. return View::fetch($this->template_dir . 'show_order');
  194. }
  195. /**
  196. * 卖家订单状态操作
  197. *
  198. */
  199. public function change_state()
  200. {
  201. $state_type = input('param.state_type');
  202. $order_id = intval(input('param.order_id'));
  203. $order_model = model('order');
  204. $condition = array();
  205. $condition[] = array('order_id', '=', $order_id);
  206. $condition[] = array('store_id', '=', session('store_id'));
  207. $order_info = $order_model->getOrderInfo($condition);
  208. if ($state_type == 'order_cancel') {
  209. $result = $this->_order_cancel($order_info, input('post.'));
  210. } elseif ($state_type == 'modify_price') {
  211. $result = $this->_order_ship_price($order_info, input('post.'));
  212. } elseif ($state_type == 'spay_price') {
  213. $result = $this->_order_spay_price($order_info, input('post.'));
  214. }
  215. if (!$result['code']) {
  216. ds_json_encode(10001, $result['msg']);
  217. } else {
  218. ds_json_encode(10000, $result['msg']);
  219. }
  220. }
  221. /**
  222. * 打印订单
  223. *
  224. */
  225. public function print_order()
  226. {
  227. $order_id = ds_delete_param(input('param.order_id'));
  228. if (empty($order_id)) {
  229. $this->error(lang('param_error'));
  230. }
  231. $order_model = model('order');
  232. $condition = array();
  233. $condition[] = array('order_id', 'in', $order_id);
  234. $condition[] = array('store_id', '=', session('store_id'));
  235. $order_list = $order_model->getOrderList($condition, '', '*', 'order_id desc', 0, array('order_common', 'order_goods'));
  236. if (empty($order_list)) {
  237. $this->error(lang('member_printorder_ordererror'));
  238. }
  239. //卖家信息
  240. $store_model = model('store');
  241. $store_info = $store_model->getStoreInfoByID(session('store_id'));
  242. if (!empty($store_info['store_avatar'])) {
  243. $store_info['store_avatar'] = ds_get_pic(ATTACH_STORE . DIRECTORY_SEPARATOR . $store_info['store_id'], $store_info['store_avatar']);
  244. }
  245. if (!empty($store_info['store_seal'])) {
  246. $store_info['store_seal'] = ds_get_pic(ATTACH_STORE, $store_info['store_seal']);
  247. }
  248. View::assign('store_info', $store_info);
  249. //订单商品
  250. foreach ($order_list as $key => $order_info) {
  251. $goods_all_num = 0;
  252. $goods_total_price = 0;
  253. if (isset($order_info['extend_order_goods']) && !empty($order_info['extend_order_goods'])) {
  254. foreach ($order_info['extend_order_goods'] as $k => $v) {
  255. $v['goods_name'] = str_cut($v['goods_name'], 100);
  256. $goods_all_num += $v['goods_num'];
  257. $v['goods_all_price'] = ds_price_format($v['goods_num'] * $v['goods_price']);
  258. $goods_total_price += $v['goods_all_price'];
  259. $order_list[$key]['extend_order_goods'][$k] = $v;
  260. }
  261. //优惠金额
  262. $order_list[$key]['promotion_amount'] = $goods_total_price - $order_info['goods_amount'];
  263. $order_list[$key]['goods_all_num'] = $goods_all_num;
  264. $order_list[$key]['goods_total_price'] = ds_price_format($goods_total_price);
  265. $order_list[$key]['total_page'] = ceil(count($order_info['extend_order_goods']) / 15);
  266. }
  267. }
  268. View::assign('order_list', $order_list);
  269. return View::fetch($this->template_dir . 'print_order');
  270. }
  271. /**
  272. * 打印订单
  273. *
  274. */
  275. public function print_eorder()
  276. {
  277. $order_id = ds_delete_param(input('param.order_id'));
  278. if (empty($order_id)) {
  279. $this->error(lang('param_error'));
  280. }
  281. $order_model = model('order');
  282. $condition = array();
  283. $condition[] = array('order_id', 'in', $order_id);
  284. $condition[] = array('store_id', '=', session('store_id'));
  285. $order_list = $order_model->getOrderList($condition);
  286. if (empty($order_list)) {
  287. $this->error(lang('member_printorder_ordererror'));
  288. }
  289. $requestData = array();
  290. foreach ($order_list as $key => $order_info) {
  291. $requestData[] = array(
  292. 'OrderCode' => $order_info['order_sn'],
  293. 'PortName' => $this->store_info['expresscf_kdn_printer'],
  294. );
  295. }
  296. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  297. echo $expresscf_kdn_config_model->printExpresscfKdnOrder($requestData, $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  298. }
  299. /**
  300. * 取消订单
  301. * @param unknown $order_info
  302. */
  303. private function _order_cancel($order_info, $post)
  304. {
  305. $order_model = model('order');
  306. $logic_order = model('order', 'logic');
  307. if (!request()->isPost()) {
  308. View::assign('order_info', $order_info);
  309. View::assign('order_id', $order_info['order_id']);
  310. echo View::fetch($this->template_dir . 'cancel');
  311. exit();
  312. } else {
  313. $if_allow = $order_model->getOrderOperateState('store_cancel', $order_info);
  314. if (!$if_allow) {
  315. return ds_callback(false, lang('have_no_legalpower'));
  316. }
  317. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  318. try {
  319. Db::startTrans();
  320. $logic_order->changeOrderStateCancel($order_info, 'seller', session('member_name'), $msg);
  321. } catch (\Exception $e) {
  322. Db::rollback();
  323. return ds_callback(false, $e->getMessage());
  324. }
  325. Db::commit();
  326. return ds_callback(true, lang('ds_common_op_succ'));
  327. }
  328. }
  329. /**
  330. * 修改运费
  331. * @param unknown $order_info
  332. */
  333. private function _order_ship_price($order_info, $post)
  334. {
  335. $order_model = model('order');
  336. $logic_order = model('order', 'logic');
  337. if (!request()->isPost()) {
  338. View::assign('order_info', $order_info);
  339. View::assign('order_id', $order_info['order_id']);
  340. echo View::fetch($this->template_dir . 'edit_price');
  341. exit();
  342. } else {
  343. $if_allow = $order_model->getOrderOperateState('modify_price', $order_info);
  344. if (!$if_allow) {
  345. return ds_callback(false, lang('have_no_legalpower'));
  346. }
  347. return $logic_order->changeOrderShipPrice($order_info, 'seller', session('member_name'), $post['shipping_fee']);
  348. }
  349. }
  350. /**
  351. * 修改商品价格
  352. * @param unknown $order_info
  353. */
  354. private function _order_spay_price($order_info, $post)
  355. {
  356. $order_model = model('order');
  357. $logic_order = model('order', 'logic');
  358. if (!request()->isPost()) {
  359. View::assign('order_info', $order_info);
  360. View::assign('order_id', $order_info['order_id']);
  361. echo View::fetch($this->template_dir . 'edit_spay_price');
  362. exit();
  363. } else {
  364. $if_allow = $order_model->getOrderOperateState('spay_price', $order_info);
  365. if (!$if_allow) {
  366. return ds_callback(false, lang('have_no_legalpower'));
  367. }
  368. return $logic_order->changeOrderSpayPrice($order_info, 'seller', session('member_name'), $post['goods_amount']);
  369. }
  370. }
  371. /**
  372. * 用户中心右边,小导航
  373. *
  374. * @param string $menu_type 导航类型
  375. * @param string $menu_key 当前导航的menu_key
  376. * @return
  377. */
  378. function getSellerItemList()
  379. {
  380. $menu_array = array(
  381. array(
  382. 'name' => 'store_order',
  383. 'text' => lang('ds_member_path_all_order'),
  384. 'url' => (string) url('Sellerorder/index')
  385. ),
  386. array(
  387. 'name' => 'state_new',
  388. 'text' => lang('ds_member_path_wait_pay'),
  389. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_new'])
  390. ),
  391. array(
  392. 'name' => 'state_pay',
  393. 'text' => lang('ds_member_path_wait_send'),
  394. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_pay'])
  395. ),
  396. array(
  397. 'name' => 'state_send',
  398. 'text' => lang('ds_member_path_sent'),
  399. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_send'])
  400. ),
  401. array(
  402. 'name' => 'state_success',
  403. 'text' => lang('ds_member_path_finished'),
  404. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_success'])
  405. ),
  406. array(
  407. 'name' => 'state_cancel',
  408. 'text' => lang('ds_member_path_canceled'),
  409. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_cancel'])
  410. ),
  411. );
  412. return $menu_array;
  413. }
  414. }