Sellerorder.php 20 KB

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