Sellerdeliverset.php 12 KB

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