Sellerorder.php 29 KB

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