Sellerorder.php 29 KB

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