Sellerinviter.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. /**
  3. * 卖家分销管理
  4. */
  5. namespace app\home\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. use think\facade\Db;
  9. /**
  10. *
  11. *
  12. * ----------------------------------------------------------------------------
  13. *
  14. * 控制器
  15. */
  16. class Sellerinviter extends BaseSeller
  17. {
  18. public function initialize()
  19. {
  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. $this->error(lang('promotion_unavailable'), 'seller/index');
  24. }
  25. }
  26. public function order_list()
  27. {
  28. /* 设置买家当前菜单 */
  29. $this->setSellerCurMenu('sellerinviter_order');
  30. /* 设置买家当前栏目 */
  31. $this->setSellerCurItem('order_list');
  32. $condition = array(array('orderinviter_store_id', '=', session('store_id')));
  33. if (input('param.orderinviter_order_sn')) {
  34. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  35. }
  36. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  37. $order_list = $orderinviter_list->items();
  38. foreach ($order_list as $key => $val) {
  39. $order_list[$key]['orderinviter_valid_text'] = lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  40. }
  41. $page = $orderinviter_list->render();
  42. View::assign('show_page', $page);
  43. View::assign('orderinviter_list', $order_list);
  44. return View::fetch($this->template_dir . 'order_list');
  45. }
  46. public function goods_list()
  47. {
  48. $goods_model = model('goods');
  49. if (check_platform_store()) {
  50. View::assign('isPlatformStore', true);
  51. }
  52. $condition = array();
  53. $condition[] = array('store_id', '=', session('store_id'));
  54. $condition[] = array('inviter_open', '=', 1);
  55. if ((input('param.goods_name'))) {
  56. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  57. }
  58. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 10);
  59. View::assign('goods_list', $goods_list);
  60. View::assign('show_page', $goods_model->page_info->render());
  61. $storage_array = $goods_model->calculateStorage($goods_list);
  62. View::assign('storage_array', $storage_array);
  63. $this->setSellerCurMenu('sellerinviter_goods');
  64. $this->setSellerCurItem('goods_list');
  65. return View::fetch($this->template_dir . 'goods_list');
  66. }
  67. /**
  68. * 添加分销活动
  69. * */
  70. public function goods_add()
  71. {
  72. $goods_model = model('goods');
  73. if (!request()->isPost()) {
  74. //输出导航
  75. $this->setSellerCurMenu('sellerinviter_goods');
  76. $this->setSellerCurItem('goods_add');
  77. return View::fetch($this->template_dir . 'goods_add');
  78. } else {
  79. //验证输入
  80. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  81. $inviter_ratio = floatval(input('post.inviter_ratio'));
  82. if (!($inviter_goods_commonid)) {
  83. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  84. }
  85. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND store_id=' . session('store_id'));
  86. if (!$goods_info) {
  87. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  88. }
  89. if ($inviter_ratio <= 0) {
  90. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . lang('ds_percent'));
  91. }
  92. if ($inviter_ratio > 100) {
  93. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . lang('ds_percent'));
  94. }
  95. $result = $goods_model->editGoodsCommonById(array(
  96. 'inviter_open' => 1,
  97. 'inviter_ratio' => $inviter_ratio,
  98. ), array($inviter_goods_commonid));
  99. if ($result) {
  100. $this->recordSellerlog('添加分销商品,商品编号:' . $inviter_goods_commonid);
  101. ds_json_encode(10001, lang('goods_add_success'));
  102. } else {
  103. ds_json_encode(10001, lang('goods_add_fail'));
  104. }
  105. }
  106. }
  107. /**
  108. * 编辑分销活动
  109. * */
  110. public function goods_edit()
  111. {
  112. $goods_model = model('goods');
  113. if (!request()->isPost()) {
  114. $goods_commonid = intval(input('param.goods_commonid'));
  115. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . session('store_id'));
  116. if (!$goods_info) {
  117. $this->error(lang('sellerinviter_goods_empty'), 'Sellerinviter/goods_list');
  118. }
  119. View::assign('goods_info', $goods_info);
  120. //输出导航
  121. $this->setSellerCurMenu('sellerinviter_goods');
  122. $this->setSellerCurItem('goods_add');
  123. return View::fetch($this->template_dir . 'goods_add');
  124. } else {
  125. //验证输入
  126. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  127. $inviter_ratio = floatval(input('post.inviter_ratio'));
  128. if (!($inviter_goods_commonid)) {
  129. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  130. }
  131. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND inviter_open=1 AND store_id=' . session('store_id'));
  132. if (!$goods_info) {
  133. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  134. }
  135. if ($inviter_ratio <= 0) {
  136. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . lang('ds_percent'));
  137. }
  138. if ($inviter_ratio > 100) {
  139. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . lang('ds_percent'));
  140. }
  141. $result = $goods_model->editGoodsCommonById(array(
  142. 'inviter_ratio' => $inviter_ratio,
  143. ), array($inviter_goods_commonid));
  144. if ($result) {
  145. $this->recordSellerlog('编辑分销商品,商品编号:' . $inviter_goods_commonid);
  146. ds_json_encode(10000, lang('goods_edit_success'));
  147. } else {
  148. ds_json_encode(10001, lang('goods_edit_fail'));
  149. }
  150. }
  151. }
  152. public function goods_del()
  153. {
  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=' . session('store_id'));
  157. if (!$goods_info) {
  158. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  159. }
  160. $result = $goods_model->editGoodsCommonById(array(
  161. 'inviter_open' => 0,
  162. ), array($goods_commonid));
  163. if ($result) {
  164. $this->recordSellerlog('删除分销商品,商品编号:' . $goods_commonid);
  165. ds_json_encode(10000, lang('goods_del_success'));
  166. } else {
  167. ds_json_encode(10001, lang('goods_del_fail'));
  168. }
  169. }
  170. /**
  171. * 选择活动商品
  172. * */
  173. public function search_goods()
  174. {
  175. $goods_model = model('goods');
  176. $condition = array();
  177. $condition[] = array('store_id', '=', session('store_id'));
  178. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  179. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 8);
  180. View::assign('goods_list', $goods_list);
  181. View::assign('show_page', $goods_model->page_info->render());
  182. echo View::fetch($this->template_dir . 'search_goods');
  183. exit;
  184. }
  185. public function inviter_goods_info()
  186. {
  187. $goods_commonid = intval(input('param.goods_commonid'));
  188. $data = array();
  189. $data['result'] = true;
  190. //获取商品具体信息用于显示
  191. $goods_model = model('goods');
  192. $condition = array();
  193. $condition[] = array('goods_commonid', '=', $goods_commonid);
  194. $goods_list = $goods_model->getGoodsOnlineList($condition);
  195. if (empty($goods_list)) {
  196. $data['result'] = false;
  197. $data['message'] = lang('param_error');
  198. echo json_encode($data);
  199. die;
  200. }
  201. $goods_info = $goods_list[0];
  202. $data['goods_id'] = $goods_info['goods_id'];
  203. $data['goods_commonid'] = $goods_info['goods_commonid'];
  204. $data['goods_name'] = $goods_info['goods_name'];
  205. $data['goods_price'] = $goods_info['goods_price'];
  206. $data['goods_image'] = goods_thumb($goods_info, 240);
  207. $data['goods_href'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  208. echo json_encode($data);
  209. die;
  210. }
  211. protected function getSellerItemList()
  212. {
  213. $menu_array = array();
  214. switch (request()->action()) {
  215. case 'goods_list':
  216. $menu_array[] = array(
  217. 'name' => 'goods_list', 'text' => lang('goods_list'),
  218. 'url' => (string) url('Sellerinviter/goods_list')
  219. );
  220. break;
  221. case 'order_list':
  222. $menu_array[] = array(
  223. 'name' => 'order_list', 'text' => lang('order_list'), 'url' => (string) url('Sellerinviter/order_list')
  224. );
  225. break;
  226. }
  227. return $menu_array;
  228. }
  229. }