Sellerorder.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  11. * 网站地址: https://www.valimart.net/
  12. * ----------------------------------------------------------------------------
  13. *
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Sellerorder extends BaseSeller {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerorder.lang.php');
  21. }
  22. /**
  23. * 订单列表
  24. *
  25. */
  26. public function index() {
  27. $order_model = model('order');
  28. $condition = array();
  29. $condition[] = array('store_id', '=', session('store_id'));
  30. $order_sn = input('get.order_sn');
  31. if ($order_sn != '') {
  32. $condition[] = array('order_sn', '=', $order_sn);
  33. }
  34. $buyer_name = input('get.buyer_name');
  35. if ($buyer_name != '') {
  36. $condition[] = array('buyer_name', '=', $buyer_name);
  37. }
  38. $allow_state_array = array('state_new', 'state_pay', 'state_send', 'state_success', 'state_cancel');
  39. $state_type = input('param.state_type');
  40. if (in_array($state_type, $allow_state_array)) {
  41. $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));
  42. } else {
  43. $state_type = 'store_order';
  44. }
  45. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('get.query_start_date'));
  46. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('get.query_end_date'));
  47. $start_unixtime = $if_start_date ? strtotime(input('get.query_start_date')) : null;
  48. $end_unixtime = $if_end_date ? (strtotime(input('get.query_end_date'))+86399) : null;
  49. if ($start_unixtime) {
  50. $condition[] = array('add_time', '>=', $start_unixtime);
  51. }
  52. if ($end_unixtime) {
  53. $condition[] = array('add_time', '<=', $end_unixtime);
  54. }
  55. $skip_off = input('get.buyer_name');
  56. if ($skip_off == 1) {
  57. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  58. }
  59. $order_list = $order_model->getOrderList($condition, 10, '*', 'order_id desc', 0, array('order_goods', 'order_common', 'ppintuanorder', 'member'));
  60. View::assign('show_page', $order_model->page_info->render());
  61. View::assign('expresscf_kdn_if_open', $this->store_info['expresscf_kdn_if_open']);
  62. //页面中显示那些操作
  63. foreach ($order_list as $key => $order_info) {
  64. //显示取消订单
  65. $order_info['if_cancel'] = $order_model->getOrderOperateState('store_cancel', $order_info);
  66. //显示调整运费
  67. $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
  68. //显示修改价格
  69. $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
  70. //显示发货
  71. $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
  72. //显示锁定中
  73. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  74. //显示物流跟踪
  75. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  76. foreach ($order_info['extend_order_goods'] as $value) {
  77. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  78. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  79. $value['goods_url'] = (string) url('Goods/index', ['goods_id' => $value['goods_id']]);
  80. if ($value['goods_type'] == 5) {
  81. $order_info['zengpin_list'][] = $value;
  82. } else {
  83. $order_info['goods_list'][] = $value;
  84. }
  85. }
  86. if (empty($order_info['zengpin_list'])) {
  87. $order_info['goods_count'] = count($order_info['goods_list']);
  88. } else {
  89. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  90. }
  91. $order_list[$key] = $order_info;
  92. }
  93. View::assign('order_list', $order_list);
  94. /* 设置卖家当前菜单 */
  95. $this->setSellerCurMenu('sellerorder');
  96. /* 设置卖家当前栏目 */
  97. $this->setSellerCurItem($state_type);
  98. return View::fetch($this->template_dir . 'index');
  99. }
  100. /**
  101. * 卖家订单详情
  102. *
  103. */
  104. public function show_order() {
  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. $state_type = input('param.state_type');
  201. $order_id = intval(input('param.order_id'));
  202. $order_model = model('order');
  203. $condition = array();
  204. $condition[] = array('order_id','=',$order_id);
  205. $condition[] = array('store_id','=',session('store_id'));
  206. $order_info = $order_model->getOrderInfo($condition);
  207. if ($state_type == 'order_cancel') {
  208. $result = $this->_order_cancel($order_info, input('post.'));
  209. } elseif ($state_type == 'modify_price') {
  210. $result = $this->_order_ship_price($order_info, input('post.'));
  211. } elseif ($state_type == 'spay_price') {
  212. $result = $this->_order_spay_price($order_info, input('post.'));
  213. }
  214. if (!$result['code']) {
  215. ds_json_encode(10001, $result['msg']);
  216. } else {
  217. ds_json_encode(10000, $result['msg']);
  218. }
  219. }
  220. /**
  221. * 打印订单
  222. *
  223. */
  224. public function print_order() {
  225. $order_id = ds_delete_param(input('param.order_id'));
  226. if (empty($order_id)) {
  227. $this->error(lang('param_error'));
  228. }
  229. $order_model = model('order');
  230. $condition = array();
  231. $condition[] = array('order_id','in',$order_id);
  232. $condition[] = array('store_id','=',session('store_id'));
  233. $order_list = $order_model->getOrderList($condition, '', '*', 'order_id desc', 0, array('order_common', 'order_goods'));
  234. if (empty($order_list)) {
  235. $this->error(lang('member_printorder_ordererror'));
  236. }
  237. //卖家信息
  238. $store_model = model('store');
  239. $store_info = $store_model->getStoreInfoByID(session('store_id'));
  240. if (!empty($store_info['store_avatar'])) {
  241. $store_info['store_avatar'] = ds_get_pic( ATTACH_STORE . DIRECTORY_SEPARATOR .$store_info['store_id'],$store_info['store_avatar']);
  242. }
  243. if (!empty($store_info['store_seal'])) {
  244. $store_info['store_seal'] = ds_get_pic( ATTACH_STORE , $store_info['store_seal']);
  245. }
  246. View::assign('store_info', $store_info);
  247. //订单商品
  248. foreach($order_list as $key =>$order_info){
  249. $goods_all_num = 0;
  250. $goods_total_price = 0;
  251. if (isset($order_info['extend_order_goods']) && !empty($order_info['extend_order_goods'])) {
  252. foreach ($order_info['extend_order_goods'] as $k => $v) {
  253. $v['goods_name'] = str_cut($v['goods_name'], 100);
  254. $goods_all_num += $v['goods_num'];
  255. $v['goods_all_price'] = ds_price_format($v['goods_num'] * $v['goods_price']);
  256. $goods_total_price += $v['goods_all_price'];
  257. $order_list[$key]['extend_order_goods'][$k]=$v;
  258. }
  259. //优惠金额
  260. $order_list[$key]['promotion_amount'] = $goods_total_price - $order_info['goods_amount'];
  261. $order_list[$key]['goods_all_num'] = $goods_all_num;
  262. $order_list[$key]['goods_total_price'] = ds_price_format($goods_total_price);
  263. $order_list[$key]['total_page'] = ceil(count($order_info['extend_order_goods']) / 15);
  264. }
  265. }
  266. View::assign('order_list', $order_list);
  267. return View::fetch($this->template_dir.'print_order');
  268. }
  269. /**
  270. * 打印订单
  271. *
  272. */
  273. public function print_eorder() {
  274. $order_id = ds_delete_param(input('param.order_id'));
  275. if (empty($order_id)) {
  276. $this->error(lang('param_error'));
  277. }
  278. $order_model = model('order');
  279. $condition = array();
  280. $condition[] = array('order_id','in',$order_id);
  281. $condition[] = array('store_id','=',session('store_id'));
  282. $order_list = $order_model->getOrderList($condition);
  283. if (empty($order_list)) {
  284. $this->error(lang('member_printorder_ordererror'));
  285. }
  286. $requestData=array();
  287. foreach($order_list as $key =>$order_info){
  288. $requestData[]=array(
  289. 'OrderCode'=>$order_info['order_sn'],
  290. 'PortName'=>$this->store_info['expresscf_kdn_printer'],
  291. );
  292. }
  293. $expresscf_kdn_config_model = model('expresscf_kdn_config');
  294. echo $expresscf_kdn_config_model->printExpresscfKdnOrder($requestData, $this->store_info['expresscf_kdn_id'], $this->store_info['expresscf_kdn_key']);
  295. }
  296. /**
  297. * 取消订单
  298. * @param unknown $order_info
  299. */
  300. private function _order_cancel($order_info, $post) {
  301. $order_model = model('order');
  302. $logic_order = model('order', 'logic');
  303. if (!request()->isPost()) {
  304. View::assign('order_info', $order_info);
  305. View::assign('order_id', $order_info['order_id']);
  306. echo View::fetch($this->template_dir . 'cancel');
  307. exit();
  308. } else {
  309. $if_allow = $order_model->getOrderOperateState('store_cancel', $order_info);
  310. if (!$if_allow) {
  311. return ds_callback(false, lang('have_no_legalpower'));
  312. }
  313. $msg = $post['state_info1'] != '' ? $post['state_info1'] : $post['state_info'];
  314. try{
  315. Db::startTrans();
  316. $logic_order->changeOrderStateCancel($order_info, 'seller', session('member_name'), $msg);
  317. } catch (\Exception $e) {
  318. Db::rollback();
  319. return ds_callback(false, $e->getMessage());
  320. }
  321. Db::commit();
  322. return ds_callback(true, lang('ds_common_op_succ'));
  323. }
  324. }
  325. /**
  326. * 修改运费
  327. * @param unknown $order_info
  328. */
  329. private function _order_ship_price($order_info, $post) {
  330. $order_model = model('order');
  331. $logic_order = model('order', 'logic');
  332. if (!request()->isPost()) {
  333. View::assign('order_info', $order_info);
  334. View::assign('order_id', $order_info['order_id']);
  335. echo View::fetch($this->template_dir . 'edit_price');
  336. exit();
  337. } else {
  338. $if_allow = $order_model->getOrderOperateState('modify_price', $order_info);
  339. if (!$if_allow) {
  340. return ds_callback(false, lang('have_no_legalpower'));
  341. }
  342. return $logic_order->changeOrderShipPrice($order_info, 'seller', session('member_name'), $post['shipping_fee']);
  343. }
  344. }
  345. /**
  346. * 修改商品价格
  347. * @param unknown $order_info
  348. */
  349. private function _order_spay_price($order_info, $post) {
  350. $order_model = model('order');
  351. $logic_order = model('order', 'logic');
  352. if (!request()->isPost()) {
  353. View::assign('order_info', $order_info);
  354. View::assign('order_id', $order_info['order_id']);
  355. echo View::fetch($this->template_dir . 'edit_spay_price');
  356. exit();
  357. } else {
  358. $if_allow = $order_model->getOrderOperateState('spay_price', $order_info);
  359. if (!$if_allow) {
  360. return ds_callback(false, lang('have_no_legalpower'));
  361. }
  362. return $logic_order->changeOrderSpayPrice($order_info, 'seller', session('member_name'), $post['goods_amount']);
  363. }
  364. }
  365. /**
  366. * 用户中心右边,小导航
  367. *
  368. * @param string $menu_type 导航类型
  369. * @param string $menu_key 当前导航的menu_key
  370. * @return
  371. */
  372. function getSellerItemList() {
  373. $menu_array = array(
  374. array(
  375. 'name' => 'store_order',
  376. 'text' => lang('ds_member_path_all_order'),
  377. 'url' => (string) url('Sellerorder/index')
  378. ),
  379. array(
  380. 'name' => 'state_new',
  381. 'text' => lang('ds_member_path_wait_pay'),
  382. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_new'])
  383. ),
  384. array(
  385. 'name' => 'state_pay',
  386. 'text' => lang('ds_member_path_wait_send'),
  387. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_pay'])
  388. ),
  389. array(
  390. 'name' => 'state_send',
  391. 'text' => lang('ds_member_path_sent'),
  392. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_send'])
  393. ),
  394. array(
  395. 'name' => 'state_success',
  396. 'text' => lang('ds_member_path_finished'),
  397. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_success'])
  398. ),
  399. array(
  400. 'name' => 'state_cancel',
  401. 'text' => lang('ds_member_path_canceled'),
  402. 'url' => (string) url('Sellerorder/index', ['state_type' => 'state_cancel'])
  403. ),
  404. );
  405. return $menu_array;
  406. }
  407. }
  408. ?>