Sellerorder.php 19 KB

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