Sellerinviter.php 10 KB

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