Sellerinviter.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 卖家分销控制器
  12. */
  13. class Sellerinviter extends MobileSeller
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerinviter.lang.php');
  19. if (intval(config('ds_config.inviter_open')) !== 1) {
  20. ds_json_encode(10001, lang('promotion_unavailable'));
  21. }
  22. }
  23. /**
  24. * @api {POST} api/Sellerinviter/order_list 分销业绩
  25. * @apiVersion 1.0.0
  26. * @apiGroup Sellerinviter
  27. *
  28. * @apiHeader {String} X-DS-KEY 用户授权token
  29. *
  30. * @apiParam {String} orderinviter_order_sn 订单号
  31. * @apiParam {String} page 页码
  32. * @apiParam {String} pagesize 每页显示数量
  33. *
  34. * @apiSuccess {String} code 返回码,10000为成功
  35. * @apiSuccess {String} message 返回消息
  36. * @apiSuccess {Object} result 返回数据
  37. * @apiSuccess {Object[]} result.order_list 分销订单列表 (返回字段参考orderinviter表)
  38. * @apiSuccess {Int} result.page_total 总页数
  39. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  40. */
  41. public function order_list()
  42. {
  43. $condition = array(array('orderinviter_store_id', '=', $this->store_info['store_id']));
  44. if (input('param.orderinviter_order_sn')) {
  45. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  46. }
  47. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  48. $order_list = $orderinviter_list->items();
  49. foreach ($order_list as $key => $val) {
  50. $order_list[$key]['orderinviter_valid_text'] = lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  51. }
  52. $result = array_merge(array('order_list' => $order_list), mobile_page($orderinviter_list));
  53. ds_json_encode(10000, lang('ds_common_op_succ'), $result);
  54. }
  55. /**
  56. * @api {POST} api/Sellerinviter/goods_list 分销商品
  57. * @apiVersion 1.0.0
  58. * @apiGroup Sellerinviter
  59. *
  60. * @apiHeader {String} X-DS-KEY 用户授权token
  61. *
  62. * @apiParam {String} goods_name 商品名
  63. * @apiParam {String} page 页码
  64. * @apiParam {String} pagesize 每页显示数量
  65. *
  66. * @apiSuccess {String} code 返回码,10000为成功
  67. * @apiSuccess {String} message 返回消息
  68. * @apiSuccess {Object} result 返回数据
  69. * @apiSuccess {Object[]} result.goods_list 分销商品列表 (返回字段参考goodscommon表)
  70. * @apiSuccess {Object} result.storage_array 库存列表,键为商品公共ID
  71. * @apiSuccess {Int} result.storage_array.sum 库存
  72. * @apiSuccess {Int} result.storage_array.goods_id 商品ID
  73. */
  74. public function goods_list()
  75. {
  76. $goods_model = model('goods');
  77. if (check_platform_store()) {
  78. View::assign('isPlatformStore', true);
  79. }
  80. $condition = array();
  81. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  82. $condition[] = array('inviter_open', '=', 1);
  83. if ((input('param.goods_name'))) {
  84. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  85. }
  86. $goods_list = $goods_model->getGoodsCommonList($condition, '*', $this->pagesize);
  87. foreach ($goods_list as $key => $val) {
  88. $goods_list[$key]['goods_image'] = goods_cthumb($val['goods_image']);
  89. }
  90. $result = array('goods_list' => $goods_list);
  91. $result = array_merge($result, mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  92. ds_json_encode(10000, '', $result);
  93. }
  94. /**
  95. * @api {POST} api/Sellerinviter/goods_add 添加分销活动
  96. * @apiVersion 1.0.0
  97. * @apiGroup Sellerinviter
  98. *
  99. * @apiHeader {String} X-DS-KEY 用户授权token
  100. *
  101. * @apiParam {Int} inviter_goods_commonid 商品公共ID
  102. * @apiParam {Float} inviter_ratio_1 一级分销佣金比例
  103. * @apiParam {Float} inviter_ratio_2 二级分销佣金比例
  104. * @apiParam {Float} inviter_ratio_3 三级分销佣金比例
  105. *
  106. * @apiSuccess {String} code 返回码,10000为成功
  107. * @apiSuccess {String} message 返回消息
  108. * @apiSuccess {Object} result 返回数据
  109. */
  110. public function goods_add()
  111. {
  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. {
  156. $goods_model = model('goods');
  157. $goods_commonid = intval(input('param.goods_commonid'));
  158. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  159. if (!$goods_info) {
  160. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  161. }
  162. ds_json_encode(10000, '', array('info' => $goods_info));
  163. }
  164. /**
  165. * @api {POST} api/Sellerinviter/goods_edit 编辑分销活动
  166. * @apiVersion 1.0.0
  167. * @apiGroup Sellerinviter
  168. *
  169. * @apiHeader {String} X-DS-KEY 用户授权token
  170. *
  171. * @apiParam {Int} inviter_goods_commonid 商品公共ID
  172. * @apiParam {Float} inviter_ratio_1 一级分销佣金比例
  173. * @apiParam {Float} inviter_ratio_2 二级分销佣金比例
  174. * @apiParam {Float} inviter_ratio_3 三级分销佣金比例
  175. *
  176. * @apiSuccess {String} code 返回码,10000为成功
  177. * @apiSuccess {String} message 返回消息
  178. * @apiSuccess {Object} result 返回数据
  179. */
  180. public function goods_edit()
  181. {
  182. $goods_model = model('goods');
  183. //验证输入
  184. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  185. $inviter_ratio = floatval(input('post.inviter_ratio'));
  186. if (!($inviter_goods_commonid)) {
  187. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  188. }
  189. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  190. if (!$goods_info) {
  191. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  192. }
  193. if ($inviter_ratio <= 0) {
  194. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . '%');
  195. }
  196. if ($inviter_ratio > 100) {
  197. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . '%');
  198. }
  199. $result = $goods_model->editGoodsCommonById(array(
  200. 'inviter_ratio' => $inviter_ratio,
  201. ), array($inviter_goods_commonid));
  202. if ($result) {
  203. $this->recordSellerlog('编辑分销商品,商品编号:' . $inviter_goods_commonid);
  204. ds_json_encode(10000, lang('goods_edit_success'));
  205. } else {
  206. ds_json_encode(10001, lang('goods_edit_fail'));
  207. }
  208. }
  209. /**
  210. * @api {POST} api/Sellerinviter/goods_del 删除分销商品
  211. * @apiVersion 1.0.0
  212. * @apiGroup Sellerinviter
  213. *
  214. * @apiHeader {String} X-DS-KEY 用户授权token
  215. *
  216. * @apiParam {Int} goods_commonid 商品公共ID
  217. *
  218. * @apiSuccess {String} code 返回码,10000为成功
  219. * @apiSuccess {String} message 返回消息
  220. * @apiSuccess {Object} result 返回数据
  221. */
  222. public function goods_del()
  223. {
  224. $goods_model = model('goods');
  225. $goods_commonid = intval(input('param.goods_commonid'));
  226. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . $this->store_info['store_id']);
  227. if (!$goods_info) {
  228. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  229. }
  230. $result = $goods_model->editGoodsCommonById(array(
  231. 'inviter_open' => 0,
  232. ), array($goods_commonid));
  233. if ($result) {
  234. $this->recordSellerlog('删除分销商品,商品编号:' . $goods_commonid);
  235. ds_json_encode(10000, lang('goods_del_success'));
  236. } else {
  237. ds_json_encode(10001, lang('goods_del_fail'));
  238. }
  239. }
  240. /**
  241. * @api {POST} api/Sellerinviter/search_goods 选择活动商品
  242. * @apiVersion 1.0.0
  243. * @apiGroup Sellerinviter
  244. *
  245. * @apiHeader {String} X-DS-KEY 用户授权token
  246. *
  247. * @apiParam {String} goods_name 商品名称
  248. * @apiParam {String} page 页码
  249. * @apiParam {String} pagesize 每页显示数量
  250. *
  251. * @apiSuccess {String} code 返回码,10000为成功
  252. * @apiSuccess {String} message 返回消息
  253. * @apiSuccess {Object} result 返回数据
  254. */
  255. public function search_goods()
  256. {
  257. $goods_model = model('goods');
  258. $condition = array();
  259. $condition[] = array('store_id', '=', $this->store_info['store_id']);
  260. $condition[] = array('inviter_open', '=', 0); //未选择为分销的商品
  261. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  262. $goods_list = $goods_model->getGoodsCommonList($condition, 'goods_commonid,goods_name,goods_price,goods_image,inviter_open', $this->pagesize);
  263. foreach ($goods_list as $key => $value) {
  264. $goods_list[$key]['goods_image'] = goods_cthumb($value['goods_image'], '240');
  265. }
  266. $result = array('goods_list' => $goods_list);
  267. $result = array_merge($result, mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  268. ds_json_encode(10000, '', $result);
  269. }
  270. public function inviter_goods_info()
  271. {
  272. $goods_commonid = intval(input('param.goods_commonid'));
  273. $data = array();
  274. $data['result'] = true;
  275. //获取商品具体信息用于显示
  276. $goods_model = model('goods');
  277. $condition = array();
  278. $condition[] = array('goods_commonid', '=', $goods_commonid);
  279. $goods_list = $goods_model->getGoodsOnlineList($condition);
  280. if (empty($goods_list)) {
  281. $data['result'] = false;
  282. $data['message'] = lang('param_error');
  283. echo json_encode($data);
  284. die;
  285. }
  286. $goods_info = $goods_list[0];
  287. $data['goods_id'] = $goods_info['goods_id'];
  288. $data['goods_commonid'] = $goods_info['goods_commonid'];
  289. $data['goods_name'] = $goods_info['goods_name'];
  290. $data['goods_price'] = $goods_info['goods_price'];
  291. $data['goods_image'] = goods_thumb($goods_info, 240);
  292. echo json_encode($data);
  293. die;
  294. }
  295. }