Sellerdeliverset.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 卖家发货设置控制器
  10. */
  11. class Sellerdeliverset extends MobileSeller
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize(); // TODO: Change the autogenerated stub
  16. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerdeliver.lang.php');
  17. $this->model_address = model('daddress');
  18. }
  19. /**
  20. * @api {POST} api/Sellerdeliverset/address_list 地址列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Sellerdeliverset
  23. *
  24. * @apiHeader {String} X-DS-KEY 卖家授权token
  25. *
  26. * @apiParam {Int} page 页码
  27. * @apiParam {Int} pagesize 每页显示数量
  28. *
  29. * @apiSuccess {String} code 返回码,10000为成功
  30. * @apiSuccess {String} message 返回消息
  31. * @apiSuccess {Object} result 返回数据
  32. * @apiSuccess {Object[]} result.address_list 发货地址列表 (返回字段参考daddress表)
  33. */
  34. public function address_list()
  35. {
  36. $daddress_model = model('daddress');
  37. $condition = array();
  38. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  39. $address_list = $daddress_model->getAddressList($condition, '*', '', 20);
  40. ds_json_encode(10000, '', array('address_list' => $address_list));
  41. }
  42. /**
  43. * @api {POST} api/Sellerdeliverset/address_info 地址详细信息
  44. * @apiVersion 1.0.0
  45. * @apiGroup Sellerdeliverset
  46. *
  47. * @apiHeader {String} X-DS-KEY 卖家授权token
  48. *
  49. * @apiParam {Int} address_id 地址ID
  50. *
  51. * @apiSuccess {String} code 返回码,10000为成功
  52. * @apiSuccess {String} message 返回消息
  53. * @apiSuccess {Object} result 返回数据
  54. * @apiSuccess {Object} result.address_info 发货地址信息 (返回字段参考daddress表)
  55. */
  56. public function address_info()
  57. {
  58. $address_id = intval(input('param.address_id'));
  59. if ($address_id <= 0) {
  60. ds_json_encode(10001, lang('param_error'));
  61. }
  62. $condition = array();
  63. $condition[] = array('daddress_id', '=', $address_id);
  64. $address_info = $this->model_address->getAddressInfo($condition);
  65. if (!empty($address_id) && $address_info['store_id'] == $this->store_info['store_id']) {
  66. ds_json_encode(10000, '', array('address_info' => $address_info));
  67. } else {
  68. ds_json_encode(10001, lang('daddress_not_exist'));
  69. }
  70. }
  71. /**
  72. * @api {POST} api/Sellerdeliverset/address_del 删除地址
  73. * @apiVersion 1.0.0
  74. * @apiGroup Sellerdeliverset
  75. *
  76. * @apiHeader {String} X-DS-KEY 卖家授权token
  77. *
  78. * @apiParam {Int} address_id 地址ID
  79. *
  80. * @apiSuccess {String} code 返回码,10000为成功
  81. * @apiSuccess {String} message 返回消息
  82. * @apiSuccess {Object} result 返回数据
  83. */
  84. public function address_del()
  85. {
  86. $address_id = intval(input('param.address_id'));
  87. if ($address_id <= 0) {
  88. ds_json_encode(10001, lang('param_error'));
  89. }
  90. $condition = array();
  91. $condition[] = array('daddress_id', '=', $address_id);
  92. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  93. $delete = model('daddress')->delDaddress($condition);
  94. if ($delete) {
  95. ds_json_encode(10000, lang('ds_common_op_succ'));
  96. } else {
  97. ds_json_encode(10001, lang('ds_common_op_fail'));
  98. }
  99. }
  100. /**
  101. * @api {POST} api/Sellerdeliverset/address_add 新增/编辑地址
  102. * @apiVersion 1.0.0
  103. * @apiGroup Sellerdeliverset
  104. *
  105. * @apiHeader {String} X-DS-KEY 卖家授权token
  106. *
  107. * @apiParam {Int} address_id 地址ID 0新增
  108. * @apiParam {String} seller_name 发货人姓名
  109. * @apiParam {Int} area_id 地区ID
  110. * @apiParam {Int} city_id 城市ID
  111. * @apiParam {String} area_info 地区
  112. * @apiParam {String} address 地址
  113. * @apiParam {String} telphone 电话
  114. * @apiParam {Int} is_default 默认地址 1是 0否
  115. *
  116. * @apiSuccess {String} code 返回码,10000为成功
  117. * @apiSuccess {String} message 返回消息
  118. * @apiSuccess {Object} result 返回数据
  119. */
  120. public function address_add()
  121. {
  122. $daddress_model = model('daddress');
  123. //保存 新增/编辑 表单
  124. $data = array(
  125. 'store_id' => $this->store_info['store_id'],
  126. 'seller_name' => input('post.seller_name'),
  127. 'area_id' => input('post.area_id'),
  128. 'city_id' => input('post.city_id'),
  129. 'area_info' => input('post.area_info'),
  130. 'daddress_detail' => input('post.address'),
  131. 'daddress_telphone' => input('post.telphone'),
  132. 'daddress_company' => '',
  133. 'daddress_isdefault' => intval(input('post.is_default'))
  134. );
  135. $selleraddress_validate = ds_validate('selleraddress');
  136. if (!$selleraddress_validate->scene('address_add')->check($data)) {
  137. ds_json_encode(10001, $selleraddress_validate->getError());
  138. }
  139. $address_id = intval(input('post.address_id'));
  140. if ($address_id > 0) {
  141. $condition = array();
  142. $condition[] = array('daddress_id', '=', $address_id);
  143. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  144. $update = $daddress_model->editDaddress($data, $condition);
  145. if (!$update) {
  146. ds_json_encode(10001, lang('store_daddress_modify_fail'));
  147. }
  148. $is_default = intval(input('post.is_default'));
  149. if ($is_default == 1) {
  150. $condition = array();
  151. $condition[] = array('daddress_id', '<>', $address_id);
  152. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  153. $update = $daddress_model->editDaddress(array('daddress_isdefault' => 0), $condition);
  154. }
  155. } else {
  156. $insert = $daddress_model->addDaddress($data);
  157. if (!$insert) {
  158. ds_json_encode(10001, lang('store_daddress_add_fail'));
  159. }
  160. $is_default = intval(input('post.is_default'));
  161. if ($is_default == 1) {
  162. $condition = array();
  163. $condition[] = array('daddress_id', '<>', $insert);
  164. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  165. $update = $daddress_model->editDaddress(array('daddress_isdefault' => 0), $condition);
  166. }
  167. }
  168. ds_json_encode(10000, lang('ds_common_op_succ'));
  169. }
  170. /**
  171. * @api {POST} api/Sellerdeliverset/express_default 获取默认发货信息
  172. * @apiVersion 1.0.0
  173. * @apiGroup Sellerdeliverset
  174. *
  175. * @apiHeader {String} X-DS-KEY 卖家授权token
  176. *
  177. * @apiParam {Int} order_id 订单ID
  178. *
  179. * @apiSuccess {String} code 返回码,10000为成功
  180. * @apiSuccess {String} message 返回消息
  181. * @apiSuccess {Object} result 返回数据
  182. * @apiSuccess {Object} result.daddress_info 默认发货地址 (返回字段参考daddress表)
  183. * @apiSuccess {Object} result.orderinfo 订单信息 (返回字段参考order表)
  184. * @apiSuccess {Object} result.orderinfo.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  185. * @apiSuccess {Object} result.orderinfo.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  186. */
  187. public function express_default()
  188. {
  189. $order_id = intval(input('post.order_id'));
  190. if ($order_id <= 0) {
  191. ds_json_encode(10001, lang('param_error'));
  192. }
  193. $order_model = model('order');
  194. $condition = array();
  195. $condition[] = array('order_id', '=', $order_id);
  196. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  197. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  198. $if_allow_send = intval($order_info['lock_state']) || !in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND));
  199. if ($if_allow_send) {
  200. ds_json_encode(10001, lang('param_error'));
  201. }
  202. //取发货地址
  203. $daddress_model = model('daddress');
  204. if ($order_info['extend_order_common']['daddress_id'] > 0) {
  205. $daddress_info = $daddress_model->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  206. } else {
  207. //取默认地址
  208. $daddress_info = $daddress_model->getAddressList(array('store_id' => $this->store_info['store_id']), '*', 'daddress_isdefault desc', 1);
  209. if (!$daddress_info) {
  210. ds_json_encode(12002, lang('default_daddress_not_exist'));
  211. }
  212. $daddress_info = $daddress_info[0];
  213. }
  214. ds_json_encode(10000, '', array('daddress_info' => $daddress_info, 'orderinfo' => $order_info));
  215. }
  216. /**
  217. * @api {POST} api/Sellerdeliverset/express_list 获取物流服务列表
  218. * @apiVersion 1.0.0
  219. * @apiGroup Sellerdeliverset
  220. *
  221. * @apiHeader {String} X-DS-KEY 卖家授权token
  222. *
  223. * @apiParam {Int} order_id 订单ID
  224. *
  225. * @apiSuccess {String} code 返回码,10000为成功
  226. * @apiSuccess {String} message 返回消息
  227. * @apiSuccess {Object} result 返回数据
  228. * @apiSuccess {Object} result.orderinfo 订单信息 (返回字段参考order表)
  229. * @apiSuccess {Object} result.orderinfo.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  230. * @apiSuccess {Object} result.orderinfo.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  231. * @apiSuccess {Object} result.orderinfo.extend_member 用户信息 (返回字段参考member表)
  232. * @apiSuccess {Object} result.express_array 物流公司列表,键为物流公司ID
  233. * @apiSuccess {String} result.express_array.express_code 物流公司代码
  234. * @apiSuccess {String} result.express_array.express_id 物流公司ID
  235. * @apiSuccess {String} result.express_array.express_letter 物流公司首字母
  236. * @apiSuccess {String} result.express_array.express_name 物流公司名称
  237. * @apiSuccess {String} result.express_array.express_order 排序 1:常用2:不常用
  238. * @apiSuccess {String} result.express_array.express_state 状态 0:不可用1:可用
  239. * @apiSuccess {String} result.express_array.express_url 官网地址
  240. */
  241. public function express_list()
  242. {
  243. $express_list = rkcache('express', true);
  244. //快递公司
  245. $express_array = array();
  246. $hot_express = array();
  247. $all_express = array();
  248. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', $this->store_info['store_id'], 'express');
  249. $my_express_list = explode(',', $my_express_list);
  250. foreach ($express_list as $key => $val) {
  251. if (in_array($key, $my_express_list)) {
  252. $express_array[] = $val;
  253. }
  254. if ($val['express_order'] == 1) {
  255. $hot_express[] = $val;
  256. }
  257. if (!$val['express_letter']) {
  258. $val['express_letter'] = '#';
  259. }
  260. if (!isset($all_express[$val['express_letter']])) {
  261. $all_express[$val['express_letter']] = array('letter' => $val['express_letter'], 'list' => array());
  262. }
  263. $all_express[$val['express_letter']]['list'][] = $val;
  264. }
  265. ksort($all_express);
  266. ds_json_encode(10000, '', array('my_express' => $express_array, 'hot_express' => $hot_express, 'all_express' => $all_express));
  267. }
  268. }