Inviter.php 22 KB

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