MarketController.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 小夏 < 449134904@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. use think\db\Query;
  15. use app\admin\model\BooksModel;
  16. use app\weixin\model\Wechat;
  17. use app\weixin\model\AccountLog;
  18. use app\weixin\model\Member;
  19. use app\weixin\model\UserBalanceLog;
  20. use app\weixin\service\PRedis;
  21. /**
  22. * Class UserController
  23. * @package app\admin\controller
  24. * @adminMenuRoot(
  25. * 'name' => '管理组',
  26. * 'action' => 'default',
  27. * 'parent' => 'user/AdminIndex/default',
  28. * 'display'=> true,
  29. * 'order' => 10000,
  30. * 'icon' => '',
  31. * 'remark' => '管理组'
  32. * )
  33. */
  34. class MarketController extends AdminBaseController
  35. {
  36. /**
  37. * 分销设置界面
  38. */
  39. public function marketset(){
  40. //查询得到分销表
  41. $market=Db::name('market')->where('id',input('id'))->find();
  42. // $market=Db::name('market')->find();
  43. // var_dump($market);die();
  44. $this->assign('market', $market);
  45. return $this->fetch();
  46. }
  47. /**
  48. * 分销设置界面提交
  49. */
  50. public function marketsetpost(){
  51. //提交 param('level_1'),也可以相当于param['level_1'];
  52. $data=$this->request->param();
  53. $data['updated_at'] = date('Y-m-d H:i:s',time());
  54. if(Db::name('market')->where('id',$data['id'])->update($data)){
  55. $this->success('保存成功!',url('market/marketsetlist'));
  56. }else{
  57. $this->error('保存失败!');
  58. }
  59. }
  60. public function marketsetedit(){
  61. //提交 param('level_1'),也可以相当于param['level_1'];
  62. $data=$this->request->param();
  63. $data['updated_at'] = date('Y-m-d H:i:s',time());
  64. if(Db::name('market')->where('id',$data['id'])->update($data)){
  65. $this->success('保存成功!',url('market/marketsetlist'));
  66. }else{
  67. $this->error('保存失败!');
  68. }
  69. }
  70. //分销用户显示
  71. public function marketuser(){
  72. $data = $this->request->param();
  73. session('search',[
  74. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  75. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  76. ]);
  77. // 添加返回历史修改 by wesmiler 2020-02-16
  78. $history = isset($data['history'])? intval($data['history']) : 0;
  79. if($history){
  80. $data = session('user_search');
  81. }else{
  82. session('user_search', $data);
  83. }
  84. // 修改 end
  85. //var_dump($data);die;
  86. $list = Db::name('user')->field('u.id,u.user_login,u.user_nickname,u.real_name,u.redheart,u.is_tuijian,u.parent_id,u.create_time,u.is_heart,u.user_status,u.balance,u.mobile,u.level,u.freezing,u.updated_at,last_login_time,up.idcard,
  87. up.idcard_check,up.position_check,up.education_check')
  88. ->alias('u')
  89. ->join('user_profile up','u.id=up.userid','left')
  90. ->where(function (Query $query) use($data){
  91. $query->where('u.user_type', 2);
  92. $query->where('u.openid', 'not in','');
  93. $query->where('u.agent_type',1);
  94. //代表是否付费定制
  95. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  96. //代表是否冻结
  97. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  98. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  99. }
  100. //代表是否筛选
  101. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  102. //代表是否注销
  103. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  104. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  105. }
  106. //$data = $this->request->param();
  107. if (!empty($data['uid'])) {
  108. $query->where('u.id', intval($data['uid']));
  109. }
  110. if (!empty($data['keyword'])) {
  111. $keyword = $data['keyword'];
  112. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  113. }
  114. //年龄区间查询
  115. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  116. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  117. $query->whereNotNull('u.birthday');
  118. }
  119. // //只有第一个年龄的情况下
  120. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  121. $birthday = $data['age1'];
  122. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  123. }
  124. // //只有第二个年龄的情况下
  125. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  126. $birthday = $data['age2'];
  127. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  128. }
  129. //身高区间查询
  130. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  131. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  132. }
  133. //身高第一个查找
  134. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  135. $query->where('up.height',input('height'));
  136. }
  137. //身高第二个查找
  138. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  139. $query->where('up.height',input('heightt'));
  140. }
  141. //学历
  142. if((!empty(input('education')) && input('education')!='none') ){
  143. $query->where('up.education',input('education'));
  144. }
  145. //职位
  146. if((!empty(input('occupation')) && input('occupation')!='none') ){
  147. $query->where('up.occupation',input('occupation'));
  148. }
  149. //收入
  150. if((!empty(input('salary')) && input('salary')!='none') ){
  151. $query->where('up.salary',input('salary'));
  152. }
  153. //资产
  154. if((!empty(input('property')) && input('property')!='none') ){
  155. $query->where('up.property',input('property'));
  156. }
  157. //家乡
  158. if((!empty(input('home_city')) && input('home_city')!='none') ){
  159. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  160. }
  161. //居住地(市)
  162. if((!empty(input('city')) && input('city')!='none') ){
  163. $query->where('up.city','like','%'.input('city').'%');
  164. }
  165. //婚姻状况
  166. if((!empty(input('married')) && input('married')!='none') ){
  167. $query->where('up.married',input('married'));
  168. }
  169. //性别
  170. if((!empty(input('sex')) && input('sex')!='none') ){
  171. $query->where('u.sex',input('sex'));
  172. }
  173. })
  174. //待审核
  175. ->order("u.create_time DESC")
  176. ->paginate(10,false,['query'=>request()->param()])
  177. ->each(function($item,$key){
  178. $item['marketusername'] = Db::name('user')->where('id',$item['parent_id'])->field('real_name,user_nickname')->find();
  179. $item['marketcount'] = Db::name('user')->where(array('parent_id'=>$item['id'],'agent_type'=>1))->count('id');
  180. $item['marketusercount'] = Db::name('user')->where(array('parent_id' =>$item['id'],'agent_type'=>0))->count('id');
  181. return $item;
  182. })
  183. ;
  184. // echo Db::name('user')->getLastSql();die;
  185. // 获取分页显示
  186. $page = $list->render();
  187. $this->assign('list', $list);
  188. $this->assign('page', $page);
  189. return $this->fetch();
  190. }
  191. //分销员审核
  192. public function marketexamine(){
  193. $data = $this->request->param();
  194. session('search',[
  195. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  196. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  197. ]);
  198. // 添加返回历史修改 by wesmiler 2020-02-16
  199. $history = isset($data['history'])? intval($data['history']) : 0;
  200. if($history){
  201. $data = session('user_search');
  202. }else{
  203. session('user_search', $data);
  204. }
  205. // 修改 end
  206. //var_dump($data);die;
  207. $list = Db::name('user')->field('u.id,u.user_login,u.user_nickname,u.real_name,u.redheart,u.is_tuijian,u.create_time,u.is_heart,u.user_status,u.mobile,u.freezing,u.updated_at,u.agent_create_time,last_login_time,up.idcard,
  208. up.idcard_check,up.position_check,up.education_check')
  209. ->alias('u')
  210. ->join('user_profile up','u.id=up.userid','left')
  211. ->where(function (Query $query) use($data){
  212. $query->where('u.user_type', 2);
  213. $query->where('u.openid', 'not in','');
  214. $query->where('u.agent_type',1);
  215. $query->where('u.agent_status',2); //待审核
  216. //代表是否付费定制
  217. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  218. //代表是否冻结
  219. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  220. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  221. }
  222. //代表是否筛选
  223. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  224. //代表是否注销
  225. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  226. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  227. }
  228. //$data = $this->request->param();
  229. if (!empty($data['uid'])) {
  230. $query->where('u.id', intval($data['uid']));
  231. }
  232. if (!empty($data['keyword'])) {
  233. $keyword = $data['keyword'];
  234. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  235. }
  236. //年龄区间查询
  237. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  238. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  239. $query->whereNotNull('u.birthday');
  240. }
  241. // //只有第一个年龄的情况下
  242. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  243. $birthday = $data['age1'];
  244. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  245. }
  246. // //只有第二个年龄的情况下
  247. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  248. $birthday = $data['age2'];
  249. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  250. }
  251. //身高区间查询
  252. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  253. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  254. }
  255. //身高第一个查找
  256. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  257. $query->where('up.height',input('height'));
  258. }
  259. //身高第二个查找
  260. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  261. $query->where('up.height',input('heightt'));
  262. }
  263. //学历
  264. if((!empty(input('education')) && input('education')!='none') ){
  265. $query->where('up.education',input('education'));
  266. }
  267. //职位
  268. if((!empty(input('occupation')) && input('occupation')!='none') ){
  269. $query->where('up.occupation',input('occupation'));
  270. }
  271. //收入
  272. if((!empty(input('salary')) && input('salary')!='none') ){
  273. $query->where('up.salary',input('salary'));
  274. }
  275. //资产
  276. if((!empty(input('property')) && input('property')!='none') ){
  277. $query->where('up.property',input('property'));
  278. }
  279. //家乡
  280. if((!empty(input('home_city')) && input('home_city')!='none') ){
  281. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  282. }
  283. //居住地(市)
  284. if((!empty(input('city')) && input('city')!='none') ){
  285. $query->where('up.city','like','%'.input('city').'%');
  286. }
  287. //婚姻状况
  288. if((!empty(input('married')) && input('married')!='none') ){
  289. $query->where('up.married',input('married'));
  290. }
  291. //性别
  292. if((!empty(input('sex')) && input('sex')!='none') ){
  293. $query->where('u.sex',input('sex'));
  294. }
  295. })
  296. //待审核
  297. ->order("u.agent_create_time DESC")
  298. ->paginate(10,false,['query'=>request()->param()]);
  299. //echo Db::name('user')->getLastSql();die;
  300. // 获取分页显示
  301. $page = $list->render();
  302. $this->assign('list', $list);
  303. $this->assign('page', $page);
  304. return $this->fetch();
  305. }
  306. //分销一级用户显示
  307. public function Marketoneuser(){
  308. $data = $this->request->param();
  309. session('search',[
  310. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  311. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  312. ]);
  313. // 添加返回历史修改 by wesmiler 2020-02-16
  314. $history = isset($data['history'])? intval($data['history']) : 0;
  315. if($history){
  316. $data = session('user_search');
  317. }else{
  318. session('user_search', $data);
  319. }
  320. // 修改 end
  321. //var_dump($data);die;
  322. $list = Db::name('user')->field('u.id,u.user_login,u.user_nickname,u.real_name,u.redheart,u.is_tuijian,u.parent_id,u.create_time,u.is_heart,u.user_status,u.balance,u.mobile,u.level,u.freezing,u.updated_at,last_login_time,up.idcard,
  323. up.idcard_check,up.position_check,up.education_check')
  324. ->alias('u')
  325. ->join('user_profile up','u.id=up.userid','left')
  326. ->where(function (Query $query) use($data){
  327. $query->where('u.user_type', 2);
  328. // $query->where('u.agent_type', 1); //分销用户
  329. $query->where('u.openid', 'not in','');
  330. if($data['agent_type']==0){
  331. $query->where(array('u.parent_id' =>$data['id'],'u.agent_type'=>0));
  332. }
  333. if($data['agent_type']==1){
  334. $query->where(array('u.parent_id' =>$data['id'],'u.agent_type'=>1));
  335. }
  336. //代表是否付费定制
  337. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  338. //代表是否冻结
  339. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  340. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  341. }
  342. //代表是否筛选
  343. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  344. //代表是否注销
  345. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  346. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  347. }
  348. //$data = $this->request->param();
  349. if (!empty($data['uid'])) {
  350. $query->where('u.id', intval($data['uid']));
  351. }
  352. if (!empty($data['keyword'])) {
  353. $keyword = $data['keyword'];
  354. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  355. }
  356. //年龄区间查询
  357. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  358. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  359. $query->whereNotNull('u.birthday');
  360. }
  361. // //只有第一个年龄的情况下
  362. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  363. $birthday = $data['age1'];
  364. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  365. }
  366. // //只有第二个年龄的情况下
  367. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  368. $birthday = $data['age2'];
  369. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  370. }
  371. //身高区间查询
  372. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  373. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  374. }
  375. //身高第一个查找
  376. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  377. $query->where('up.height',input('height'));
  378. }
  379. //身高第二个查找
  380. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  381. $query->where('up.height',input('heightt'));
  382. }
  383. //学历
  384. if((!empty(input('education')) && input('education')!='none') ){
  385. $query->where('up.education',input('education'));
  386. }
  387. //职位
  388. if((!empty(input('occupation')) && input('occupation')!='none') ){
  389. $query->where('up.occupation',input('occupation'));
  390. }
  391. //收入
  392. if((!empty(input('salary')) && input('salary')!='none') ){
  393. $query->where('up.salary',input('salary'));
  394. }
  395. //资产
  396. if((!empty(input('property')) && input('property')!='none') ){
  397. $query->where('up.property',input('property'));
  398. }
  399. //家乡
  400. if((!empty(input('home_city')) && input('home_city')!='none') ){
  401. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  402. }
  403. //居住地(市)
  404. if((!empty(input('city')) && input('city')!='none') ){
  405. $query->where('up.city','like','%'.input('city').'%');
  406. }
  407. //婚姻状况
  408. if((!empty(input('married')) && input('married')!='none') ){
  409. $query->where('up.married',input('married'));
  410. }
  411. //性别
  412. if((!empty(input('sex')) && input('sex')!='none') ){
  413. $query->where('u.sex',input('sex'));
  414. }
  415. })
  416. //待审核
  417. ->order("u.create_time DESC")
  418. ->paginate(10,false,['query'=>request()->param()])
  419. ->each(function($item,$key){
  420. $item['marketusername'] = Db::name('user')->where('id',$item['parent_id'])->field('real_name,user_nickname')->find();
  421. $item['marketcount'] = Db::name('user')->where('parent_id',$item['id'])->count('id');
  422. $item['marketusercount'] = Db::name('user')->where(array('parent_id'=>$item['id'],'agent_type'=>0))->count('id');//普通用户会员,不是分销员
  423. return $item;
  424. })
  425. ;
  426. //echo Db::name('user')->getLastSql();die;
  427. // 获取分页显示
  428. $page = $list->render();
  429. $this->assign('list', $list);
  430. $this->assign('page', $page);
  431. return $this->fetch();
  432. }
  433. //显示子级用户显示
  434. public function Markettwouser(){
  435. $data = $this->request->param();
  436. session('search',[
  437. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  438. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  439. ]);
  440. // 添加返回历史修改 by wesmiler 2020-02-16
  441. $history = isset($data['history'])? intval($data['history']) : 0;
  442. if($history){
  443. $data = session('user_search');
  444. }else{
  445. session('user_search', $data);
  446. }
  447. // 修改 end
  448. //var_dump($data);die;
  449. $list = Db::name('user')->field('u.id,u.user_login,u.user_nickname,u.real_name,u.redheart,u.is_tuijian,u.create_time,u.is_heart,u.user_status,u.mobile,u.freezing,u.updated_at,last_login_time,up.idcard,
  450. up.idcard_check,up.position_check,up.education_check')
  451. ->alias('u')
  452. ->join('user_profile up','u.id=up.userid','left')
  453. ->where(function (Query $query) use($data){
  454. $query->where('u.user_type', 2);
  455. $query->where('u.openid', 'not in','');
  456. $query->where('u.agent_type',1);
  457. //代表是否付费定制
  458. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  459. //代表是否冻结
  460. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  461. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  462. }
  463. //代表是否筛选
  464. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  465. //代表是否注销
  466. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  467. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  468. }
  469. //$data = $this->request->param();
  470. if (!empty($data['uid'])) {
  471. $query->where('u.id', intval($data['uid']));
  472. }
  473. if (!empty($data['keyword'])) {
  474. $keyword = $data['keyword'];
  475. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  476. }
  477. //年龄区间查询
  478. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  479. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  480. $query->whereNotNull('u.birthday');
  481. }
  482. // //只有第一个年龄的情况下
  483. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  484. $birthday = $data['age1'];
  485. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  486. }
  487. // //只有第二个年龄的情况下
  488. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  489. $birthday = $data['age2'];
  490. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  491. }
  492. //身高区间查询
  493. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  494. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  495. }
  496. //身高第一个查找
  497. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  498. $query->where('up.height',input('height'));
  499. }
  500. //身高第二个查找
  501. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  502. $query->where('up.height',input('heightt'));
  503. }
  504. //学历
  505. if((!empty(input('education')) && input('education')!='none') ){
  506. $query->where('up.education',input('education'));
  507. }
  508. //职位
  509. if((!empty(input('occupation')) && input('occupation')!='none') ){
  510. $query->where('up.occupation',input('occupation'));
  511. }
  512. //收入
  513. if((!empty(input('salary')) && input('salary')!='none') ){
  514. $query->where('up.salary',input('salary'));
  515. }
  516. //资产
  517. if((!empty(input('property')) && input('property')!='none') ){
  518. $query->where('up.property',input('property'));
  519. }
  520. //家乡
  521. if((!empty(input('home_city')) && input('home_city')!='none') ){
  522. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  523. }
  524. //居住地(市)
  525. if((!empty(input('city')) && input('city')!='none') ){
  526. $query->where('up.city','like','%'.input('city').'%');
  527. }
  528. //婚姻状况
  529. if((!empty(input('married')) && input('married')!='none') ){
  530. $query->where('up.married',input('married'));
  531. }
  532. //性别
  533. if((!empty(input('sex')) && input('sex')!='none') ){
  534. $query->where('u.sex',input('sex'));
  535. }
  536. })
  537. //待审核
  538. ->order("u.create_time DESC")
  539. ->paginate(10,false,['query'=>request()->param()]);
  540. // echo Db::name('user')->getLastSql();die;
  541. // 获取分页显示
  542. $page = $list->render();
  543. $this->assign('list', $list);
  544. $this->assign('page', $page);
  545. return $this->fetch();
  546. }
  547. /**
  548. * 审核通过和审核不通过的弹框
  549. */
  550. public function goconfrom(){
  551. $this->assign("id",input('id'));
  552. return $this->fetch('marketconfrom');
  553. }
  554. /**
  555. * 审核通过和审核不通过的弹框操作
  556. */
  557. public function doconfrom(){
  558. $param= $this->request->param();
  559. if(isset($param['yes']) && isset($param['id'])){
  560. //开始进行调用成功发送
  561. $data['agent_status'] = 1; //已审核
  562. $data['agent_type'] = 1; //分销用户
  563. $result=Db::name('user')->where('id',$param['id'])->update($data);
  564. // echo Db::name('user')->getLastSql();die();
  565. //通过id来获得用户的openid
  566. $userinfo=Db::name('user')->where('id',$param['id'])->find();
  567. if($result){
  568. //发送模板
  569. $openid = isset($userinfo['openid'])? $userinfo['openid'] : '';
  570. if($openid){
  571. $checkTime = date('Y.m.d H:i');
  572. $remark = "感谢您对拾光的信任,我们一起解救单身青年!点击查看分销中心";
  573. $msgParams = [
  574. 'title' => "恭喜!!您的推广红娘账号已审核通过!",
  575. 'remark' => $remark,
  576. 'type' => 'confirm',
  577. 'keywords' => [
  578. 'keyword1' => [
  579. 'value' =>'推广红娘',
  580. 'color' => '#173177',
  581. ],
  582. 'keyword2' => [
  583. 'value' => '审核通过',
  584. 'color' => '#3FAD46',
  585. ],
  586. ],
  587. 'url' => url('/weixin/market/index', '', '', true),
  588. ];
  589. Wechat::sendTplMsg($openid, $msgParams);
  590. }
  591. echo 1;die;
  592. }else{
  593. echo 0;die;
  594. }
  595. }
  596. if(isset($param['no']) && isset($param['id'])){
  597. //开始进行调用成功发送
  598. $data['agent_status'] = 3; //审核未通过
  599. $data['agent_type'] = 0; //分销用户无
  600. $result=Db::name('user')->where('id',$param['id'])->update($data);
  601. // echo Db::name('user')->getLastSql();die();
  602. //通过id来获得用户的openid
  603. $userinfo=Db::name('user')->where('id',$param['id'])->find();
  604. if($result){
  605. //发送模板
  606. $openid = isset($userinfo['openid'])? $userinfo['openid'] : '';
  607. if($openid){
  608. $checkTime = date('Y.m.d H:i');
  609. $remark = $param['noremark'];
  610. $msgParams = [
  611. 'title' => "您的推广红娘账号不通过审核!",
  612. 'remark' => $remark,
  613. 'type' => 'confirm',
  614. 'keywords' => [
  615. 'keyword1' => [
  616. 'value' => '推广红娘',
  617. 'color' => '#173177',
  618. ],
  619. 'keyword2' => [
  620. 'value' => '审核不通过',
  621. 'color' => '#c9302c',
  622. ],
  623. ],
  624. 'url' => url('', '', '', true),
  625. ];
  626. Wechat::sendTplMsg($openid, $msgParams);
  627. }
  628. echo 1;die;
  629. }else{
  630. echo 0;die;
  631. }
  632. }
  633. }
  634. /**
  635. * 分销员奖励交易记录表
  636. */
  637. public function markettrans(){
  638. //
  639. /**搜索条件**/
  640. $trans_name = $this->request->param('user_nickname');
  641. $money = $this->request->param('money');
  642. //$userEmail = trim($this->request->param('user_email'));
  643. //账户明细表(包含用户名称,爱心,余额)
  644. $account_logs = Db::name('user_balance_log')
  645. ->alias('blog')
  646. ->join('user u','blog.user_id=u.id','left')
  647. ->where('blog.type','neq',1)
  648. ->where(function (Query $query) use ($trans_name,$money) {
  649. if ($trans_name) {
  650. $query->where('u.user_nickname', 'like', "%$trans_name%");
  651. }
  652. if ($money) {
  653. $query->where('blog.balance', $money);
  654. }
  655. })
  656. ->field('blog.*,u.user_nickname')
  657. ->order("blog.id DESC")
  658. ->paginate(10,false,['query'=>request()->param()])
  659. ->each(function($item,$key){
  660. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('user_nickname')->find();
  661. return $item;
  662. })
  663. ;
  664. //echo Db::name('user_balance_log')->getLastSql();die();
  665. $account_logs->appends(['title' => $trans_name]);
  666. // 获取分页显示
  667. $page = $account_logs->render();
  668. $this->assign("page", $page);
  669. $this->assign("account_logs", $account_logs);
  670. return $this->fetch();
  671. }
  672. /**
  673. * 分销奖励和扣除查看详情
  674. */
  675. public function transinfo(){
  676. $id=input('id');
  677. $balance_log = Db::name('user_balance_log')
  678. ->alias('blog')
  679. ->join('user u','blog.user_id=u.id','left')
  680. ->where(function (Query $query) use ($id) {
  681. if ($id) {
  682. $query->where('blog.id', $id);
  683. }
  684. })
  685. ->field('blog.*,u.user_nickname,u.real_name')
  686. ->find();
  687. $this->assign($balance_log);
  688. return $this->fetch();
  689. }
  690. /**
  691. * 分销记录
  692. */
  693. public function marketrecord(){
  694. // echo Db::name('user')->getLastSql().var_dump( $result);die();
  695. /**搜索条件**/
  696. $trans_name = $this->request->param('user_nickname');
  697. $money = $this->request->param('money');
  698. //$userEmail = trim($this->request->param('user_email'));
  699. //账户明细表(包含用户名称,爱心,余额)
  700. $balance_logs = Db::name('user_balance_log')
  701. ->alias('blog')
  702. ->join('user u','blog.user_id=u.id','left')
  703. ->whereIn('blog.type',[31,32])
  704. ->where(function (Query $query) use ($trans_name,$money) {
  705. if ($trans_name) {
  706. $query->where('u.user_nickname', 'like', "%$trans_name%");
  707. }
  708. if ($money) {
  709. $query->where('blog.balance', $money);
  710. }
  711. })
  712. ->field('blog.*,u.user_nickname')
  713. ->order("blog.id DESC")
  714. ->paginate(10,false,['query'=>request()->param()])
  715. ->each(function($item,$key){
  716. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('user_nickname')->find();
  717. return $item;
  718. })
  719. ;
  720. //echo Db::name('user_balance_log')->getLastSql();die();
  721. $balance_logs->appends(['title' => $trans_name]);
  722. // 获取分页显示
  723. $page = $balance_logs->render();
  724. // var_dump($balance_logs);die();
  725. $this->assign("page", $page);
  726. $this->assign("balance_logs", $balance_logs);
  727. return $this->fetch();
  728. }
  729. //假删除用户
  730. public function todelete(){
  731. $param = $this->request->param();
  732. if (isset($param['ids']) && isset($param["yes"])) {
  733. $ids = $this->request->param('ids/a');
  734. Db::name('user')->where('id', 'in', $ids)->update(['agent_type' => 0,'agent_status' =>2]); //无,和待审核
  735. $this->success("删除成功!");
  736. }
  737. if (isset($_POST['ids']) && isset($param["no"])) {
  738. $ids = $this->request->param('ids/a');
  739. Db::name('user')->where('id', 'in', $ids)->update(['agent_type' => 1]);
  740. $this->success("取消删除成功!", '/market/marketexamine');
  741. }
  742. }
  743. /**
  744. * 显示奖励充值
  745. */
  746. public function marketshowreward(){
  747. $this->assign("id",input('id'));
  748. return $this->fetch();
  749. }
  750. /**
  751. * 进行奖励充值
  752. */
  753. public function markettoreward(){
  754. $this->assign("id",input('id'));
  755. $where = ['id' => input('id'), 'agent_type' => 1, 'agent_status' => 1];
  756. $result=Db::name('user')->where($where)->find();
  757. if ($result) {
  758. $awardMoney=$result['balance']+input('am');
  759. // 账户变动
  760. Db::startTrans();
  761. if (Member::where($where)->setInc('balance', input('am'))) {
  762. // 写入分销奖励日志
  763. $logTitle = "你获得了".input('ar')."奖励,额度".input('am')."元";
  764. $log = [
  765. 'change' => input('am'),
  766. 'type' => 31,
  767. 'level' => 1, //默认是1级
  768. 'change_type' => 1, //收入相对于客户。
  769. 'pay_money' => input('am'),
  770. 'user_id' => input('id'),
  771. 'source_uid' => 0,
  772. 'balance' => $awardMoney,
  773. 'description' => input('ar'),
  774. 'create_time' => time(),
  775. 'status' => 1,
  776. ];
  777. $logData['log'] = $log;
  778. //PRedis::set("{$cacheKey}:log", $logData, 7200);
  779. if(UserBalanceLog::insertGetId($log)){
  780. // 账户明细
  781. $accountData = [
  782. 'type' => 4,
  783. 'account_type' => 2,
  784. 'change_type' =>2,
  785. 'user_id' => input('id'),
  786. 'money' => input('am'),
  787. 'balance' => $awardMoney,
  788. 'created_at' => date('Y-m-d H:i:s'),
  789. 'remark' => input('ar'),
  790. ];
  791. if(AccountLog::insertGetId($accountData)){
  792. // 发送模板消息
  793. $openid = isset($result['openid'])? $result['openid'] : '';
  794. if($openid){
  795. $checkTime = date('Y.m.d H:i:s',time());
  796. $remark = input('ar');
  797. $msgParams = [
  798. 'title' => "您好,您有一笔奖励结算金额已入账",
  799. 'remark' => $remark,
  800. 'type' => 'income',
  801. 'keywords' => [
  802. 'keyword1' => [
  803. 'value' => '¥'.input('am'),
  804. 'color' => '#173177',
  805. ],
  806. 'keyword2' => [
  807. 'value' => $checkTime,
  808. 'color' => '#173177',
  809. ],
  810. ],
  811. 'url' => url('/weixin/market/income', '', '', true),
  812. ];
  813. // PRedis::set("{$cacheKey}:message", ['result' => $userInfoTwo, 'params' => $msgParams], 600);
  814. Wechat::sendTplMsg($openid, $msgParams);
  815. }
  816. Db::commit();
  817. }else{
  818. // PRedis::set("{$cacheKey}:account_log", $logData, 7200);
  819. Db::rollback();
  820. echo 0;die();
  821. }
  822. }else{
  823. //PRedis::set("{$cacheKey}:balance_log", $logData, 7200);
  824. Db::rollback();
  825. echo 0;die();
  826. }
  827. } else {
  828. // PRedis::set("{$cacheKey}:update_balance", $logData, 7200);
  829. Db::rollback();
  830. echo 0;die();
  831. }
  832. } else {
  833. // PRedis::set("{$cacheKey}:error_awardMoney", $logData, 7200);
  834. echo 0;die();
  835. }
  836. echo 1;die();
  837. }
  838. //提现审核
  839. public function withdraw(){
  840. $data = $this->request->param();
  841. session('search',[
  842. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  843. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  844. ]);
  845. // 添加返回历史修改 by wesmiler 2020-02-16
  846. $history = isset($data['history'])? intval($data['history']) : 0;
  847. if($history){
  848. $data = session('user_search');
  849. }else{
  850. session('user_search', $data);
  851. }
  852. // 修改 end
  853. //var_dump($data);die;
  854. $list = Db::name('user_balance_log')
  855. ->alias('ub')
  856. ->join('user u','u.id = ub.user_id','left')
  857. ->where(function (Query $query) use($data){
  858. $query->where('ub.type', 1);
  859. $query->where('ub.status',1); //待审核
  860. })
  861. ->field('ub.*,u.user_nickname,u.real_name')
  862. //待审核
  863. ->order("ub.create_time DESC")
  864. ->paginate(10,false,['query'=>request()->param()])
  865. ->each(function($item,$key){
  866. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('real_name,user_nickname')->find();
  867. return $item;
  868. })
  869. ;
  870. //echo Db::name('user')->getLastSql();die;
  871. // 获取分页显示
  872. $page = $list->render();
  873. $this->assign('list', $list);
  874. $this->assign('page', $page);
  875. //var_dump($list);die();
  876. return $this->fetch("marketwithdraw");
  877. }
  878. //提现审核确认显示
  879. public function godrawconfrom(){
  880. $this->assign('id',input('id'));
  881. $this->assign('balance',input('balance'));
  882. return $this->fetch("marketdrawconfrom");
  883. }
  884. //进行提交审核提现。
  885. public function dodrawconfrom(){
  886. $param= $this->request->param();
  887. if(isset($param['yes']) && isset($param['id'])){
  888. //
  889. //通过userid来得到openid
  890. $result=Db::name('user_balance_log')
  891. ->alias('ub')
  892. ->join('user u','ub.user_id=u.id','left')
  893. ->where(['ub.id'=>$param['id']])
  894. ->field('ub.order_sn,ub.description,ub.user_id,ub.pay_money,ub.change,u.openid,ub.create_time')
  895. ->find();
  896. if (empty($result['openid'])) {
  897. echo 0;die;
  898. }
  899. $pay_moneys=($param['pay_money']!='')?$param['pay_money']:$result['pay_money'];
  900. //开始进行调用成功发送
  901. $order = array(
  902. 'orderNo' => $result['order_sn'], //订单号
  903. 'openid' => $result['openid'],
  904. 'amount' => $pay_moneys, //实际支付金额
  905. 'desc' =>$result['description'], //描述
  906. );
  907. //var_dump($order);die();
  908. $resulttrans=wechat::transferOrder($order); //进行调用发送企业到零钱打款模板信息
  909. //var_dump($resulttrans);die();
  910. if($resulttrans['result_code']=="SUCCESS"){
  911. // 增加账户明细
  912. $accountData = [
  913. 'type' => 8, //提现
  914. 'account_type' => 2, //余额类型
  915. 'change_type' => 1, //收入
  916. 'user_id' => $param['id'],
  917. 'money' => ($param['pay_money']!='')?$param['pay_money']:$result['pay_money'],
  918. 'balance' => $param['balance'],
  919. 'created_at' => date('Y-m-d H:i:s'),
  920. 'remark' => '客户进行提现',
  921. ];
  922. Db::startTrans();
  923. if(AccountLog::insertGetId($accountData)){
  924. //进行,变更审核成功。
  925. $data0['status'] = 2;
  926. $result0=Db::name('user_balance_log')->where('id',$param['id'])->update($data0);
  927. if($result0){
  928. //发送模板消息
  929. if($result['openid']){
  930. $checkTime = date('Y-m-d H:i:s',$result['create_time']);
  931. $giveTime = date('Y-m-d H:i:s',time());
  932. $remark = "您的提现已到账,请查收!";
  933. $msgParams=[
  934. 'title'=>$remark,
  935. 'remark'=>$remark,
  936. 'type' =>'withdraw',
  937. 'keywords' =>[
  938. 'keyword1'=>[
  939. 'value'=> ($param['pay_money']!='')?$param['pay_money']:$result['pay_money'],
  940. 'color'=>'#173177'
  941. ],
  942. 'keyword2'=>[
  943. 'value'=>$checkTime,
  944. 'color'=>'#173177'
  945. ],
  946. 'keyword3'=>[
  947. 'value'=>'商家转账入账',
  948. 'color'=>'#173177'
  949. ],
  950. 'keyword4'=>[
  951. 'value'=>$giveTime,
  952. 'color'=>'#173177'
  953. ],
  954. 'keyword5'=>[
  955. 'value'=>$result['order_sn'],
  956. 'color'=>'#173177',
  957. ]
  958. ],
  959. 'url' =>url('/weixin/Account/withdraw','','',true),
  960. ];
  961. wechat::sendTplMsg($result['openid'],$msgParams);
  962. }
  963. Db::commit();
  964. echo 1;die;
  965. }else{
  966. Db::rollback();
  967. echo 0;die;
  968. }
  969. }else{
  970. Db::rollback();
  971. echo 0;die();
  972. }
  973. }else{
  974. echo 0;die;
  975. }
  976. }
  977. if(isset($param['no']) && isset($param['id'])){
  978. //开始进行调用审核失败发送
  979. Db::startTrans();
  980. $data0['status'] = 2;
  981. $result0=Db::name('user_balance_log')->where('id',$param['id'])->update($data0);
  982. // $result=Activity::bookConfirm($param['id'],5,$param['noremark']);
  983. if(is_array($result)){
  984. Db::commit();
  985. echo 1;die;
  986. }else{
  987. //进行反扣回去
  988. $data0['balance'] +=$result['change'];
  989. Db::name('user_balance_log')->where('id',$param['id'])->update($data0);
  990. Db::name('user')->where('id',$result['user_id'])->update($data0);
  991. Db::rollback();
  992. echo 0;die;
  993. }
  994. }
  995. }
  996. //进行提交显示出团队人数。
  997. public function showteam(){
  998. return $this->fetch('marketoneuser');
  999. }
  1000. //分销提现记录
  1001. public function withdrawrecord(){
  1002. $data = $this->request->param();
  1003. session('search',[
  1004. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  1005. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  1006. ]);
  1007. // 添加返回历史修改 by wesmiler 2020-02-16
  1008. $history = isset($data['history'])? intval($data['history']) : 0;
  1009. if($history){
  1010. $data = session('user_search');
  1011. }else{
  1012. session('user_search', $data);
  1013. }
  1014. // 修改 end
  1015. //var_dump($data);die;
  1016. $list = Db::name('user_balance_log')
  1017. ->alias('ub')
  1018. ->join('user u','u.id = ub.user_id','left')
  1019. ->where(function (Query $query) use($data){
  1020. $query->where('ub.type', 1);
  1021. $query->where('ub.status','neq',1); //已审核
  1022. })
  1023. ->field('ub.*,u.user_nickname,u.real_name')
  1024. //待审核
  1025. ->order("ub.create_time DESC")
  1026. ->paginate(10,false,['query'=>request()->param()])
  1027. ->each(function($item,$key){
  1028. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('real_name,user_nickname')->find();
  1029. return $item;
  1030. })
  1031. ;
  1032. //echo Db::name('user')->getLastSql();die;
  1033. // 获取分页显示
  1034. $page = $list->render();
  1035. $this->assign('list', $list);
  1036. $this->assign('page', $page);
  1037. return $this->fetch('marketwithdrawrecord');
  1038. }
  1039. //分销列表显示
  1040. public function marketsetlist(){
  1041. $list=Db::name('market')->paginate(10,false,['query'=>request()->param()]);
  1042. $page = $list->render();
  1043. $this->assign('list',$list);
  1044. $this->assign('page',$page);
  1045. return $this->fetch();
  1046. }
  1047. }