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