Sellerdeliverset.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Lang;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 卖家发货设置控制器
  15. */
  16. class Sellerdeliverset 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') . '/sellerdeliver.lang.php');
  20. $this->model_address = model('daddress');
  21. }
  22. /**
  23. * @api {POST} api/Sellerdeliverset/address_list 地址列表
  24. * @apiVersion 1.0.0
  25. * @apiGroup Sellerdeliverset
  26. *
  27. * @apiHeader {String} X-DS-KEY 卖家授权token
  28. *
  29. * @apiParam {Int} page 页码
  30. * @apiParam {Int} pagesize 每页显示数量
  31. *
  32. * @apiSuccess {String} code 返回码,10000为成功
  33. * @apiSuccess {String} message 返回消息
  34. * @apiSuccess {Object} result 返回数据
  35. * @apiSuccess {Object[]} result.address_list 发货地址列表 (返回字段参考daddress表)
  36. */
  37. public function address_list() {
  38. $daddress_model = model('daddress');
  39. $condition = array();
  40. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  41. $address_list = $daddress_model->getAddressList($condition, '*', '', 20);
  42. ds_json_encode(10000, '', array('address_list' => $address_list));
  43. }
  44. /**
  45. * @api {POST} api/Sellerdeliverset/address_info 地址详细信息
  46. * @apiVersion 1.0.0
  47. * @apiGroup Sellerdeliverset
  48. *
  49. * @apiHeader {String} X-DS-KEY 卖家授权token
  50. *
  51. * @apiParam {Int} address_id 地址ID
  52. *
  53. * @apiSuccess {String} code 返回码,10000为成功
  54. * @apiSuccess {String} message 返回消息
  55. * @apiSuccess {Object} result 返回数据
  56. * @apiSuccess {Object} result.address_info 发货地址信息 (返回字段参考daddress表)
  57. */
  58. public function address_info() {
  59. $address_id = intval(input('param.address_id'));
  60. if ($address_id <= 0) {
  61. ds_json_encode(10001, lang('param_error'));
  62. }
  63. $condition = array();
  64. $condition[] = array('daddress_id', '=', $address_id);
  65. $address_info = $this->model_address->getAddressInfo($condition);
  66. if (!empty($address_id) && $address_info['store_id'] == $this->store_info['store_id']) {
  67. ds_json_encode(10000, '', array('address_info' => $address_info));
  68. } else {
  69. ds_json_encode(10001, lang('daddress_not_exist'));
  70. }
  71. }
  72. /**
  73. * @api {POST} api/Sellerdeliverset/address_del 删除地址
  74. * @apiVersion 1.0.0
  75. * @apiGroup Sellerdeliverset
  76. *
  77. * @apiHeader {String} X-DS-KEY 卖家授权token
  78. *
  79. * @apiParam {Int} address_id 地址ID
  80. *
  81. * @apiSuccess {String} code 返回码,10000为成功
  82. * @apiSuccess {String} message 返回消息
  83. * @apiSuccess {Object} result 返回数据
  84. */
  85. public function address_del() {
  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. $daddress_model = model('daddress');
  122. //保存 新增/编辑 表单
  123. $data = array(
  124. 'store_id' => $this->store_info['store_id'],
  125. 'seller_name' => input('post.seller_name'),
  126. 'area_id' => input('post.area_id'),
  127. 'city_id' => input('post.city_id'),
  128. 'area_info' => input('post.area_info'),
  129. 'daddress_detail' => input('post.address'),
  130. 'daddress_telphone' => input('post.telphone'),
  131. 'daddress_company' => '',
  132. 'daddress_isdefault' => intval(input('post.is_default'))
  133. );
  134. $selleraddress_validate = ds_validate('selleraddress');
  135. if (!$selleraddress_validate->scene('address_add')->check($data)) {
  136. ds_json_encode(10001, $selleraddress_validate->getError());
  137. }
  138. $address_id = intval(input('post.address_id'));
  139. if ($address_id > 0) {
  140. $condition = array();
  141. $condition[] = array('daddress_id', '=', $address_id);
  142. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  143. $update = $daddress_model->editDaddress($data, $condition);
  144. if (!$update) {
  145. ds_json_encode(10001, lang('store_daddress_modify_fail'));
  146. }
  147. $is_default = intval(input('post.is_default'));
  148. if ($is_default == 1) {
  149. $condition = array();
  150. $condition[] = array('daddress_id', '<>', $address_id);
  151. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  152. $update = $daddress_model->editDaddress(array('daddress_isdefault' => 0), $condition);
  153. }
  154. } else {
  155. $insert = $daddress_model->addDaddress($data);
  156. if (!$insert) {
  157. ds_json_encode(10001, lang('store_daddress_add_fail'));
  158. }
  159. $is_default = intval(input('post.is_default'));
  160. if ($is_default == 1) {
  161. $condition = array();
  162. $condition[] = array('daddress_id', '<>', $insert);
  163. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  164. $update = $daddress_model->editDaddress(array('daddress_isdefault' => 0), $condition);
  165. }
  166. }
  167. ds_json_encode(10000, lang('ds_common_op_succ'));
  168. }
  169. /**
  170. * @api {POST} api/Sellerdeliverset/express_default 获取默认发货信息
  171. * @apiVersion 1.0.0
  172. * @apiGroup Sellerdeliverset
  173. *
  174. * @apiHeader {String} X-DS-KEY 卖家授权token
  175. *
  176. * @apiParam {Int} order_id 订单ID
  177. *
  178. * @apiSuccess {String} code 返回码,10000为成功
  179. * @apiSuccess {String} message 返回消息
  180. * @apiSuccess {Object} result 返回数据
  181. * @apiSuccess {Object} result.daddress_info 默认发货地址 (返回字段参考daddress表)
  182. * @apiSuccess {Object} result.orderinfo 订单信息 (返回字段参考order表)
  183. * @apiSuccess {Object} result.orderinfo.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  184. * @apiSuccess {Object} result.orderinfo.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  185. */
  186. public function express_default() {
  187. $order_id = intval(input('post.order_id'));
  188. if ($order_id <= 0) {
  189. ds_json_encode(10001, lang('param_error'));
  190. }
  191. $order_model = model('order');
  192. $condition = array();
  193. $condition[] = array('order_id', '=', $order_id);
  194. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  195. $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
  196. $if_allow_send = intval($order_info['lock_state']) || !in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND));
  197. if ($if_allow_send) {
  198. ds_json_encode(10001, lang('param_error'));
  199. }
  200. //取发货地址
  201. $daddress_model = model('daddress');
  202. if ($order_info['extend_order_common']['daddress_id'] > 0) {
  203. $daddress_info = $daddress_model->getAddressInfo(array('daddress_id' => $order_info['extend_order_common']['daddress_id']));
  204. } else {
  205. //取默认地址
  206. $daddress_info = $daddress_model->getAddressList(array('store_id' => $this->store_info['store_id']), '*', 'daddress_isdefault desc', 1);
  207. if (!$daddress_info) {
  208. ds_json_encode(12002, lang('default_daddress_not_exist'));
  209. }
  210. $daddress_info = $daddress_info[0];
  211. }
  212. ds_json_encode(10000, '', array('daddress_info' => $daddress_info, 'orderinfo' => $order_info));
  213. }
  214. /**
  215. * @api {POST} api/Sellerdeliverset/express_list 获取物流服务列表
  216. * @apiVersion 1.0.0
  217. * @apiGroup Sellerdeliverset
  218. *
  219. * @apiHeader {String} X-DS-KEY 卖家授权token
  220. *
  221. * @apiParam {Int} order_id 订单ID
  222. *
  223. * @apiSuccess {String} code 返回码,10000为成功
  224. * @apiSuccess {String} message 返回消息
  225. * @apiSuccess {Object} result 返回数据
  226. * @apiSuccess {Object} result.orderinfo 订单信息 (返回字段参考order表)
  227. * @apiSuccess {Object} result.orderinfo.extend_order_common 订单其他信息 (返回字段参考ordercommon表)
  228. * @apiSuccess {Object} result.orderinfo.extend_order_goods 订单商品信息 (返回字段参考ordergoods表)
  229. * @apiSuccess {Object} result.orderinfo.extend_member 用户信息 (返回字段参考member表)
  230. * @apiSuccess {Object} result.express_array 物流公司列表,键为物流公司ID
  231. * @apiSuccess {String} result.express_array.express_code 物流公司代码
  232. * @apiSuccess {String} result.express_array.express_id 物流公司ID
  233. * @apiSuccess {String} result.express_array.express_letter 物流公司首字母
  234. * @apiSuccess {String} result.express_array.express_name 物流公司名称
  235. * @apiSuccess {String} result.express_array.express_order 排序 1:常用2:不常用
  236. * @apiSuccess {String} result.express_array.express_state 状态 0:不可用1:可用
  237. * @apiSuccess {String} result.express_array.express_url 官网地址
  238. */
  239. public function express_list() {
  240. $express_list = rkcache('express', true);
  241. //快递公司
  242. $express_array = array();
  243. $hot_express=array();
  244. $all_express=array();
  245. $my_express_list = ds_getvalue_byname('storeextend', 'store_id', $this->store_info['store_id'], 'express');
  246. $my_express_list = explode(',', $my_express_list);
  247. foreach($express_list as $key => $val){
  248. if(in_array($key,$my_express_list)){
  249. $express_array[]=$val;
  250. }
  251. if($val['express_order']==1){
  252. $hot_express[]=$val;
  253. }
  254. if(!$val['express_letter']){
  255. $val['express_letter']='#';
  256. }
  257. if(!isset($all_express[$val['express_letter']])){
  258. $all_express[$val['express_letter']]=array('letter'=>$val['express_letter'],'list'=>array());
  259. }
  260. $all_express[$val['express_letter']]['list'][]=$val;
  261. }
  262. ksort($all_express);
  263. ds_json_encode(10000, '', array('my_express' => $express_array, 'hot_express' => $hot_express, 'all_express' => $all_express));
  264. }
  265. }
  266. ?>