Sellerinviter.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\View;
  4. use think\facade\Db;
  5. use think\facade\Lang;
  6. /**
  7. * ============================================================================
  8. * DSMall多用户商城
  9. * ============================================================================
  10. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  11. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 卖家分销控制器
  17. */
  18. class Sellerinviter extends MobileSeller {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerinviter.lang.php');
  22. if (intval(config('ds_config.inviter_open')) !== 1) {
  23. ds_json_encode(10001, lang('promotion_unavailable'));
  24. }
  25. }
  26. /**
  27. * @api {POST} api/Sellerinviter/order_list 分销业绩
  28. * @apiVersion 1.0.0
  29. * @apiGroup Sellerinviter
  30. *
  31. * @apiHeader {String} X-DS-KEY 用户授权token
  32. *
  33. * @apiParam {String} orderinviter_order_sn 订单号
  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 分销订单列表 (返回字段参考orderinviter表)
  41. * @apiSuccess {Int} result.page_total 总页数
  42. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  43. */
  44. public function order_list() {
  45. $condition = array(array('orderinviter_store_id', '=', $this->store_info['store_id']));
  46. if (input('param.orderinviter_order_sn')) {
  47. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  48. }
  49. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  50. $order_list=$orderinviter_list->items();
  51. foreach($order_list as $key => $val){
  52. $order_list[$key]['orderinviter_valid_text']=lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  53. }
  54. $result = array_merge(array('order_list' => $order_list), mobile_page($orderinviter_list));
  55. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  56. }
  57. /**
  58. * @api {POST} api/Sellerinviter/goods_list 分销商品
  59. * @apiVersion 1.0.0
  60. * @apiGroup Sellerinviter
  61. *
  62. * @apiHeader {String} X-DS-KEY 用户授权token
  63. *
  64. * @apiParam {String} goods_name 商品名
  65. * @apiParam {String} page 页码
  66. * @apiParam {String} pagesize 每页显示数量
  67. *
  68. * @apiSuccess {String} code 返回码,10000为成功
  69. * @apiSuccess {String} message 返回消息
  70. * @apiSuccess {Object} result 返回数据
  71. * @apiSuccess {Object[]} result.goods_list 分销商品列表 (返回字段参考goodscommon表)
  72. * @apiSuccess {Object} result.storage_array 库存列表,键为商品公共ID
  73. * @apiSuccess {Int} result.storage_array.sum 库存
  74. * @apiSuccess {Int} result.storage_array.goods_id 商品ID
  75. */
  76. public function goods_list() {
  77. $goods_model = model('goods');
  78. if (check_platform_store()) {
  79. View::assign('isPlatformStore', true);
  80. }
  81. $condition = array();
  82. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  83. $condition[] = array('inviter_open', '=', 1);
  84. if ((input('param.goods_name'))) {
  85. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  86. }
  87. $goods_list = $goods_model->getGoodsCommonList($condition, '*', $this->pagesize);
  88. foreach($goods_list as $key => $val){
  89. $goods_list[$key]['goods_image'] = goods_cthumb($val['goods_image']);
  90. }
  91. $result = array('goods_list' => $goods_list);
  92. $result = array_merge($result, mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  93. ds_json_encode(10000, '', $result);
  94. }
  95. /**
  96. * @api {POST} api/Sellerinviter/goods_add 添加分销活动
  97. * @apiVersion 1.0.0
  98. * @apiGroup Sellerinviter
  99. *
  100. * @apiHeader {String} X-DS-KEY 用户授权token
  101. *
  102. * @apiParam {Int} inviter_goods_commonid 商品公共ID
  103. * @apiParam {Float} inviter_ratio_1 一级分销佣金比例
  104. * @apiParam {Float} inviter_ratio_2 二级分销佣金比例
  105. * @apiParam {Float} inviter_ratio_3 三级分销佣金比例
  106. *
  107. * @apiSuccess {String} code 返回码,10000为成功
  108. * @apiSuccess {String} message 返回消息
  109. * @apiSuccess {Object} result 返回数据
  110. */
  111. public function goods_add() {
  112. $goods_model = model('goods');
  113. //验证输入
  114. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  115. $inviter_ratio = floatval(input('post.inviter_ratio'));
  116. if (!($inviter_goods_commonid)) {
  117. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  118. }
  119. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND store_id=' . $this->store_info['store_id']);
  120. if (!$goods_info) {
  121. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  122. }
  123. if ($inviter_ratio <= 0) {
  124. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . '%');
  125. }
  126. if ($inviter_ratio > 100) {
  127. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . '%');
  128. }
  129. $result = $goods_model->editGoodsCommonById(array(
  130. 'inviter_open' => 1,
  131. 'inviter_ratio' => $inviter_ratio,
  132. ), array($inviter_goods_commonid));
  133. if ($result) {
  134. $this->recordSellerlog('添加分销商品,商品编号:' . $inviter_goods_commonid);
  135. ds_json_encode(10000, lang('goods_add_success'));
  136. } else {
  137. ds_json_encode(10001, lang('goods_add_fail'));
  138. }
  139. }
  140. /**
  141. * @api {POST} api/Sellerinviter/goods_info 获取分销商品信息
  142. * @apiVersion 1.0.0
  143. * @apiGroup Sellerinviter
  144. *
  145. * @apiHeader {String} X-DS-KEY 用户授权token
  146. *
  147. * @apiParam {Int} goods_commonid 商品公共ID
  148. *
  149. * @apiSuccess {String} code 返回码,10000为成功
  150. * @apiSuccess {String} message 返回消息
  151. * @apiSuccess {Object} result 返回数据
  152. * @apiSuccess {Object} result.info 商品信息 (返回字段参考goodscommon表)
  153. */
  154. public function goods_info() {
  155. $goods_model = model('goods');
  156. $goods_commonid = intval(input('param.goods_commonid'));
  157. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  158. if (!$goods_info) {
  159. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  160. }
  161. ds_json_encode(10000, '', array('info' => $goods_info));
  162. }
  163. /**
  164. * @api {POST} api/Sellerinviter/goods_edit 编辑分销活动
  165. * @apiVersion 1.0.0
  166. * @apiGroup Sellerinviter
  167. *
  168. * @apiHeader {String} X-DS-KEY 用户授权token
  169. *
  170. * @apiParam {Int} inviter_goods_commonid 商品公共ID
  171. * @apiParam {Float} inviter_ratio_1 一级分销佣金比例
  172. * @apiParam {Float} inviter_ratio_2 二级分销佣金比例
  173. * @apiParam {Float} inviter_ratio_3 三级分销佣金比例
  174. *
  175. * @apiSuccess {String} code 返回码,10000为成功
  176. * @apiSuccess {String} message 返回消息
  177. * @apiSuccess {Object} result 返回数据
  178. */
  179. public function goods_edit() {
  180. $goods_model = model('goods');
  181. //验证输入
  182. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  183. $inviter_ratio = floatval(input('post.inviter_ratio'));
  184. if (!($inviter_goods_commonid)) {
  185. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  186. }
  187. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  188. if (!$goods_info) {
  189. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  190. }
  191. if ($inviter_ratio <= 0) {
  192. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . '%');
  193. }
  194. if ($inviter_ratio > 100) {
  195. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . '%');
  196. }
  197. $result = $goods_model->editGoodsCommonById(array(
  198. 'inviter_ratio' => $inviter_ratio,
  199. ), array($inviter_goods_commonid));
  200. if ($result) {
  201. $this->recordSellerlog('编辑分销商品,商品编号:' . $inviter_goods_commonid);
  202. ds_json_encode(10000, lang('goods_edit_success'));
  203. } else {
  204. ds_json_encode(10001, lang('goods_edit_fail'));
  205. }
  206. }
  207. /**
  208. * @api {POST} api/Sellerinviter/goods_del 删除分销商品
  209. * @apiVersion 1.0.0
  210. * @apiGroup Sellerinviter
  211. *
  212. * @apiHeader {String} X-DS-KEY 用户授权token
  213. *
  214. * @apiParam {Int} goods_commonid 商品公共ID
  215. *
  216. * @apiSuccess {String} code 返回码,10000为成功
  217. * @apiSuccess {String} message 返回消息
  218. * @apiSuccess {Object} result 返回数据
  219. */
  220. public function goods_del() {
  221. $goods_model = model('goods');
  222. $goods_commonid = intval(input('param.goods_commonid'));
  223. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  224. if (!$goods_info) {
  225. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  226. }
  227. $result = $goods_model->editGoodsCommonById(array(
  228. 'inviter_open' => 0,
  229. ), array($goods_commonid));
  230. if ($result) {
  231. $this->recordSellerlog('删除分销商品,商品编号:' . $goods_commonid);
  232. ds_json_encode(10000, lang('goods_del_success'));
  233. } else {
  234. ds_json_encode(10001, lang('goods_del_fail'));
  235. }
  236. }
  237. /**
  238. * @api {POST} api/Sellerinviter/search_goods 选择活动商品
  239. * @apiVersion 1.0.0
  240. * @apiGroup Sellerinviter
  241. *
  242. * @apiHeader {String} X-DS-KEY 用户授权token
  243. *
  244. * @apiParam {String} goods_name 商品名称
  245. * @apiParam {String} page 页码
  246. * @apiParam {String} pagesize 每页显示数量
  247. *
  248. * @apiSuccess {String} code 返回码,10000为成功
  249. * @apiSuccess {String} message 返回消息
  250. * @apiSuccess {Object} result 返回数据
  251. */
  252. public function search_goods() {
  253. $goods_model = model('goods');
  254. $condition = array();
  255. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  256. $condition[] = array('inviter_open', '=', 0); //未选择为分销的商品
  257. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  258. $goods_list = $goods_model->getGoodsCommonList($condition, 'goods_commonid,goods_name,goods_price,goods_image,inviter_open', $this->pagesize);
  259. foreach ($goods_list as $key => $value) {
  260. $goods_list[$key]['goods_image'] = goods_cthumb($value['goods_image'], '240');
  261. }
  262. $result = array('goods_list' => $goods_list);
  263. $result = array_merge($result, mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  264. ds_json_encode(10000, '', $result);
  265. }
  266. public function inviter_goods_info() {
  267. $goods_commonid = intval(input('param.goods_commonid'));
  268. $data = array();
  269. $data['result'] = true;
  270. //获取商品具体信息用于显示
  271. $goods_model = model('goods');
  272. $condition = array();
  273. $condition[]=array('goods_commonid','=',$goods_commonid);
  274. $goods_list = $goods_model->getGoodsOnlineList($condition);
  275. if (empty($goods_list)) {
  276. $data['result'] = false;
  277. $data['message'] = lang('param_error');
  278. echo json_encode($data);
  279. die;
  280. }
  281. $goods_info = $goods_list[0];
  282. $data['goods_id'] = $goods_info['goods_id'];
  283. $data['goods_commonid'] = $goods_info['goods_commonid'];
  284. $data['goods_name'] = $goods_info['goods_name'];
  285. $data['goods_price'] = $goods_info['goods_price'];
  286. $data['goods_image'] = goods_thumb($goods_info, 240);
  287. echo json_encode($data);
  288. die;
  289. }
  290. }