Inviter.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <?php
  2. /**
  3. * 推荐人设置
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Db;
  8. use think\facade\Lang;
  9. /**
  10. * ============================================================================
  11. * DSMall多用户商城
  12. * ============================================================================
  13. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  14. * 网站地址: http://www.csdeshang.com
  15. * ----------------------------------------------------------------------------
  16. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  17. * 不允许对程序代码以任何形式任何目的的再发布。
  18. * ============================================================================
  19. * 控制器
  20. */
  21. class Inviter extends AdminControl
  22. {
  23. public function initialize()
  24. {
  25. parent::initialize(); // TODO: Change the autogenerated stub
  26. Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/inviter.lang.php');
  27. }
  28. /**
  29. * 基本设置
  30. */
  31. public function setting(){
  32. $config_model = model('config');
  33. if (request()->isPost()){
  34. $upload_file = BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . ATTACH_COMMON;
  35. if (!empty($_FILES['inviter_back']['name'])) {
  36. $res=ds_upload_pic(ATTACH_COMMON,'inviter_back', 'inviter_back.png');
  37. if($res['code']){
  38. $file_name=$res['data']['file_name'];
  39. $upload['inviter_back'] = $file_name;
  40. }else{
  41. $this->error($res['msg']);
  42. }
  43. }
  44. if (!empty($upload['inviter_back'])) {
  45. $update_array['inviter_back'] = $upload['inviter_back'];
  46. }
  47. $update_array['inviter_ratio_1']=floatval(input('post.inviter_ratio_1'));
  48. $update_array['inviter_ratio_2']=floatval(input('post.inviter_ratio_2'));
  49. $update_array['inviter_ratio_3']=floatval(input('post.inviter_ratio_3'));
  50. $update_array['inviter_open']=intval(input('post.inviter_open'));
  51. $update_array['inviter_level']=intval(input('post.inviter_level'));
  52. $update_array['inviter_show']=floatval(input('post.inviter_show'));
  53. $update_array['inviter_return']=floatval(input('post.inviter_return'));
  54. $update_array['inviter_view']=floatval(input('post.inviter_view'));
  55. $update_array['inviter_condition']=floatval(input('post.inviter_condition'));
  56. $update_array['inviter_condition_amount']=floatval(input('post.inviter_condition_amount'));
  57. if($update_array['inviter_return']){
  58. if(($update_array['inviter_ratio_1']*2+$update_array['inviter_ratio_2']+$update_array['inviter_ratio_3'])>100){
  59. $this->error(lang('inviter_ratio_error'));
  60. }
  61. }else{
  62. if(($update_array['inviter_ratio_1']+$update_array['inviter_ratio_2']+$update_array['inviter_ratio_3'])>100){
  63. $this->error(lang('inviter_ratio_error'));
  64. }
  65. }
  66. $result = $config_model->editConfig($update_array);
  67. if ($result) {
  68. $this->log(lang('ds_inviter_set'),1);
  69. $this->success(lang('ds_common_op_succ'), 'Inviter/setting');
  70. }else{
  71. $this->log(lang('ds_inviter_set'),0);
  72. }
  73. } else {
  74. $list_setting = rkcache('config', true);
  75. View::assign('list_setting', $list_setting);
  76. $this->setAdminCurItem('index');
  77. return View::fetch('index');
  78. }
  79. }
  80. public function goods(){
  81. $goods_model=model('goods');
  82. $condition = array();
  83. $condition[]=array('inviter_open','=',1);
  84. if ((input('param.goods_name'))) {
  85. $condition[]=array('goods_name','like', '%' . input('param.goods_name') . '%');
  86. }
  87. $goods_list = $goods_model->getGoodsCommonList($condition, '*', 10);
  88. View::assign('goods_list', $goods_list);
  89. View::assign('show_page', $goods_model->page_info->render());
  90. $this->setAdminCurItem('goods');
  91. return View::fetch('goods');
  92. }
  93. public function order(){
  94. $search_field_value = input('param.search_field_value');
  95. $search_field_name = input('param.search_field_name');
  96. $condition = array();
  97. if ($search_field_value != '') {
  98. switch ($search_field_name) {
  99. case 'orderinviter_member_name':
  100. $condition[] = array('orderinviter_member_name','=',$search_field_value);
  101. break;
  102. case 'orderinviter_order_sn':
  103. $condition[] = array('orderinviter_order_sn','=',$search_field_value);
  104. break;
  105. case 'orderinviter_store_name':
  106. $condition[] = array('orderinviter_store_name','=',$search_field_value);
  107. break;
  108. }
  109. }
  110. $orderinviter_list=Db::name('orderinviter')->where($condition)->order('orderinviter_addtime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  111. $order_list=$orderinviter_list->items();
  112. foreach($order_list as $key => $val){
  113. $order_list[$key]['orderinviter_valid_text']=lang('orderinviter_valid_array')[$val['orderinviter_valid']];
  114. }
  115. View::assign('orderinviter_list', $order_list);
  116. View::assign('show_page', $orderinviter_list->render());
  117. View::assign('search_field_name', trim($search_field_name));
  118. View::assign('search_field_value', trim($search_field_value));
  119. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  120. $this->setAdminCurItem('order');
  121. return View::fetch();
  122. }
  123. public function member(){
  124. $inviter_model=model('inviter');
  125. $search_field_value = input('search_field_value');
  126. $search_field_name = input('search_field_name');
  127. $condition = array();
  128. if ($search_field_value != '') {
  129. switch ($search_field_name) {
  130. case 'member_name':
  131. $condition[]=array('member_name','like', '%' . trim($search_field_value) . '%');
  132. break;
  133. case 'member_email':
  134. $condition[]=array('member_email','like', '%' . trim($search_field_value) . '%');
  135. break;
  136. case 'member_mobile':
  137. $condition[]=array('member_mobile','like', '%' . trim($search_field_value) . '%');
  138. break;
  139. case 'member_truename':
  140. $condition[]=array('member_truename','like', '%' . trim($search_field_value) . '%');
  141. break;
  142. }
  143. }
  144. $member_list = $inviter_model->getInviterList($condition, 10,'','i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename');
  145. $inviterclass_model=model('inviterclass');
  146. foreach($member_list as $key => $item){
  147. $member_list[$key]['inviter_parent_name']='';
  148. $member_list[$key]['inviter_class']='';
  149. $member_list[$key]['inviter_class']=$inviterclass_model->getInviterclass($item['inviter_total_amount']);
  150. if($item['inviter_parent_id']){
  151. $member_list[$key]['inviter_parent_name'] = Db::name('member')->where('member_id='.$item['inviter_parent_id'])->value('member_name');
  152. }
  153. }
  154. View::assign('member_list', $member_list);
  155. View::assign('show_page', $inviter_model->page_info->render());
  156. View::assign('search_field_name', trim($search_field_name));
  157. View::assign('search_field_value', trim($search_field_value));
  158. View::assign('filtered', $condition ? 1 : 0); //是否有查询条件
  159. $this->setAdminCurItem('member');
  160. return View::fetch('member');
  161. }
  162. public function memberclass(){
  163. $memberclass_list=Db::name('inviterclass')->order('inviterclass_amount asc')->select()->toArray();
  164. View::assign('memberclass_list',$memberclass_list);
  165. $this->setAdminCurItem('memberclass');
  166. return View::fetch('memberclass');
  167. }
  168. public function member_adjust(){
  169. $member_id=intval(input('param.member_id'));
  170. if(!$member_id){
  171. $this->error(lang('param_error'));
  172. }
  173. $inviter_model=model('inviter');
  174. $inviter_info=$inviter_model->getInviterInfo(array('m.member_id'=>$member_id),'m.member_id,m.inviter_id as inviter_parent_id,i.inviter_1_quantity,i.inviter_2_quantity,i.inviter_3_quantity');
  175. if(!$inviter_info){
  176. $this->error(lang('inviter_member_empty'));
  177. }
  178. if (request()->isPost()) {
  179. $member_name=trim(input('param.member_name'));
  180. if($member_name){
  181. $inviter=$inviter_model->getInviterInfo(array('m.member_name'=>$member_name),'m.member_id');
  182. $inviter_id=$inviter['member_id'];
  183. if(!$inviter_id){
  184. $this->error(lang('inviter_member_empty'));
  185. }
  186. //上级不能是自己
  187. if($inviter_id==$member_id){
  188. $this->error(lang('inviter_parent_error'));
  189. }
  190. //上级不能是自己下级中(3级内)的成员
  191. if(Db::name('member')->where('inviter_id='.$member_id.' AND member_id='.$inviter_id)->value('member_id')){
  192. $this->error(lang('inviter_parent_error2'));
  193. }
  194. $subQuery=Db::name('member')->field('member_id')->where('inviter_id='.$member_id)->buildSql();
  195. if(Db::name('member')->where('member_id='.$inviter_id.' AND inviter_id IN'.$subQuery)->value('member_id')){
  196. $this->error(lang('inviter_parent_error2'));
  197. }
  198. $subQuery=Db::name('member')->field('member_id')->where('inviter_id IN'.$subQuery)->buildSql();
  199. if(Db::name('member')->where('member_id='.$inviter_id.' AND inviter_id IN'.$subQuery)->value('member_id')){
  200. $this->error(lang('inviter_parent_error2'));
  201. }
  202. }else{
  203. $inviter_id=0;
  204. }
  205. Db::name('member')->where('member_id='.$member_id)->update(array(
  206. 'inviter_id'=>$inviter_id
  207. ));
  208. //给旧的父级减去下线成员
  209. if($inviter_info['inviter_parent_id']){
  210. Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_1_quantity>=1')->dec('inviter_1_quantity')->update();
  211. Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_2_quantity>='.$inviter_info['inviter_1_quantity'])->dec('inviter_2_quantity',$inviter_info['inviter_1_quantity'])->update();
  212. Db::name('inviter')->where('inviter_id='.$inviter_info['inviter_parent_id'].' AND inviter_3_quantity>='.$inviter_info['inviter_2_quantity'])->dec('inviter_3_quantity',$inviter_info['inviter_2_quantity'])->update();
  213. //父级的父级
  214. $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$inviter_info['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
  215. if($temp['inviter_parent_id']){
  216. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_2_quantity>=1')->dec('inviter_2_quantity')->update();
  217. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_3_quantity>='.$inviter_info['inviter_1_quantity'])->dec('inviter_3_quantity',$inviter_info['inviter_1_quantity'])->update();
  218. //父级的父级的父级
  219. $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$temp['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
  220. if($temp['inviter_parent_id']){
  221. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'].' AND inviter_3_quantity>=1')->dec('inviter_3_quantity')->update();
  222. }
  223. }
  224. }
  225. //给新的父级增加下线成员
  226. if($inviter_id){
  227. Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_1_quantity')->update();
  228. Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_2_quantity',$inviter_info['inviter_1_quantity'])->update();
  229. Db::name('inviter')->where('inviter_id='.$inviter_id)->inc('inviter_3_quantity',$inviter_info['inviter_2_quantity'])->update();
  230. //父级的父级
  231. $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$inviter_id),'m.inviter_id as inviter_parent_id');
  232. if($temp['inviter_parent_id']){
  233. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_2_quantity')->update();
  234. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_3_quantity',$inviter_info['inviter_1_quantity'])->update();
  235. //父级的父级的父级
  236. $temp=$inviter_model->getInviterInfo(array('m.member_id'=>$temp['inviter_parent_id']),'m.inviter_id as inviter_parent_id');
  237. if($temp['inviter_parent_id']){
  238. Db::name('inviter')->where('inviter_id='.$temp['inviter_parent_id'])->inc('inviter_3_quantity')->update();
  239. }
  240. }
  241. }
  242. $this->log(lang('adjust_superior') . '[ID:' . $member_id . ']', 1);
  243. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  244. }else{
  245. return View::fetch();
  246. }
  247. }
  248. /**
  249. * 添加标签
  250. */
  251. public function memberclass_add(){
  252. if (request()->isPost()) {
  253. $data=array(
  254. 'inviterclass_name'=>trim(input('post.inviterclass_name')),
  255. 'inviterclass_amount'=>abs(floatval(input('post.inviterclass_amount'))),
  256. );
  257. if(!$data['inviterclass_name']){
  258. $this->error(lang('param_error'));
  259. }
  260. Db::name('inviterclass')->insert($data);
  261. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  262. }else{
  263. return View::fetch('memberclass_form');
  264. }
  265. }
  266. /**
  267. * 编辑标签
  268. */
  269. public function memberclass_edit()
  270. {
  271. $id=intval(input('param.id'));
  272. if(!$id){
  273. $this->error(lang('param_error'));
  274. }
  275. $inviterclass_info=Db::name('inviterclass')->where('inviterclass_id',$id)->find();
  276. if(!$inviterclass_info){
  277. $this->error(lang('inviterclass_empty'));
  278. }
  279. // 实例化模型
  280. if (request()->isPost()) {
  281. $data=array(
  282. 'inviterclass_name'=>trim(input('post.inviterclass_name')),
  283. 'inviterclass_amount'=>abs(floatval(input('post.inviterclass_amount'))),
  284. );
  285. if(!$data['inviterclass_name']){
  286. $this->error(lang('param_error'));
  287. }
  288. Db::name('inviterclass')->where('inviterclass_id',$id)->update($data);
  289. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  290. } else {
  291. View::assign('inviterclass_info', $inviterclass_info);
  292. return View::fetch('memberclass_form');
  293. }
  294. }
  295. /**
  296. * 删除标签
  297. */
  298. public function memberclass_del()
  299. {
  300. $inviterclass_id = input('param.id');
  301. $inviterclass_id_array = ds_delete_param($inviterclass_id);
  302. if ($inviterclass_id_array == FALSE) {
  303. ds_json_encode('10001', lang('param_error'));
  304. }
  305. $result=Db::name('inviterclass')->where(array(array('inviterclass_id','in',$inviterclass_id_array)))->delete();
  306. if ($result) {
  307. ds_json_encode('10000', lang('ds_common_del_succ'));
  308. }
  309. else {
  310. ds_json_encode('10001', lang('ds_common_del_fail'));
  311. }
  312. }
  313. public function memberstate(){
  314. $member_id=input('param.member_id');
  315. $member_id_array = ds_delete_param($member_id);
  316. $member_state=input('param.member_state');
  317. if(!$member_id_array || !in_array($member_state, array(1,2))){
  318. ds_json_encode('10001', lang('param_error'));
  319. }
  320. $inviter_model=model('inviter');
  321. $inviter_info=$inviter_model->getInviterInfo(array(array('i.inviter_id','in',$member_id_array)));
  322. if(!$inviter_info){
  323. ds_json_encode('10001', lang('inviter_member_empty'));
  324. }
  325. $inviter_model->editInviter(array(array('inviter_id','in',$member_id_array)),array('inviter_state'=>$member_state));
  326. $this->log(($member_state==1?lang('ds_enable'):lang('ds_disable')) . '[ID:' . implode(',', $member_id_array) . ']', 1);
  327. ds_json_encode('10000', ($member_state==1?lang('ds_enable'):lang('ds_disable')).lang('ds_succ'));
  328. }
  329. public function memberinfo(){
  330. $member_id=input('param.member_id');
  331. if(!$member_id){
  332. ds_json_encode('10001', lang('param_error'));
  333. }
  334. $inviter_model=model('inviter');
  335. $inviter_info=$inviter_model->getInviterInfo(array('i.inviter_id'=>$member_id),'i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename');
  336. if(!$inviter_info){
  337. ds_json_encode('10001', lang('inviter_member_empty'));
  338. }
  339. $inviter_info['inviter_parent_name']='';
  340. if($inviter_info['inviter_parent_id']){
  341. $inviter_info['inviter_parent_name']= Db::name('member')->where('member_id='.$inviter_info['inviter_parent_id'])->value('member_name');
  342. }
  343. $inviterclass_model=model('inviterclass');
  344. $inviter_info['inviter_class']=$inviterclass_model->getInviterclass($inviter_info['inviter_total_amount']);
  345. View::assign('inviter_info',$inviter_info);
  346. $this->setAdminCurItem('member');
  347. return View::fetch('memberinfo');
  348. }
  349. public function memberlist(){
  350. $member_id=intval(input('param.member_id'));
  351. $type=input('param.type');
  352. if(!$member_id || !in_array($type, array(1,2,3))){
  353. return;
  354. }
  355. $inviter_model=model('inviter');
  356. if($type==1){
  357. $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  358. $page_info=$res;
  359. $member_list=$res->items();
  360. }elseif($type==2){
  361. $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->buildSql();
  362. $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  363. $page_info=$res;
  364. $member_list=$res->items();
  365. }elseif($type==3){
  366. $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id='.$member_id)->order('inviter_applytime desc')->buildSql();
  367. $subQuery=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('m.member_id')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->buildSql();
  368. $res=Db::name('member')->alias('m')->join('inviter i', 'i.inviter_id=m.member_id','LEFT')->field('i.*,m.inviter_id as inviter_parent_id,m.member_id,m.member_ww,m.member_qq,m.member_addtime,m.member_name,m.member_avatar,m.member_email,m.member_mobile,m.member_truename')->where('m.inviter_id IN'.$subQuery)->order('inviter_applytime desc')->paginate(['list_rows'=>10,'query' => request()->param()],false);
  369. $page_info=$res;
  370. $member_list=$res->items();
  371. }
  372. $inviterclass_model=model('inviterclass');
  373. foreach($member_list as $key => $item){
  374. $member_list[$key]['inviter_parent_name']='';
  375. $member_list[$key]['inviter_class']='';
  376. $member_list[$key]['inviter_class']=$inviterclass_model->getInviterclass(floatval($item['inviter_total_amount']));
  377. if($item['inviter_parent_id']){
  378. $member_list[$key]['inviter_parent_name'] = Db::name('member')->where('member_id='.$item['inviter_parent_id'])->value('member_name');
  379. }
  380. }
  381. View::assign('member_list',$member_list);
  382. View::assign('show_page', $page_info->render());
  383. echo View::fetch('memberlist');
  384. }
  385. /**
  386. * 获取卖家栏目列表,针对控制器下的栏目
  387. */
  388. protected function getAdminItemList() {
  389. $menu_array = array(
  390. array(
  391. 'name' => 'index',
  392. 'text' => lang('inviter_setting'),
  393. 'url' => (string)url('Inviter/setting')
  394. ),
  395. array(
  396. 'name' => 'goods',
  397. 'text' => lang('inviter_goods'),
  398. 'url' => (string)url('Inviter/goods')
  399. ),
  400. array(
  401. 'name' => 'member',
  402. 'text' => lang('inviter_member'),
  403. 'url' => (string)url('Inviter/member')
  404. ),
  405. array(
  406. 'name' => 'memberclass',
  407. 'text' => lang('inviter_memberclass'),
  408. 'url' => (string)url('Inviter/memberclass')
  409. ),
  410. array(
  411. 'name' => 'order',
  412. 'text' => lang('inviter_order'),
  413. 'url' => (string)url('Inviter/order')
  414. ),
  415. );
  416. return $menu_array;
  417. }
  418. }