Sellerorder.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. use think\facade\Db;
  5. /**
  6. *
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * 卖家订单控制器
  11. */
  12. class Sellerorder extends MobileSeller
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize(); // TODO: Change the autogenerated stub
  17. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerorder.lang.php');
  18. }
  19. /**
  20. * @api {POST} api/Sellerorder/order_list 订单列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Sellerorder
  23. *
  24. * @apiHeader {String} X-DS-KEY 卖家授权token
  25. *
  26. * @apiParam {String} order_sn 订单号
  27. * @apiParam {String} buyer_name 用户名
  28. * @apiParam {String} state_type 订单状态 state_new待付款 state_pay待发货 state_send待收货 state_success已完成 state_cancel已取消
  29. * @apiParam {String} query_start_date 开始日期 YYYY-MM-DD
  30. * @apiParam {String} query_end_date 结束日期 YYYY-MM-DD
  31. * @apiParam {String} page 页码
  32. * @apiParam {String} pagesize 每页显示数量
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. * @apiSuccess {Object[]} result.order_list 订单列表 (返回字段参考order表)
  38. * @apiSuccess {Boolean} result.order_list.if_cancel 是否可取消 true是false否
  39. * @apiSuccess {Boolean} result.order_list.if_modify_price 是否可修改运费 true是false否
  40. * @apiSuccess {Boolean} result.order_list.if_spay_price 是否可修改商品价格 true是false否
  41. * @apiSuccess {Boolean} result.order_list.if_send 是否可发货 true是false否
  42. * @apiSuccess {Boolean} result.order_list.if_lock 是否被锁定 true是false否
  43. * @apiSuccess {Boolean} result.order_list.if_deliver 是否显示物流跟踪 true是false否
  44. * @apiSuccess {Object} result.order_list.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  45. * @apiSuccess {Object} result.order_list.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  46. * @apiSuccess {Object} result.order_list.extend_order_goods.image_240_url 商品图片完整路径
  47. * @apiSuccess {Object} result.order_list.extend_order_goods.goods_type_cn 商品类型名称
  48. * @apiSuccess {Object} result.order_list.extend_order_goods.goods_url 商品PC链接
  49. * @apiSuccess {Object} result.order_list.extend_member 用户信息 (返回字段参考member表)
  50. * @apiSuccess {object} result.order_list.zengpin_list 赠品列表 (返回字段参考ordergoods表)
  51. * @apiSuccess {object} result.order_list.goods_list 订单商品列表 (返回字段参考ordergoods表)
  52. * @apiSuccess {object} result.order_list.goods_count 商品数量
  53. * @apiSuccess {Int} result.page_total 总页数
  54. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  55. */
  56. public function order_list()
  57. {
  58. $order_model = model('order');
  59. $condition = array();
  60. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  61. $order_sn = input('post.order_sn');
  62. if (!empty($order_sn)) {
  63. $condition[] = array('order_sn', '=', $order_sn);
  64. }
  65. $buyer_name = input('post.buyer_name');
  66. $pagesize = intval('pagesize');
  67. if (!empty($buyer_name)) {
  68. $condition[] = array('buyer_name', '=', $buyer_name);
  69. }
  70. $allow_state_array = array('state_new', 'state_pay', 'state_send', 'state_success', 'state_cancel');
  71. $state_type = input('post.state_type');
  72. if (in_array($state_type, $allow_state_array)) {
  73. $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));
  74. }
  75. $if_start_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_start_date'));
  76. $if_end_date = preg_match('/^20\d{2}-\d{2}-\d{2}$/', input('param.query_end_date'));
  77. $start_unixtime = $if_start_date ? strtotime(input('param.query_start_date')) : null;
  78. $end_unixtime = $if_end_date ? strtotime(input('param.query_end_date')) : null;
  79. if ($start_unixtime || $end_unixtime) {
  80. $condition[] = array('add_time', 'between', array($start_unixtime, $end_unixtime));
  81. }
  82. $skip_off = input('param.buyer_name');
  83. if ($skip_off == 1) {
  84. $condition[] = array('order_state', '<>', ORDER_STATE_CANCEL);
  85. }
  86. $order_list = $order_model->getOrderList($condition, (($pagesize < 1) ? 10 : $pagesize), '*', 'order_id desc', '', array('order_goods', 'order_common', 'ppintuanorder', 'member'));
  87. $mobile_page = $order_model->page_info;
  88. //页面中显示那些操作
  89. foreach ($order_list as $key => $order_info) {
  90. //显示取消订单
  91. $order_info['if_cancel'] = $order_model->getOrderOperateState('store_cancel', $order_info);
  92. //显示调整运费
  93. $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
  94. //显示修改价格
  95. $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
  96. //显示发货
  97. $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
  98. //显示锁定中
  99. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  100. //显示物流跟踪
  101. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  102. foreach ($order_info['extend_order_goods'] as $value) {
  103. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  104. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  105. if ($value['goods_type'] == 5) {
  106. $order_info['zengpin_list'][] = $value;
  107. } else {
  108. $order_info['goods_list'][] = $value;
  109. }
  110. }
  111. if (empty($order_info['zengpin_list'])) {
  112. $order_info['goods_count'] = count($order_info['goods_list']);
  113. } else {
  114. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  115. }
  116. $order_list[$key] = $order_info;
  117. }
  118. $order_list = array_values($order_list);
  119. $result = array_merge(array('order_list' => $order_list), mobile_page($mobile_page));
  120. ds_json_encode(10000, '', $result);
  121. }
  122. /**
  123. * @api {POST} api/Sellerorder/search_deliver 物流跟踪
  124. * @apiVersion 1.0.0
  125. * @apiGroup Sellerorder
  126. *
  127. * @apiHeader {String} X-DS-KEY 卖家授权token
  128. *
  129. * @apiParam {String} order_id 订单id
  130. *
  131. * @apiSuccess {String} code 返回码,10000为成功
  132. * @apiSuccess {String} message 返回消息
  133. * @apiSuccess {Object} result 返回数据
  134. * @apiSuccess {String} result.express_name 物流公司名称
  135. * @apiSuccess {String} result.shipping_code 物流单号
  136. * @apiSuccess {Object[]} result.deliver_info 物流数据
  137. * @apiSuccess {String} result.deliver_info.context 内容
  138. * @apiSuccess {String} result.deliver_info.time 时间
  139. */
  140. public function search_deliver()
  141. {
  142. $order_id = intval(input('post.order_id'));
  143. if ($order_id <= 0) {
  144. ds_json_encode(10001, lang('store_order_none_existr'));
  145. }
  146. $condition = array();
  147. $order_model = model('order');
  148. $condition[] = array('order_id', '=', $order_id);
  149. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  150. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  151. if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
  152. ds_json_encode(10001, lang('store_order_none_existr'));
  153. }
  154. $express = rkcache('express', true);
  155. if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
  156. $express_code = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
  157. $express_name = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
  158. $deliver_info = $this->_get_express($express_code, $order_info['shipping_code'], $order_info['extend_order_common']['reciver_info']['phone']);
  159. } else {
  160. $express_name = '';
  161. $deliver_info = array();
  162. }
  163. ds_json_encode(10000, '', array('express_name' => $express_name, 'shipping_code' => $order_info['shipping_code'], 'deliver_info' => $deliver_info));
  164. }
  165. /**
  166. * 从第三方取快递信息
  167. *
  168. */
  169. public function _get_express($express_code, $shipping_code, $phone)
  170. {
  171. $result = model('express')->queryExpress($express_code, $shipping_code, $phone);
  172. if ($result['Success'] != true) {
  173. ds_json_encode(10001, lang('deliver_search_fail'));
  174. }
  175. $content['Traces'] = array_reverse($result['Traces']);
  176. $output = array();
  177. if (is_array($content['Traces'])) {
  178. foreach ($content['Traces'] as $k => $v) {
  179. if ($v['AcceptTime'] == '')
  180. continue;
  181. //$output[] = $v['time'] . '&nbsp;&nbsp;' . $v['context'];
  182. $output[$k]['AcceptTime'] = $v['AcceptTime'];
  183. $output[$k]['AcceptStation'] = $v['AcceptStation'];
  184. }
  185. }
  186. if (empty($output))
  187. ds_json_encode(10001, lang('deliver_not_exist'));
  188. return $output;
  189. }
  190. /**
  191. * 取得当前的物流最新信息
  192. */
  193. public function get_current_deliver()
  194. {
  195. $order_id = intval(input('post.order_id'));
  196. if ($order_id <= 0) {
  197. ds_json_encode(10001, lang('store_order_none_existr'));
  198. }
  199. $condition = array();
  200. $order_model = model('order');
  201. $condition[] = array('order_id', '=', $order_id);
  202. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  203. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  204. if (empty($order_info) || !in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS))) {
  205. ds_json_encode(10001, lang('store_order_none_existr'));
  206. }
  207. $express = rkcache('express', true);
  208. if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
  209. $express_code = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
  210. $express_name = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
  211. $deliver_info = $this->_get_express($express_code, $order_info['shipping_code'], $order_info['extend_order_common']['reciver_info']['phone']);
  212. } else {
  213. $express_code = '';
  214. $express_name = '';
  215. $deliver_info = array('0' => '');
  216. }
  217. $data = array();
  218. $data['deliver_info']['context'] = $express_name;
  219. $data['deliver_info']['time'] = $deliver_info['0'];
  220. ds_json_encode(10000, '', $data);
  221. }
  222. /**
  223. * @api {POST} api/Sellerorder/order_info 订单详情
  224. * @apiVersion 1.0.0
  225. * @apiGroup Sellerorder
  226. *
  227. * @apiHeader {String} X-DS-KEY 卖家授权token
  228. *
  229. * @apiParam {String} order_id 订单id
  230. *
  231. * @apiSuccess {String} code 返回码,10000为成功
  232. * @apiSuccess {String} message 返回消息
  233. * @apiSuccess {Object} result 返回数据
  234. * @apiSuccess {Object} result.order_info 订单信息
  235. * @apiSuccess {Int} result.order_info.if_cancel 是否可取消 true是false否
  236. * @apiSuccess {Int} result.order_info.if_modify_price 是否可修改运费 true是false否
  237. * @apiSuccess {Int} result.order_info.if_spay_price 是否可修改商品价格 true是false否
  238. * @apiSuccess {Int} result.order_info.if_send 是否可发货 true是false否
  239. * @apiSuccess {Int} result.order_info.if_lock 是否被锁定 true是false否
  240. * @apiSuccess {Int} result.order_info.if_deliver 是否显示物流跟踪 true是false否
  241. * @apiSuccess {Object} result.order_info.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  242. * @apiSuccess {Object} result.order_info.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  243. * @apiSuccess {Object} result.order_info.extend_order_goods.image_240_url 商品图片完整路径
  244. * @apiSuccess {Object} result.order_info.extend_order_goods.goods_type_cn 商品类型名称
  245. * @apiSuccess {Object} result.order_info.extend_order_goods.goods_url 商品PC链接
  246. * @apiSuccess {Object} result.order_info.extend_member 用户信息 (返回字段参考member表)
  247. * @apiSuccess {String} result.order_info.invoice 发票信息
  248. * @apiSuccess {String} result.order_info.reciver_phone 收货人手机号
  249. * @apiSuccess {String} result.order_info.reciver_name 收货人姓名
  250. * @apiSuccess {String} result.order_info.reciver_addr 收货地址
  251. * @apiSuccess {String} result.order_info.order_cancel_day 自动取消订单日期
  252. * @apiSuccess {Object} result.order_info.express_info 物流信息
  253. * @apiSuccess {String} result.order_info.express_info.express_code 物流公司代码
  254. * @apiSuccess {String} result.order_info.express_info.express_name 物流公司名称
  255. * @apiSuccess {String} result.order_info.express_info.express_url 物流公司官网
  256. * @apiSuccess {object} result.order_info.zengpin_list 赠品列表 (返回字段参考ordergoods表)
  257. * @apiSuccess {object} result.order_info.goods_list 订单商品列表 (返回字段参考ordergoods表)
  258. * @apiSuccess {object} result.order_info.goods_count 商品数量
  259. * @apiSuccess {object[]} result.order_info.extend_log.order_log_list 订单操作日志列表 (返回字段参考orderlog表)
  260. * @apiSuccess {object} result.order_info.daddress_info 发货信息 (返回字段参考daddress表)
  261. * @apiSuccess {object} result.order_info.real_pay_amount 实际支付金额
  262. */
  263. public function order_info()
  264. {
  265. $order_id = intval(input('param.order_id'));
  266. if (!$order_id) {
  267. ds_json_encode(10001, lang('param_error'));
  268. }
  269. $order_model = model('order');
  270. $condition = array();
  271. $condition[] = array('order_id', '=', $order_id);
  272. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  273. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods', 'member'));
  274. if (empty($order_info)) {
  275. ds_json_encode(10001, lang('store_order_none_existr'));
  276. }
  277. $refundreturn_model = model('refundreturn');
  278. $order_list = array();
  279. $order_list[$order_id] = $order_info;
  280. //订单商品的退款退货显示
  281. $order_list = $refundreturn_model->getGoodsRefundList($order_list, 1);
  282. $order_info = $order_list[$order_id];
  283. $refund_all = isset($order_info['refund_list'][0]) ? $order_info['refund_list'][0] : '';
  284. //订单全部退款商家审核状态:1为待审核,2为同意,3为不同意
  285. if (!empty($refund_all) && $refund_all['seller_state'] < 3) {
  286. $order_info['extend_refund']['refund_all'] = $refund_all;
  287. }
  288. if ($order_info['payment_time']) {
  289. $order_info['payment_time'] = date('Y-m-d H:i:s', $order_info['payment_time']);
  290. } else {
  291. $order_info['payment_time'] = '';
  292. }
  293. if ($order_info['finnshed_time']) {
  294. $order_info['finnshed_time'] = date('Y-m-d H:i:s', $order_info['finnshed_time']);
  295. } else {
  296. $order_info['finnshed_time'] = '';
  297. }
  298. if ($order_info['add_time']) {
  299. $order_info['add_time'] = date('Y-m-d H:i:s', $order_info['add_time']);
  300. } else {
  301. $order_info['add_time'] = '';
  302. }
  303. if ($order_info['extend_order_common']['order_message']) {
  304. $order_info['order_message'] = $order_info['extend_order_common']['order_message'];
  305. }
  306. if (!empty($order_info['extend_order_common']['invoice_info'])) {
  307. $order_info['invoice'] = $order_info['extend_order_common']['invoice_info'];
  308. }
  309. $order_info['reciver_phone'] = $order_info['extend_order_common']['reciver_info']['phone'];
  310. $order_info['reciver_name'] = $order_info['extend_order_common']['reciver_name'];
  311. $order_info['reciver_addr'] = $order_info['extend_order_common']['reciver_info']['address'];
  312. //显示锁定中
  313. $order_info['if_lock'] = $order_model->getOrderOperateState('lock', $order_info);
  314. //显示调整运费
  315. $order_info['if_modify_price'] = $order_model->getOrderOperateState('modify_price', $order_info);
  316. //显示调整价格
  317. $order_info['if_spay_price'] = $order_model->getOrderOperateState('spay_price', $order_info);
  318. //显示取消订单
  319. $order_info['if_cancel'] = $order_model->getOrderOperateState('buyer_cancel', $order_info);
  320. //显示发货
  321. $order_info['if_send'] = $order_model->getOrderOperateState('send', $order_info);
  322. //显示物流跟踪
  323. $order_info['if_deliver'] = $order_model->getOrderOperateState('deliver', $order_info);
  324. //显示系统自动取消订单日期
  325. if ($order_info['order_state'] == ORDER_STATE_NEW) {
  326. $order_info['order_cancel_day'] = date('Y-m-d H:i:s', strtotime($order_info['add_time']) + config('ds_config.order_auto_cancel_day') * 24 * 3600);
  327. }
  328. //显示快递信息
  329. if ($order_info['shipping_code'] != '') {
  330. $express = rkcache('express', true);
  331. if (isset($express[$order_info['extend_order_common']['shipping_express_id']])) {
  332. $order_info['express_info']['express_code'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_code'];
  333. $order_info['express_info']['express_name'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_name'];
  334. $order_info['express_info']['express_url'] = $express[$order_info['extend_order_common']['shipping_express_id']]['express_url'];
  335. } else {
  336. $order_info['express_info']['express_code'] = '';
  337. $order_info['express_info']['express_name'] = '';
  338. $order_info['express_info']['express_url'] = '';
  339. }
  340. }
  341. //显示系统自动收获时间
  342. if ($order_info['order_state'] == ORDER_STATE_SEND) {
  343. $order_info['order_confirm_day'] = $order_info['delay_time'] + config('ds_config.order_auto_receive_day') * 24 * 3600;
  344. }
  345. //取得订单操作日志
  346. $order_log_list = $order_model->getOrderlogList(array('order_id' => $order_info['order_id']), 'log_id asc');
  347. $order_info['extend_log']['order_log_list'] = $order_log_list;
  348. //如果订单已取消,取得取消原因、时间,操作人
  349. if ($order_info['order_state'] == ORDER_STATE_CANCEL) {
  350. $last_log = end($order_log_list);
  351. if ($last_log['log_orderstate'] == ORDER_STATE_CANCEL) {
  352. $order_info['close_info'] = $last_log;
  353. }
  354. }
  355. $order_info['chain_order_type'] = 0;
  356. //如果是待自提则获取提货码
  357. $chain_order_model = model('chain_order');
  358. $chain_order_info = $chain_order_model->getChainOrderInfo(array(array('order_id', '=', $order_info['order_id'])));
  359. if ($chain_order_info) {
  360. $order_info['chain_order_type'] = $chain_order_info['chain_order_type'];
  361. }
  362. foreach ($order_info['extend_order_goods'] as $value) {
  363. $value['image_240_url'] = goods_cthumb($value['goods_image'], 240, $value['store_id']);
  364. $value['goods_type_cn'] = get_order_goodstype($value['goods_type']);
  365. $order_info['zengpin_list'] = array();
  366. if ($value['goods_type'] == 5) {
  367. $order_info['zengpin_list'][] = $value;
  368. } else {
  369. $order_info['goods_list'][] = $value;
  370. }
  371. }
  372. if (empty($order_info['zengpin_list'])) {
  373. $order_info['goods_count'] = count($order_info['goods_list']);
  374. } else {
  375. $order_info['goods_count'] = count($order_info['goods_list']) + 1;
  376. }
  377. //优惠信息
  378. $order_info['promotion'] = stripslashes(strip_tags($order_info['extend_order_common']['promotion_info']));
  379. $order_info['voucher_code'] = $order_info['extend_order_common']['voucher_code'];
  380. $order_info['voucher_price'] = $order_info['extend_order_common']['voucher_price'];
  381. //发货信息
  382. if (!empty($order_info['extend_order_common']['daddress_id'])) {
  383. $daddress_info = model('daddress')->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  384. $order_info['daddress_info'] = $daddress_info;
  385. }
  386. $order_info['real_pay_amount'] = $order_info['order_amount'] + $order_info['shipping_fee'];
  387. ds_json_encode(10000, '', array('order_info' => $order_info));
  388. }
  389. /**
  390. * @api {POST} api/Sellerorder/order_cancel 取消订单
  391. * @apiVersion 1.0.0
  392. * @apiGroup Sellerorder
  393. *
  394. * @apiHeader {String} X-DS-KEY 卖家授权token
  395. *
  396. * @apiParam {String} order_id 订单id
  397. * @apiParam {String} reason 理由
  398. *
  399. * @apiSuccess {String} code 返回码,10000为成功
  400. * @apiSuccess {String} message 返回消息
  401. * @apiSuccess {Object} result 返回数据
  402. */
  403. public function order_cancel()
  404. {
  405. $order_id = intval(input('post.order_id'));
  406. $reason = input('post.reason');
  407. $order_model = model('order');
  408. $condition = array();
  409. $condition[] = array('order_id', '=', $order_id);
  410. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  411. $order_info = $order_model->getOrderInfo($condition);
  412. $if_allow = $order_model->getOrderOperateState('store_cancel', $order_info);
  413. if (!$if_allow) {
  414. ds_json_encode(10001, lang('no_right'));
  415. }
  416. try {
  417. Db::startTrans();
  418. model('order', 'logic')->changeOrderStateCancel($order_info, 'seller', $this->seller_info['seller_name'], $reason);
  419. } catch (\Exception $e) {
  420. Db::rollback();
  421. ds_json_encode(10001, $e->getMessage());
  422. }
  423. Db::commit();
  424. ds_json_encode(10000, '', 1);
  425. }
  426. /**
  427. * @api {POST} api/Sellerorder/order_ship_price 修改运费
  428. * @apiVersion 1.0.0
  429. * @apiGroup Sellerorder
  430. *
  431. * @apiHeader {String} X-DS-KEY 卖家授权token
  432. *
  433. * @apiParam {String} order_id 订单id
  434. * @apiParam {String} shipping_fee 运费
  435. *
  436. * @apiSuccess {String} code 返回码,10000为成功
  437. * @apiSuccess {String} message 返回消息
  438. * @apiSuccess {Object} result 返回数据
  439. */
  440. public function order_ship_price()
  441. {
  442. $order_id = intval(input('post.order_id'));
  443. $shipping_fee = ds_price_format(input('post.shipping_fee'));
  444. $order_model = model('order');
  445. $condition = array();
  446. $condition[] = array('order_id', '=', $order_id);
  447. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  448. $order_info = $order_model->getOrderInfo($condition);
  449. $if_allow = $order_model->getOrderOperateState('modify_price', $order_info);
  450. if (!$if_allow) {
  451. ds_json_encode(10001, lang('no_right'));
  452. }
  453. $result = model('order', 'logic')->changeOrderShipPrice($order_info, 'seller', $this->seller_info['seller_name'], $shipping_fee);
  454. if (!$result['code']) {
  455. ds_json_encode(10001, $result['msg']);
  456. }
  457. ds_json_encode(10000, '', 1);
  458. }
  459. /**
  460. * @api {POST} api/Sellerorder/order_spay_price 修改商品价格
  461. * @apiVersion 1.0.0
  462. * @apiGroup Sellerorder
  463. *
  464. * @apiHeader {String} X-DS-KEY 卖家授权token
  465. *
  466. * @apiParam {String} order_id 订单id
  467. * @apiParam {String} order_fee 商品价格
  468. *
  469. * @apiSuccess {String} code 返回码,10000为成功
  470. * @apiSuccess {String} message 返回消息
  471. * @apiSuccess {Object} result 返回数据
  472. */
  473. public function order_spay_price()
  474. {
  475. $order_model = model('order');
  476. $logic_order = model('order', 'logic');
  477. $order_id = intval(input('post.order_id'));
  478. $condition = array();
  479. $condition[] = array('order_id', '=', $order_id);
  480. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  481. $goods_amount = input('post.order_fee');
  482. $order_info = $order_model->getOrderInfo($condition);
  483. $if_allow = $order_model->getOrderOperateState('spay_price', $order_info);
  484. if (!$if_allow) {
  485. ds_json_encode(10001, lang('no_right'));
  486. }
  487. $info = $logic_order->changeOrderSpayPrice($order_info, 'seller', $this->seller_info['seller_name'], $goods_amount);
  488. if ($info['code'] == TRUE) {
  489. ds_json_encode(10000, lang('ds_common_op_succ'));
  490. } else {
  491. ds_json_encode(10001, lang('ds_common_op_fail'));
  492. }
  493. }
  494. /**
  495. * @api {POST} api/Sellerorder/order_deliver_send 发货
  496. * @apiVersion 1.0.0
  497. * @apiGroup Sellerorder
  498. *
  499. * @apiHeader {String} X-DS-KEY 卖家授权token
  500. *
  501. * @apiParam {Int} order_id 订单id
  502. * @apiParam {Int} daddress_id 发货地址id
  503. * @apiParam {Int} shipping_express_id 物流公司id
  504. * @apiParam {String} shipping_code 物流单号
  505. *
  506. * @apiSuccess {String} code 返回码,10000为成功
  507. * @apiSuccess {String} message 返回消息
  508. * @apiSuccess {Object} result 返回数据
  509. */
  510. public function order_deliver_send()
  511. {
  512. $order_id = intval(input('post.order_id'));
  513. if ($order_id <= 0) {
  514. ds_json_encode(10001, lang('param_error'));
  515. }
  516. $order_model = model('order');
  517. $condition = array();
  518. $condition[] = array('order_id', '=', $order_id);
  519. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  520. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  521. $if_allow_send = intval($order_info['lock_state']) || !in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND));
  522. if ($if_allow_send) {
  523. ds_json_encode(10001, lang('no_right'));
  524. }
  525. //由于PC 端可以修改收货信息,手机端不可,则使用默认客户收货信息。
  526. $extend = array(
  527. 'reciver_name' => $order_info['extend_order_common']['reciver_name'],
  528. 'reciver_info' => serialize($order_info['extend_order_common']['reciver_info']),
  529. 'deliver_explain' => $order_info['extend_order_common']['deliver_explain'],
  530. 'daddress_id' => !empty(input('post.daddress_id')) ? input('post.daddress_id') : $order_info['extend_order_common']['daddress_id'],
  531. 'shipping_express_id' => !empty(input('post.shipping_express_id')) ? input('post.shipping_express_id') : $order_info['extend_order_common']['shipping_express_id'],
  532. 'shipping_code' => !empty(input('post.shipping_code')) ? input('post.shipping_code') : $order_info['shipping_code'],
  533. );
  534. $result = model('order', 'logic')->changeOrderSend($order_info, 'seller', $this->seller_info['seller_name'], $extend);
  535. if (!$result['code']) {
  536. ds_json_encode(10001, $result['msg']);
  537. }
  538. ds_json_encode(10000, lang('ds_common_op_succ'), 1);
  539. }
  540. }