Sellerinviter.php 13 KB

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