Sellerinviter.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Sellerinviter extends BaseSeller {
  22. public function initialize() {
  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. $this->setSellerCurMenu('sellerinviter_order');
  32. /* 设置买家当前栏目 */
  33. $this->setSellerCurItem('order_list');
  34. $condition = array(array('orderinviter_store_id', '=', session('store_id')));
  35. if (input('param.orderinviter_order_sn')) {
  36. $condition[] = array('orderinviter_order_sn', 'like', '%' . input('param.orderinviter_order_sn') . '%');
  37. }
  38. $orderinviter_list = Db::name('orderinviter')->where($condition)->order('orderinviter_id desc')->paginate(10);
  39. $order_list=$orderinviter_list->items();
  40. foreach($order_list as $key => $val){
  41. $order_list[$key]['orderinviter_valid_text']=lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  42. }
  43. $page = $orderinviter_list->render();
  44. View::assign('show_page', $page);
  45. View::assign('orderinviter_list', $order_list);
  46. return View::fetch($this->template_dir . 'order_list');
  47. }
  48. public function goods_list() {
  49. $goods_model = model('goods');
  50. if (check_platform_store()) {
  51. View::assign('isPlatformStore', true);
  52. }
  53. $condition = array();
  54. $condition[] = array('store_id', '=', session('store_id'));
  55. $condition[] = array('inviter_open', '=', 1);
  56. if ((input('param.goods_name'))) {
  57. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  58. }
  59. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 10);
  60. View::assign('goods_list', $goods_list);
  61. View::assign('show_page', $goods_model->page_info->render());
  62. $storage_array = $goods_model->calculateStorage($goods_list);
  63. View::assign('storage_array', $storage_array);
  64. $this->setSellerCurMenu('sellerinviter_goods');
  65. $this->setSellerCurItem('goods_list');
  66. return View::fetch($this->template_dir . 'goods_list');
  67. }
  68. /**
  69. * 添加分销活动
  70. * */
  71. public function goods_add() {
  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. $goods_model = model('goods');
  112. if (!request()->isPost()) {
  113. $goods_commonid = intval(input('param.goods_commonid'));
  114. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . session('store_id'));
  115. if (!$goods_info) {
  116. $this->error(lang('sellerinviter_goods_empty'), 'Sellerinviter/goods_list');
  117. }
  118. View::assign('goods_info', $goods_info);
  119. //输出导航
  120. $this->setSellerCurMenu('sellerinviter_goods');
  121. $this->setSellerCurItem('goods_add');
  122. return View::fetch($this->template_dir . 'goods_add');
  123. } else {
  124. //验证输入
  125. $inviter_goods_commonid = intval(input('post.inviter_goods_commonid'));
  126. $inviter_ratio = floatval(input('post.inviter_ratio'));
  127. if (!($inviter_goods_commonid)) {
  128. ds_json_encode(10001, lang('inviter_goods_commonid_required'));
  129. }
  130. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $inviter_goods_commonid . ' AND inviter_open=1 AND store_id=' . session('store_id'));
  131. if (!$goods_info) {
  132. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  133. }
  134. if ($inviter_ratio <= 0) {
  135. ds_json_encode(10001, lang('inviter_ratio_min') . 0.01 . lang('ds_percent'));
  136. }
  137. if ($inviter_ratio > 100) {
  138. ds_json_encode(10001, lang('inviter_ratio_max') . 100 . lang('ds_percent'));
  139. }
  140. $result = $goods_model->editGoodsCommonById(array(
  141. 'inviter_ratio' => $inviter_ratio,
  142. ), array($inviter_goods_commonid));
  143. if ($result) {
  144. $this->recordSellerlog('编辑分销商品,商品编号:' . $inviter_goods_commonid);
  145. ds_json_encode(10000, lang('goods_edit_success'));
  146. } else {
  147. ds_json_encode(10001, lang('goods_edit_fail'));
  148. }
  149. }
  150. }
  151. public function goods_del() {
  152. $goods_model = model('goods');
  153. $goods_commonid = intval(input('param.goods_commonid'));
  154. $goods_info = $goods_model->getGoodsCommonInfo('goods_commonid=' . $goods_commonid . ' AND inviter_open=1 AND store_id=' . session('store_id'));
  155. if (!$goods_info) {
  156. ds_json_encode(10001, lang('sellerinviter_goods_empty'));
  157. }
  158. $result = $goods_model->editGoodsCommonById(array(
  159. 'inviter_open' => 0,
  160. ), array($goods_commonid));
  161. if ($result) {
  162. $this->recordSellerlog('删除分销商品,商品编号:' . $goods_commonid);
  163. ds_json_encode(10000, lang('goods_del_success'));
  164. } else {
  165. ds_json_encode(10001, lang('goods_del_fail'));
  166. }
  167. }
  168. /**
  169. * 选择活动商品
  170. * */
  171. public function search_goods() {
  172. $goods_model = model('goods');
  173. $condition = array();
  174. $condition[] = array('store_id', '=', session('store_id'));
  175. $condition[] = array('goods_name', 'like', '%' . input('param.goods_name') . '%');
  176. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 8);
  177. View::assign('goods_list', $goods_list);
  178. View::assign('show_page', $goods_model->page_info->render());
  179. echo View::fetch($this->template_dir . 'search_goods');
  180. exit;
  181. }
  182. public function inviter_goods_info() {
  183. $goods_commonid = intval(input('param.goods_commonid'));
  184. $data = array();
  185. $data['result'] = true;
  186. //获取商品具体信息用于显示
  187. $goods_model = model('goods');
  188. $condition = array();
  189. $condition[]=array('goods_commonid','=',$goods_commonid);
  190. $goods_list = $goods_model->getGoodsOnlineList($condition);
  191. if (empty($goods_list)) {
  192. $data['result'] = false;
  193. $data['message'] = lang('param_error');
  194. echo json_encode($data);
  195. die;
  196. }
  197. $goods_info = $goods_list[0];
  198. $data['goods_id'] = $goods_info['goods_id'];
  199. $data['goods_commonid'] = $goods_info['goods_commonid'];
  200. $data['goods_name'] = $goods_info['goods_name'];
  201. $data['goods_price'] = $goods_info['goods_price'];
  202. $data['goods_image'] = goods_thumb($goods_info, 240);
  203. $data['goods_href'] = (string) url('Goods/index', array('goods_id' => $goods_info['goods_id']));
  204. echo json_encode($data);
  205. die;
  206. }
  207. protected function getSellerItemList() {
  208. $menu_array = array();
  209. switch (request()->action()) {
  210. case 'goods_list':
  211. $menu_array[] = array(
  212. 'name' => 'goods_list', 'text' => lang('goods_list'),
  213. 'url' => (string) url('Sellerinviter/goods_list')
  214. );
  215. break;
  216. case 'order_list':
  217. $menu_array[] = array(
  218. 'name' => 'order_list', 'text' => lang('order_list'), 'url' => (string) url('Sellerinviter/order_list')
  219. );
  220. break;
  221. }
  222. return $menu_array;
  223. }
  224. }