MarketController.php 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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\service\PRedis;
  18. /**
  19. * Class UserController
  20. * @package app\admin\controller
  21. * @adminMenuRoot(
  22. * 'name' => '管理组',
  23. * 'action' => 'default',
  24. * 'parent' => 'user/AdminIndex/default',
  25. * 'display'=> true,
  26. * 'order' => 10000,
  27. * 'icon' => '',
  28. * 'remark' => '管理组'
  29. * )
  30. */
  31. class MarketController extends AdminBaseController
  32. {
  33. /**
  34. * 分销设置界面
  35. */
  36. public function marketset(){
  37. //查询得到分销表
  38. $market=Db::name('market')->where('id',1)->find();
  39. // var_dump($market);die();
  40. $this->assign('market', $market);
  41. return $this->fetch();
  42. }
  43. /**
  44. * 分销设置界面提交
  45. */
  46. public function marketsetpost(){
  47. //提交 param('level_1'),也可以相当于param['level_1'];
  48. $data=$this->request->param();
  49. $data['updated_at'] = date('Y-m-d H:i:s',time());
  50. if(Db::name('market')->where('id',1)->update($data)){
  51. $this->success('保存成功!');
  52. }else{
  53. $this->error('保存失败!');
  54. }
  55. }
  56. //分销用户显示
  57. public function marketuser(){
  58. $data = $this->request->param();
  59. session('search',[
  60. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  61. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  62. ]);
  63. // 添加返回历史修改 by wesmiler 2020-02-16
  64. $history = isset($data['history'])? intval($data['history']) : 0;
  65. if($history){
  66. $data = session('user_search');
  67. }else{
  68. session('user_search', $data);
  69. }
  70. // 修改 end
  71. //var_dump($data);die;
  72. $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,
  73. up.idcard_check,up.position_check,up.education_check')
  74. ->alias('u')
  75. ->join('user_profile up','u.id=up.userid','left')
  76. ->where(function (Query $query) use($data){
  77. $query->where('u.user_type', 2);
  78. $query->where('u.openid', 'not in','');
  79. $query->where('u.agent_type',1);
  80. //代表是否付费定制
  81. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  82. //代表是否冻结
  83. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  84. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  85. }
  86. //代表是否筛选
  87. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  88. //代表是否注销
  89. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  90. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  91. }
  92. //$data = $this->request->param();
  93. if (!empty($data['uid'])) {
  94. $query->where('u.id', intval($data['uid']));
  95. }
  96. if (!empty($data['keyword'])) {
  97. $keyword = $data['keyword'];
  98. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  99. }
  100. //年龄区间查询
  101. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  102. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  103. $query->whereNotNull('u.birthday');
  104. }
  105. // //只有第一个年龄的情况下
  106. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  107. $birthday = $data['age1'];
  108. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  109. }
  110. // //只有第二个年龄的情况下
  111. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  112. $birthday = $data['age2'];
  113. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  114. }
  115. //身高区间查询
  116. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  117. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  118. }
  119. //身高第一个查找
  120. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  121. $query->where('up.height',input('height'));
  122. }
  123. //身高第二个查找
  124. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  125. $query->where('up.height',input('heightt'));
  126. }
  127. //学历
  128. if((!empty(input('education')) && input('education')!='none') ){
  129. $query->where('up.education',input('education'));
  130. }
  131. //职位
  132. if((!empty(input('occupation')) && input('occupation')!='none') ){
  133. $query->where('up.occupation',input('occupation'));
  134. }
  135. //收入
  136. if((!empty(input('salary')) && input('salary')!='none') ){
  137. $query->where('up.salary',input('salary'));
  138. }
  139. //资产
  140. if((!empty(input('property')) && input('property')!='none') ){
  141. $query->where('up.property',input('property'));
  142. }
  143. //家乡
  144. if((!empty(input('home_city')) && input('home_city')!='none') ){
  145. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  146. }
  147. //居住地(市)
  148. if((!empty(input('city')) && input('city')!='none') ){
  149. $query->where('up.city','like','%'.input('city').'%');
  150. }
  151. //婚姻状况
  152. if((!empty(input('married')) && input('married')!='none') ){
  153. $query->where('up.married',input('married'));
  154. }
  155. //性别
  156. if((!empty(input('sex')) && input('sex')!='none') ){
  157. $query->where('u.sex',input('sex'));
  158. }
  159. })
  160. //待审核
  161. ->order("u.create_time DESC")
  162. ->paginate(10,false,['query'=>request()->param()])
  163. ->each(function($item,$key){
  164. $item['marketusername'] = Db::name('user')->where('id',$item['parent_id'])->field('real_name,user_nickname')->find();
  165. $item['marketcount'] = Db::name('user')->where('parent_id',$item['id'])->count('id');
  166. return $item;
  167. })
  168. ;
  169. // echo Db::name('user')->getLastSql();die;
  170. // 获取分页显示
  171. $page = $list->render();
  172. $this->assign('list', $list);
  173. $this->assign('page', $page);
  174. return $this->fetch();
  175. }
  176. //分销员审核
  177. public function marketexamine(){
  178. $data = $this->request->param();
  179. session('search',[
  180. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  181. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  182. ]);
  183. // 添加返回历史修改 by wesmiler 2020-02-16
  184. $history = isset($data['history'])? intval($data['history']) : 0;
  185. if($history){
  186. $data = session('user_search');
  187. }else{
  188. session('user_search', $data);
  189. }
  190. // 修改 end
  191. //var_dump($data);die;
  192. $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,
  193. up.idcard_check,up.position_check,up.education_check')
  194. ->alias('u')
  195. ->join('user_profile up','u.id=up.userid','left')
  196. ->where(function (Query $query) use($data){
  197. $query->where('u.user_type', 2);
  198. $query->where('u.openid', 'not in','');
  199. $query->where('u.agent_status',2); //待审核
  200. //代表是否付费定制
  201. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  202. //代表是否冻结
  203. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  204. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  205. }
  206. //代表是否筛选
  207. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  208. //代表是否注销
  209. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  210. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  211. }
  212. //$data = $this->request->param();
  213. if (!empty($data['uid'])) {
  214. $query->where('u.id', intval($data['uid']));
  215. }
  216. if (!empty($data['keyword'])) {
  217. $keyword = $data['keyword'];
  218. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  219. }
  220. //年龄区间查询
  221. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  222. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  223. $query->whereNotNull('u.birthday');
  224. }
  225. // //只有第一个年龄的情况下
  226. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  227. $birthday = $data['age1'];
  228. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  229. }
  230. // //只有第二个年龄的情况下
  231. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  232. $birthday = $data['age2'];
  233. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  234. }
  235. //身高区间查询
  236. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  237. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  238. }
  239. //身高第一个查找
  240. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  241. $query->where('up.height',input('height'));
  242. }
  243. //身高第二个查找
  244. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  245. $query->where('up.height',input('heightt'));
  246. }
  247. //学历
  248. if((!empty(input('education')) && input('education')!='none') ){
  249. $query->where('up.education',input('education'));
  250. }
  251. //职位
  252. if((!empty(input('occupation')) && input('occupation')!='none') ){
  253. $query->where('up.occupation',input('occupation'));
  254. }
  255. //收入
  256. if((!empty(input('salary')) && input('salary')!='none') ){
  257. $query->where('up.salary',input('salary'));
  258. }
  259. //资产
  260. if((!empty(input('property')) && input('property')!='none') ){
  261. $query->where('up.property',input('property'));
  262. }
  263. //家乡
  264. if((!empty(input('home_city')) && input('home_city')!='none') ){
  265. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  266. }
  267. //居住地(市)
  268. if((!empty(input('city')) && input('city')!='none') ){
  269. $query->where('up.city','like','%'.input('city').'%');
  270. }
  271. //婚姻状况
  272. if((!empty(input('married')) && input('married')!='none') ){
  273. $query->where('up.married',input('married'));
  274. }
  275. //性别
  276. if((!empty(input('sex')) && input('sex')!='none') ){
  277. $query->where('u.sex',input('sex'));
  278. }
  279. })
  280. //待审核
  281. ->order("u.agent_create_time DESC")
  282. ->paginate(10,false,['query'=>request()->param()]);
  283. //echo Db::name('user')->getLastSql();die;
  284. // 获取分页显示
  285. $page = $list->render();
  286. $this->assign('list', $list);
  287. $this->assign('page', $page);
  288. return $this->fetch();
  289. }
  290. //分销一级用户显示
  291. public function Marketoneuser(){
  292. $data = $this->request->param();
  293. session('search',[
  294. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  295. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  296. ]);
  297. // 添加返回历史修改 by wesmiler 2020-02-16
  298. $history = isset($data['history'])? intval($data['history']) : 0;
  299. if($history){
  300. $data = session('user_search');
  301. }else{
  302. session('user_search', $data);
  303. }
  304. // 修改 end
  305. //var_dump($data);die;
  306. $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,
  307. up.idcard_check,up.position_check,up.education_check')
  308. ->alias('u')
  309. ->join('user_profile up','u.id=up.userid','left')
  310. ->where(function (Query $query) use($data){
  311. $query->where('u.user_type', 2);
  312. $query->where('u.openid', 'not in','');
  313. $query->where('u.parent_id',$data['id']);
  314. //代表是否付费定制
  315. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  316. //代表是否冻结
  317. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  318. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  319. }
  320. //代表是否筛选
  321. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  322. //代表是否注销
  323. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  324. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  325. }
  326. //$data = $this->request->param();
  327. if (!empty($data['uid'])) {
  328. $query->where('u.id', intval($data['uid']));
  329. }
  330. if (!empty($data['keyword'])) {
  331. $keyword = $data['keyword'];
  332. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  333. }
  334. //年龄区间查询
  335. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  336. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  337. $query->whereNotNull('u.birthday');
  338. }
  339. // //只有第一个年龄的情况下
  340. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  341. $birthday = $data['age1'];
  342. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  343. }
  344. // //只有第二个年龄的情况下
  345. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  346. $birthday = $data['age2'];
  347. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  348. }
  349. //身高区间查询
  350. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  351. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  352. }
  353. //身高第一个查找
  354. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  355. $query->where('up.height',input('height'));
  356. }
  357. //身高第二个查找
  358. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  359. $query->where('up.height',input('heightt'));
  360. }
  361. //学历
  362. if((!empty(input('education')) && input('education')!='none') ){
  363. $query->where('up.education',input('education'));
  364. }
  365. //职位
  366. if((!empty(input('occupation')) && input('occupation')!='none') ){
  367. $query->where('up.occupation',input('occupation'));
  368. }
  369. //收入
  370. if((!empty(input('salary')) && input('salary')!='none') ){
  371. $query->where('up.salary',input('salary'));
  372. }
  373. //资产
  374. if((!empty(input('property')) && input('property')!='none') ){
  375. $query->where('up.property',input('property'));
  376. }
  377. //家乡
  378. if((!empty(input('home_city')) && input('home_city')!='none') ){
  379. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  380. }
  381. //居住地(市)
  382. if((!empty(input('city')) && input('city')!='none') ){
  383. $query->where('up.city','like','%'.input('city').'%');
  384. }
  385. //婚姻状况
  386. if((!empty(input('married')) && input('married')!='none') ){
  387. $query->where('up.married',input('married'));
  388. }
  389. //性别
  390. if((!empty(input('sex')) && input('sex')!='none') ){
  391. $query->where('u.sex',input('sex'));
  392. }
  393. })
  394. //待审核
  395. ->order("u.create_time DESC")
  396. ->paginate(10,false,['query'=>request()->param()])
  397. ->each(function($item,$key){
  398. $item['marketusername'] = Db::name('user')->where('id',$item['parent_id'])->field('real_name,user_nickname')->find();
  399. $item['marketcount'] = Db::name('user')->where('parent_id',$item['id'])->count('id');
  400. return $item;
  401. })
  402. ;
  403. // echo Db::name('user')->getLastSql();die;
  404. // 获取分页显示
  405. $page = $list->render();
  406. $this->assign('list', $list);
  407. $this->assign('page', $page);
  408. return $this->fetch();
  409. }
  410. //显示子级用户显示
  411. public function Markettwouser(){
  412. $data = $this->request->param();
  413. session('search',[
  414. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  415. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  416. ]);
  417. // 添加返回历史修改 by wesmiler 2020-02-16
  418. $history = isset($data['history'])? intval($data['history']) : 0;
  419. if($history){
  420. $data = session('user_search');
  421. }else{
  422. session('user_search', $data);
  423. }
  424. // 修改 end
  425. //var_dump($data);die;
  426. $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,
  427. up.idcard_check,up.position_check,up.education_check')
  428. ->alias('u')
  429. ->join('user_profile up','u.id=up.userid','left')
  430. ->where(function (Query $query) use($data){
  431. $query->where('u.user_type', 2);
  432. $query->where('u.openid', 'not in','');
  433. $query->where('u.agent_type',1);
  434. //代表是否付费定制
  435. ($this->request->action()=='custom' || $this->request->param('u')==2)?$query->where('u.is_vip', 1):$query->where('u.is_vip', 0);
  436. //代表是否冻结
  437. if($this->request->action()!='userlogout' && $this->request->param('u')!=5){
  438. ($this->request->action()=='userban' || $this->request->param('u')==3)?$query->where('u.user_status', 0):$query->where('u.user_status', 1);
  439. }
  440. //代表是否筛选
  441. ($this->request->action()=='screen' || $this->request->param('u')==4)?$query->where('u.is_screen', 1):$query->where('u.is_screen', 0);
  442. //代表是否注销
  443. if($this->request->action()!='userban' && $this->request->param('u')!=3){
  444. ($this->request->action()=='userlogout' || $this->request->param('u')==5)?$query->where('u.user_status', -1):$query->where('u.user_status', 1);
  445. }
  446. //$data = $this->request->param();
  447. if (!empty($data['uid'])) {
  448. $query->where('u.id', intval($data['uid']));
  449. }
  450. if (!empty($data['keyword'])) {
  451. $keyword = $data['keyword'];
  452. $query->where('u.user_nickname|u.real_name|u.mobile', 'like', "%$keyword%");
  453. }
  454. //年龄区间查询
  455. if((!empty($data['age1']) && $data['age1']!='none') && (!empty($data['age2']) && $data['age2']!='none')){
  456. $query->where('u.birthday',['>',strtotime($data['age1'])],['<',strtotime($data['age2'])],'and');
  457. $query->whereNotNull('u.birthday');
  458. }
  459. // //只有第一个年龄的情况下
  460. if((!empty($data['age1']) && $data['age1']!='none') && (empty($data['age2']) || $data['age2']=='none')){
  461. $birthday = $data['age1'];
  462. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  463. }
  464. // //只有第二个年龄的情况下
  465. if((empty($data['age1']) || $data['age1']=='none') && (!empty($data['age2']) && $data['age2']!='none')){
  466. $birthday = $data['age2'];
  467. $query->whereRaw("YEAR(from_unixtime(u.`birthday`))=$birthday and u.birthday is not null ");
  468. }
  469. //身高区间查询
  470. if((!empty(input('height')) && input('height')!='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  471. $query->where('up.height',['>',input('height')],['<',input('heightt')],'and');
  472. }
  473. //身高第一个查找
  474. if((!empty(input('height')) && input('height')!='none') && (empty(input('heightt')) || input('heightt')=='none')){
  475. $query->where('up.height',input('height'));
  476. }
  477. //身高第二个查找
  478. if((empty(input('height')) ||input('height')=='none') && (!empty(input('heightt')) && input('heightt')!='none')){
  479. $query->where('up.height',input('heightt'));
  480. }
  481. //学历
  482. if((!empty(input('education')) && input('education')!='none') ){
  483. $query->where('up.education',input('education'));
  484. }
  485. //职位
  486. if((!empty(input('occupation')) && input('occupation')!='none') ){
  487. $query->where('up.occupation',input('occupation'));
  488. }
  489. //收入
  490. if((!empty(input('salary')) && input('salary')!='none') ){
  491. $query->where('up.salary',input('salary'));
  492. }
  493. //资产
  494. if((!empty(input('property')) && input('property')!='none') ){
  495. $query->where('up.property',input('property'));
  496. }
  497. //家乡
  498. if((!empty(input('home_city')) && input('home_city')!='none') ){
  499. $query->where('up.home_province|up.home_city','like','%'.input('home_city').'%','or');
  500. }
  501. //居住地(市)
  502. if((!empty(input('city')) && input('city')!='none') ){
  503. $query->where('up.city','like','%'.input('city').'%');
  504. }
  505. //婚姻状况
  506. if((!empty(input('married')) && input('married')!='none') ){
  507. $query->where('up.married',input('married'));
  508. }
  509. //性别
  510. if((!empty(input('sex')) && input('sex')!='none') ){
  511. $query->where('u.sex',input('sex'));
  512. }
  513. })
  514. //待审核
  515. ->order("u.create_time DESC")
  516. ->paginate(10,false,['query'=>request()->param()]);
  517. // echo Db::name('user')->getLastSql();die;
  518. // 获取分页显示
  519. $page = $list->render();
  520. $this->assign('list', $list);
  521. $this->assign('page', $page);
  522. return $this->fetch();
  523. }
  524. /**
  525. * 审核通过和审核不通过的弹框
  526. */
  527. public function goconfrom(){
  528. $this->assign("id",input('id'));
  529. return $this->fetch('marketconfrom');
  530. }
  531. /**
  532. * 审核通过和审核不通过的弹框操作
  533. */
  534. public function doconfrom(){
  535. $param= $this->request->param();
  536. if(isset($param['yes']) && isset($param['id'])){
  537. //开始进行调用成功发送
  538. $data['agent_status'] = 1;
  539. $result=Db::name('user')->where('id',$param['id'])->update($data);
  540. // echo Db::name('user')->getLastSql();die();
  541. //$result=Activity::bookConfirm($param['id'],3);
  542. // if(is_array($result)){
  543. if($result){
  544. echo 1;die;
  545. }else{
  546. echo 0;die;
  547. }
  548. }
  549. if(isset($param['no']) && isset($param['id'])){
  550. //开始进行调用审核失败发送
  551. // $result=Activity::bookConfirm($param['id'],5,$param['noremark']);
  552. if(is_array($result)){
  553. echo 1;die;
  554. }else{
  555. echo 0;die;
  556. }
  557. }
  558. }
  559. /**
  560. * 分销员奖励交易记录表
  561. */
  562. public function markettrans(){
  563. //
  564. /**搜索条件**/
  565. $trans_name = $this->request->param('user_nickname');
  566. $money = $this->request->param('money');
  567. //$userEmail = trim($this->request->param('user_email'));
  568. //账户明细表(包含用户名称,爱心,余额)
  569. $account_logs = Db::name('user_balance_log')
  570. ->alias('blog')
  571. ->join('user u','blog.user_id=u.id','left')
  572. ->whereIn('blog.type',[31,32])
  573. ->where(function (Query $query) use ($trans_name,$money) {
  574. if ($trans_name) {
  575. $query->where('u.user_nickname', 'like', "%$trans_name%");
  576. }
  577. if ($money) {
  578. $query->where('blog.balance', $money);
  579. }
  580. })
  581. ->field('blog.*,u.user_nickname')
  582. ->order("blog.id DESC")
  583. ->paginate(10,false,['query'=>request()->param()])
  584. ->each(function($item,$key){
  585. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('user_nickname')->find();
  586. return $item;
  587. })
  588. ;
  589. //echo Db::name('user_balance_log')->getLastSql();die();
  590. $account_logs->appends(['title' => $trans_name]);
  591. // 获取分页显示
  592. $page = $account_logs->render();
  593. $this->assign("page", $page);
  594. $this->assign("account_logs", $account_logs);
  595. return $this->fetch();
  596. }
  597. /**
  598. * 分销奖励和扣除查看详情
  599. */
  600. public function transinfo(){
  601. $id=input('id');
  602. $balance_log = Db::name('user_balance_log')
  603. ->alias('blog')
  604. ->join('user u','blog.user_id=u.id','left')
  605. ->where(function (Query $query) use ($id) {
  606. if ($id) {
  607. $query->where('blog.id', $id);
  608. }
  609. })
  610. ->field('blog.*,u.user_nickname')
  611. ->find();
  612. $this->assign($balance_log);
  613. return $this->fetch();
  614. }
  615. /**
  616. * 分销记录
  617. */
  618. public function marketrecord(){
  619. // echo Db::name('user')->getLastSql().var_dump( $result);die();
  620. /**搜索条件**/
  621. $trans_name = $this->request->param('user_nickname');
  622. $money = $this->request->param('money');
  623. //$userEmail = trim($this->request->param('user_email'));
  624. //账户明细表(包含用户名称,爱心,余额)
  625. $balance_logs = Db::name('user_balance_log')
  626. ->alias('blog')
  627. ->join('user u','blog.user_id=u.id','left')
  628. ->whereIn('blog.type',[31,32])
  629. ->where(function (Query $query) use ($trans_name,$money) {
  630. if ($trans_name) {
  631. $query->where('u.user_nickname', 'like', "%$trans_name%");
  632. }
  633. if ($money) {
  634. $query->where('blog.balance', $money);
  635. }
  636. })
  637. ->field('blog.*,u.user_nickname')
  638. ->order("blog.id DESC")
  639. ->paginate(10,false,['query'=>request()->param()])
  640. ->each(function($item,$key){
  641. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('user_nickname')->find();
  642. return $item;
  643. })
  644. ;
  645. //echo Db::name('user_balance_log')->getLastSql();die();
  646. $balance_logs->appends(['title' => $trans_name]);
  647. // 获取分页显示
  648. $page = $balance_logs->render();
  649. // var_dump($balance_logs);die();
  650. $this->assign("page", $page);
  651. $this->assign("balance_logs", $balance_logs);
  652. return $this->fetch();
  653. }
  654. //假删除用户
  655. public function todelete(){
  656. $param = $this->request->param();
  657. if (isset($param['ids']) && isset($param["yes"])) {
  658. $ids = $this->request->param('ids/a');
  659. Db::name('user')->where('id', 'in', $ids)->update(['agent_type' => 0]);
  660. $this->success("删除成功!");
  661. }
  662. if (isset($_POST['ids']) && isset($param["no"])) {
  663. $ids = $this->request->param('ids/a');
  664. Db::name('user')->where('id', 'in', $ids)->update(['agent_type' => 1]);
  665. $this->success("取消删除成功!", '/market/marketexamine');
  666. }
  667. }
  668. /**
  669. * 显示奖励充值
  670. */
  671. public function marketshowreward(){
  672. $this->assign("id",input('id'));
  673. return $this->fetch();
  674. }
  675. /**
  676. * 进行奖励充值
  677. */
  678. public function markettoreward(){
  679. $this->assign("id",input('id'));
  680. return $this->fetch();
  681. }
  682. //提现审核
  683. public function withdraw(){
  684. $data = $this->request->param();
  685. session('search',[
  686. 'uid' => isset($data['uid'])? intval($data['uid']) : 0,
  687. 'keyword' => isset($data['keyword'])? trim($data['keyword']) : '',
  688. ]);
  689. // 添加返回历史修改 by wesmiler 2020-02-16
  690. $history = isset($data['history'])? intval($data['history']) : 0;
  691. if($history){
  692. $data = session('user_search');
  693. }else{
  694. session('user_search', $data);
  695. }
  696. // 修改 end
  697. //var_dump($data);die;
  698. $list = Db::name('user_balance_log')
  699. ->alias('ub')
  700. ->join('user u','u.id = ub.user_id','left')
  701. ->where(function (Query $query) use($data){
  702. $query->where('ub.type', 1);
  703. $query->where('ub.status',1); //待审核
  704. })
  705. ->field('ub.*,u.user_nickname,u.real_name')
  706. //待审核
  707. ->order("ub.create_time DESC")
  708. ->paginate(10,false,['query'=>request()->param()])
  709. ->each(function($item,$key){
  710. $item['source_username'] = Db::name('user')->where(['id'=> $item['source_uid'], 'user_type'=> 2])->field('real_name,user_nickname')->find();
  711. return $item;
  712. })
  713. ;
  714. //echo Db::name('user')->getLastSql();die;
  715. // 获取分页显示
  716. $page = $list->render();
  717. $this->assign('list', $list);
  718. $this->assign('page', $page);
  719. //var_dump($list);die();
  720. return $this->fetch("marketwithdraw");
  721. }
  722. //提现审核确认显示
  723. public function godrawconfrom(){
  724. $this->assign('id',input('id'));
  725. return $this->fetch("marketdrawconfrom");
  726. }
  727. //进行提交审核提现。
  728. public function dodrawconfrom(){
  729. $param= $this->request->param();
  730. if(isset($param['yes']) && isset($param['id'])){
  731. //通过userid来得到openid
  732. $result=Db::name('user_balance_log')
  733. ->alias('ub')
  734. ->join('user u','ub.user_id=u.id','left')
  735. ->where(['ub.id'=>$param['id']])
  736. ->field('ub.order_sn,ub.description,ub.user_id,ub.pay_money,ub.change,u.openid')
  737. ->find();
  738. if (empty($result['openid'])) {
  739. echo 0;die;
  740. }
  741. //开始进行调用成功发送
  742. $order = array(
  743. 'orderNo' => $result['order_sn'], //订单号
  744. 'openid' => $result['openid'],
  745. 'amount' => $result['pay_money'], //实际支付金额
  746. 'desc' =>$result['description'], //描述
  747. );
  748. $resulttrans=wechat::transferOrder($order);
  749. if($resulttrans['result_code']=="SUCCESS"){
  750. //进行,变更审核成功。
  751. $data0['status'] = 2;
  752. $result=Db::name('user_balance_log')->where('id',$param['id'])->update($data0);
  753. if($result){
  754. echo 1;die;
  755. }else{
  756. echo 0;die;
  757. }
  758. }else{
  759. echo 0;die;
  760. }
  761. }
  762. if(isset($param['no']) && isset($param['id'])){
  763. //开始进行调用审核失败发送
  764. // $result=Activity::bookConfirm($param['id'],5,$param['noremark']);
  765. if(is_array($result)){
  766. echo 1;die;
  767. }else{
  768. //进行反扣回去
  769. $data0['balance'] +=$result['change'];
  770. Db::name('user_balance_log')->where('id',$param['id'])->update($data0);
  771. Db::name('user')->where('id',$result['user_id'])->update($data0);
  772. echo 0;die;
  773. }
  774. }
  775. }
  776. //进行提交显示出团队人数。
  777. public function showteam(){
  778. return $this->fetch('marketoneuser');
  779. }
  780. }