User.php 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-07
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\user;
  11. use app\common\model\merchant\order\OrderMerchant;
  12. use app\common\model\system\admin\Admin;
  13. use app\common\model\system\auth\Role;
  14. use app\common\model\user\UserCertification;
  15. use app\common\repositories\merchant\order\OrderMerchantRepository;
  16. use app\common\repositories\user\UserExtractRepository;
  17. use app\controller\api\merchant\sxy\Access;
  18. use app\controller\api\user\Im;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  21. use app\common\repositories\store\order\StoreOrderRepository;
  22. use app\common\repositories\user\UserBillRepository;
  23. use app\common\repositories\user\UserGroupRepository;
  24. use app\common\repositories\user\UserLabelRepository;
  25. use app\common\repositories\user\UserRepository;
  26. use app\common\repositories\wechat\WechatNewsRepository;
  27. use app\common\repositories\wechat\WechatUserRepository;
  28. use app\validate\admin\UserNowMoneyValidate;
  29. use app\validate\admin\UserValidate;
  30. use FormBuilder\Exception\FormBuilderException;
  31. use think\App;
  32. use think\db\exception\DataNotFoundException;
  33. use think\db\exception\DbException;
  34. use think\db\exception\ModelNotFoundException;
  35. use think\Exception;
  36. use think\facade\Cache;
  37. use think\facade\Db;
  38. use think\Log;
  39. /**
  40. * Class User
  41. * @package app\controller\admin\user
  42. * @author xaboy
  43. * @day 2020-05-07
  44. */
  45. class User extends BaseController
  46. {
  47. /**
  48. * @var UserRepository
  49. */
  50. protected $repository;
  51. /**
  52. * User constructor.
  53. * @param App $app
  54. * @param UserRepository $repository
  55. */
  56. public function __construct(App $app, UserRepository $repository)
  57. {
  58. parent::__construct($app);
  59. $this->repository = $repository;
  60. }
  61. /**
  62. * @return mixed
  63. * @throws DataNotFoundException
  64. * @throws DbException
  65. * @throws ModelNotFoundException
  66. * @author xaboy
  67. * @day 2020-05-07
  68. */
  69. public function lst()
  70. {
  71. /*
  72. * 昵称,分组,标签,地址,性别,
  73. */
  74. $where = $this->request->params([
  75. 'label_id',
  76. 'user_type',
  77. 'sex',
  78. 'is_promoter',
  79. 'country',
  80. 'pay_count',
  81. 'user_time_type',
  82. 'user_time',
  83. 'nickname',
  84. 'province',
  85. 'city',
  86. 'group_id',
  87. 'identity',
  88. 'now_money',
  89. 'account',
  90. 'user_card',
  91. 'user_rich_type',
  92. 'stockholder',
  93. 'subIdentify',
  94. 'user_group',
  95. 'is_show'
  96. ]);
  97. [$page, $limit] = $this->getPage();
  98. return app('json')->success($this->repository->getList($where, $page, $limit));
  99. }
  100. /**
  101. * 协议
  102. * @return mixed
  103. */
  104. public function xieyi(){
  105. var_dump(111);die;
  106. return app('json')->success($this->repository->getXieYi());
  107. }
  108. /**
  109. * 批量设置星级
  110. * @return mixed
  111. * @throws DbException
  112. */
  113. public function start_level(){
  114. $ids = (array)$this->request->param('ids', []);
  115. $admin_start_level = $this->request->param('admin_start_level', '0');
  116. if (!count($ids))
  117. return app('json')->fail('数据不存在');
  118. foreach ($ids as $id){
  119. $rich=Db::name('user_rich')->where('uid',$id)->count();
  120. if($rich){
  121. Db::name('user_rich')->where('uid',$id)->update(['admin_start_level'=>$admin_start_level]);
  122. }else{
  123. $insert=['uid' => $id, 'admin_start_level' => $admin_start_level];
  124. Db::name('user_rich')->insert($insert);
  125. }
  126. }
  127. return app('json')->success('修改成功');
  128. }
  129. public function spreadList($uid)
  130. {
  131. $where = $this->request->params(['level', 'keyword', 'date','identity']);
  132. [$page, $limit] = $this->getPage();
  133. return app('json')->success($this->repository->getLevelList($uid, $where, $page, $limit));
  134. }
  135. public function spreadOrder($uid)
  136. {
  137. $where = $this->request->params(['level', 'keyword', 'date']);
  138. [$page, $limit] = $this->getPage();
  139. return app('json')->success($this->repository->subOrder($uid, $page, $limit, $where));
  140. }
  141. public function clearSpread($uid)
  142. {
  143. $this->repository->update($uid, ['spread_uid' => 0]);
  144. return app('json')->success('清除成功');
  145. }
  146. /**
  147. * @param $id
  148. * @return mixed
  149. * @throws DataNotFoundException
  150. * @throws DbException
  151. * @throws FormBuilderException
  152. * @throws ModelNotFoundException
  153. * @author xaboy
  154. * @day 2020-05-09
  155. */
  156. public function updateForm($id)
  157. {
  158. if (!$this->repository->exists($id))
  159. return app('json')->fail('数据不存在');
  160. return app('json')->success(formToData($this->repository->userForm($id)));
  161. }
  162. public function get_info($id)
  163. {
  164. // ini_set('display_errors','On');
  165. //
  166. // error_reporting(E_ALL);
  167. if (!$this->repository->exists($id))
  168. return app('json')->fail('数据不存在');
  169. $user=Db::name('user')->find($id);
  170. $certification = Db::name('user_certification')->where("uid", $id)->find();
  171. $user['real_name'] = $certification['user_name'] ?? '';
  172. $user['card_id'] = $certification['user_card'] ?? '';
  173. $user_rich=Db::name('user_rich')->where('uid',$id)->find();
  174. $user['admin_start_level'] =$user_rich?$user_rich['admin_start_level']:'0';
  175. $user['user_rich_type'] =$user_rich?$user_rich['type']:'0';
  176. $user['area_manage_pics'] =[];
  177. $user['area_manage_obtain'] ='0';
  178. if($user_rich){
  179. $user['area_manage_obtain'] =$user_rich['obtain'];
  180. if($user_rich['pics']){
  181. $user['area_manage_pics']=explode(',',$user_rich['pics']);
  182. }
  183. }
  184. $code_list_province=DB::name('user')->where('user_group',6)->where('manage_address!=""')->column('manage_address');
  185. $code_list_district=DB::name('user')->where('user_group',5)->where('manage_address!=""')->column('manage_address');
  186. // 省
  187. $code_list_province_arr=[];
  188. foreach ($code_list_province as $v){
  189. $v_explode=explode(',',$v);
  190. $code_list_province_arr[$v_explode[0]][]=$v_explode[0];
  191. }
  192. //区县
  193. $code_list_district_arr=[];
  194. foreach ($code_list_district as $v){
  195. $v_explode=explode(',',$v);
  196. $code_list_district_arr[$v_explode[1]][]=$v_explode[0];
  197. }
  198. if( $user['manage_address']){
  199. $code_list_explode=explode(',',$user['manage_address']);
  200. }
  201. $regions1 = Db::name('regions') -> field('id as value,name as label')->where('level',1) ->select();
  202. $regions2 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',2) ->select();
  203. $regions3 = Db::name('regions') -> field('id as value,name as label,pid')->where('level',3) ->select();
  204. $regions3_data=[];
  205. foreach ($regions3 as $v){
  206. $v['disabled']=false;
  207. if(isset($code_list_district_arr[$v['pid']]) && in_array($v['value'],$code_list_district_arr[$v['pid']])){
  208. if(!isset($code_list_explode[2]) || $code_list_explode[2]!=$v['value']){
  209. $v['disabled']=true;
  210. }
  211. }
  212. $regions3_data[$v['pid']][]=$v;
  213. }
  214. $regions2_data=[];
  215. foreach ($regions2 as $v){
  216. $v['children']=isset( $regions3_data[$v['value']])? $regions3_data[$v['value']]:[];
  217. $regions2_data[$v['pid']][]=$v;
  218. }
  219. $city_area=[];
  220. foreach ($regions1 as $v){
  221. $v['children']=isset( $regions2_data[$v['value']])? $regions2_data[$v['value']]:[];
  222. $city_area[]=$v;
  223. }
  224. $regions2_data2=[];
  225. foreach ($regions2 as $v){
  226. $v['disabled']=false;
  227. if(isset($code_list_province_arr[$v['pid']]) && in_array($v['value'],$code_list_province_arr[$v['pid']])){
  228. if(!isset($code_list_explode[0]) || $code_list_explode[0]!=$v['value']){
  229. $v['disabled']=true;
  230. }
  231. }
  232. $regions2_data2[$v['pid']][]=$v;
  233. }
  234. $city_area_2=[];
  235. foreach ($regions1 as $v){
  236. $v['children']=isset( $regions2_data2[$v['value']])? $regions2_data2[$v['value']]:[];
  237. $city_area_2[]=$v;
  238. }
  239. $user['city_area_1']=$city_area;
  240. $user['city_area_2']=$city_area_2;
  241. //查询当前团队的用户列表
  242. $sql = "select getUserSpreadId($id) as uids";
  243. //\think\facade\Log::info("lplpDB".$sql);
  244. try{
  245. $spread_user_list = Db::query($sql);
  246. }catch (Exception $exception){
  247. return app('json')->success($exception);
  248. }
  249. $spread_user_list = array_diff(explode(",", trim($spread_user_list[0]['uids'],'$,')), [$id]);
  250. //查询创客手机号
  251. $marker_phone_list = [];
  252. $marker_user_list = Db::name("user")->whereIn("uid", $spread_user_list)->where('is_shop_partner', 1)->select()->toArray();
  253. foreach ($marker_user_list as $k=>$v){
  254. $marker_phone_list[] = $v['account'];
  255. }
  256. $user['marker_phone_list'] = $marker_phone_list;
  257. return app('json')->success($user);
  258. }
  259. /**
  260. * @param $id
  261. * @param UserValidate $validate
  262. * @param UserLabelRepository $labelRepository
  263. * @param UserGroupRepository $groupRepository
  264. * @return mixed
  265. * @throws DbException
  266. * @author xaboy
  267. * @day 2020-05-09
  268. */
  269. public function update($id, UserValidate $validate, UserLabelRepository $labelRepository, UserGroupRepository $groupRepository)
  270. {
  271. $data = $this->request->params(['real_name', 'agent_rebate', "mer_rebate", "promoter_rebate", "cross_store", "jurisdiction", "other_jurisdictions", "xqxiaofei", 'phone', 'birthday', 'card_id', 'addres', 'mark', 'group_id', 'user_group', ['label_id', []], ['is_promoter', 0], ['maker_phone_list', []]]);
  272. $validate->check($data);
  273. if (!$this->repository->exists($id))
  274. return app('json')->fail('数据不存在');
  275. // if ($data['group_id'] && !$groupRepository->exists($data['group_id']))
  276. // return app('json')->fail('分组不存在');
  277. $label_id = (array)$data['label_id'];
  278. $maker_phone_list = (array)$data['maker_phone_list'] ?? [];
  279. foreach ($label_id as $k => $value) {
  280. $label_id[$k] = (int)$value;
  281. if (!$labelRepository->exists((int)$value))
  282. return app('json')->fail('标签不存在');
  283. }
  284. //查询当前团队的用户列表,判断当前用户是否为团队成员
  285. $sql = "select getUserSpreadId($id) as uids";
  286. $spread_user_list = Db::query($sql);
  287. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  288. $error_maker_phone = [
  289. 'no_registry' => [],
  290. 'no_team' => [],
  291. ];
  292. foreach ($maker_phone_list as $k => $maker_phone) {
  293. //检查手机号是否已注册
  294. $user = Db::name('user')->where('account', $maker_phone)->find();
  295. if (empty($user)) {
  296. $error_maker_phone['not_sign'][] = $maker_phone;
  297. }
  298. if (!in_array($user['uid'], explode(",", $spread_user_list))) {
  299. $error_maker_phone['no_team'][] = $maker_phone;
  300. }
  301. }
  302. if (count($error_maker_phone['no_registry']) > 0 || count($error_maker_phone['no_team']) > 0) {
  303. return app('json')->fail("创客手机号校验异常", [
  304. 'error_maker_phone' => $error_maker_phone,
  305. ]);
  306. } else {
  307. foreach ($maker_phone_list as $k => $maker_phone) {
  308. Db::name('user')
  309. ->where('account', $maker_phone)
  310. ->update([
  311. 'is_shop_partner' => 1,
  312. ]);
  313. }
  314. }
  315. unset($data['maker_phone_list']);
  316. $data['label_id'] = implode(',', $label_id);
  317. if(!$data['birthday']) unset($data['birthday']);
  318. $user_group=input('post.user_group','');
  319. if(in_array($user_group,[5,6])){
  320. $city_list=input('post.city',[]);
  321. $city_string = implode(",", $city_list);
  322. if(!$city_list){
  323. return app('json')->fail('请选择代理区域');
  324. }
  325. $code_list_count=Db::name('user')->where('manage_address', $city_string)->where('uid !='.$id)->count();
  326. if($code_list_count){
  327. return app('json')->fail('改区域已经分配给其他人了');
  328. }
  329. $data['manage_address']=$city_string;
  330. $data['up_agency_time']=date('Y-m-d H:i:s');
  331. }else{
  332. $data['up_agency_time']=null;
  333. }
  334. if ($user_group == 3) {
  335. $mer = Db::name('merchant')->where('uid', $id)->find();
  336. if ($mer)
  337. return app('json')->fail('已经是创客,不可调整成大V经理身份');
  338. $data['up_vip_time'] = date('Y-m-d H:i:s');
  339. } else {
  340. $data['up_vip_time'] = null;
  341. }
  342. if ($user_group == 4) {
  343. $new_user_group = Db::name('user')->where('uid', $id)->value('user_group');
  344. if ($new_user_group == 3)
  345. return app('json')->fail('已经是大V经理,不可调整成创客身份');
  346. $data['up_vip_time'] = date('Y-m-d H:i:s');
  347. } else {
  348. $data['up_vip_time'] = null;
  349. }
  350. $this->repository->update($id, $data);
  351. //更新身份证信息
  352. $cardData = [];
  353. if ($data['card_id']) {
  354. $cardData['user_card'] = $data['card_id'];
  355. }
  356. if ($data['real_name']) {
  357. $cardData['user_name'] = $data['real_name'];
  358. }
  359. if (!empty($cardData)) {
  360. Db::name('user_certification')->where("uid", $id)->update($cardData);
  361. }
  362. // $admin_start_level=input('post.admin_start_level',0);
  363. // if (!empty($admin_start_level)) {
  364. // }
  365. $pics=input('post.area_manage_pics',[]);
  366. $user_rich_ypdate['type']=input('post.user_rich_type',0);
  367. $user_rich_ypdate['obtain']=input('post.area_manage_obtain',0);
  368. $user_rich_ypdate['admin_start_level']=input('post.admin_start_level',0);
  369. if($pics){
  370. $user_rich_ypdate['pics']=implode(',',$pics);
  371. }
  372. $rich=Db::name('user_rich')->where('uid',$id)->count();
  373. if($rich){
  374. Db::name('user_rich')->where('uid',$id)->update($user_rich_ypdate);
  375. }else{
  376. $user_rich_ypdate['uid']=$id;
  377. Db::name('user_rich')->insert($user_rich_ypdate);
  378. }
  379. return app('json')->success('编辑成功');
  380. }
  381. public function maker_check_phone($id)
  382. {
  383. $params = $this->request->params(['phone']);
  384. $user = Db::name('user')->where('account', $params['phone'])->find();
  385. if (empty($user)) {
  386. return app('json')->fail('该用户未注册,请先邀请用户注册~');
  387. }
  388. //查询当前团队的用户列表,判断当前用户是否为团队成员
  389. $sql = "select getUserSpreadId($id) as uids";
  390. $spread_user_list = Db::query($sql);
  391. $spread_user_list = trim($spread_user_list[0]['uids'],'$,');
  392. if (!in_array($user['uid'], explode(",", $spread_user_list))) {
  393. return app('json')->fail('该用户不属于您团队,不可设置为合伙人~');
  394. }
  395. return app('json')->success();
  396. }
  397. /**
  398. * 设为合伙人
  399. * @return mixed
  400. * @throws DataNotFoundException
  401. * @throws DbException
  402. * @throws ModelNotFoundException
  403. */
  404. public function setAreaManage()
  405. {
  406. $area_type = $this->request->param('area_type', 0);//类型 district town village
  407. $area_manage_address_ids = $this->request->param('area_manage_address_ids', 0);//
  408. $uid = $this->request->param('uid', 0);//用户id
  409. // $area_manage = Db::name('area_manage')->where('code_list', $area_manage_address_ids)->find();
  410. // if ($area_manage) {
  411. // return app('json')->fail('该地区已有代理!');
  412. // }
  413. // $area_manage = Db::name('area_manage')->where('uid', $uid)->find();
  414. // if ($area_manage) {
  415. // return app('json')->fail('该用户已经是代理了!');
  416. // }
  417. $area_manage_address_list = explode(',', $area_manage_address_ids);
  418. switch ($area_type) {
  419. case 'district':
  420. if (count($area_manage_address_list) != 3)
  421. return app('json')->fail('请输入正确的高级合伙人代理地址!');
  422. break;
  423. case 'town':
  424. if (count($area_manage_address_list) != 4)
  425. return app('json')->fail('请输入正确的中级合伙人代理地址!');
  426. break;
  427. case 'village':
  428. if (count($area_manage_address_list) != 3)
  429. return app('json')->fail('请输入正确的初级合伙人代理地址!');
  430. break;
  431. default :
  432. return app('json')->fail('请输入正确的初级合伙人代理地址!');
  433. }
  434. $end_address = Db::name('regions_new')->where('id', end($area_manage_address_list))->find();
  435. if (empty($end_address))
  436. return app('json')->fail('该地址不存在!');
  437. // 查询当时是否已有未支付的合伙人商品订单
  438. $hehuo_store_group_order = DB::name('store_order')
  439. ->alias('store_order')
  440. ->leftJoin('store_order_product store_order_product', 'store_order.order_id=store_order_product.order_id')
  441. ->where('store_order.uid', $uid)
  442. ->where('store_order.paid', 0)
  443. ->where('store_order_product.type', 'in', [11, 12, 13])
  444. ->find();
  445. if($hehuo_store_group_order)
  446. return app('json')->fail('该用户当前有待支付的合伙人商品,不可下单!');
  447. $key = 'area_manage_order:' . $area_manage_address_ids;
  448. $redis = Cache::store('redis')->handler();
  449. if (!$redis->setnx($key, 1))
  450. return app('json')->fail('该地区已有用户锁定,请稍后再试!');
  451. // 区域设置成功 记录
  452. Db::name('area_manage')->insert([
  453. 'uid' => $uid,
  454. 'type' => $area_type,
  455. 'order_sn' => '',
  456. 'code_list' => $area_manage_address_ids,
  457. 'create_time' => date('Y-m-d H:i:s')
  458. ]);
  459. Db::name('log')->insert(['data' => "后台修改{$uid}为{$area_type}区域成功,code_list:{$area_manage_address_ids}!"]);
  460. return app('json')->success('修改成功');
  461. }
  462. /**
  463. * 设为回填
  464. * @return mixed
  465. * @throws DataNotFoundException
  466. * @throws DbException
  467. * @throws ModelNotFoundException
  468. */
  469. public function setHuiTian()
  470. {
  471. $uid = $this->request->param('uid', 0);//用户id
  472. $user_rich = Db::name('user_rich')->where('uid', $uid)->find();
  473. if ($user_rich) {
  474. if ($user_rich['is_huitian'] == 1)
  475. return app('json')->fail('该用户已经是回填!');
  476. if ($user_rich['type'] != 0)
  477. return app('json')->fail('只有普通用户可以设置为回填!');
  478. Db::name('user_rich')->where('uid', $uid)->update([
  479. 'type' => 4,
  480. 'is_huitian' => 1,
  481. ]);
  482. } else {
  483. Db::name('user_rich')->where('uid', $uid)->insert([
  484. 'uid' => $uid,
  485. 'type' => 4,
  486. 'is_huitian' => 1,
  487. ]);
  488. }
  489. Db::name('log')->insert(['data' => "后台修改{$uid}为回填成功!"]);
  490. return app('json')->success('修改成功');
  491. }
  492. /**
  493. * @param $id
  494. * @param UserLabelRepository $labelRepository
  495. * @return mixed
  496. * @throws DbException
  497. * @author xaboy
  498. * @day 2020-05-08
  499. */
  500. public function changeLabel($id, UserLabelRepository $labelRepository)
  501. {
  502. $label_id = (array)$this->request->param('label_id', []);
  503. if (!$this->repository->exists($id))
  504. return app('json')->fail('数据不存在');
  505. foreach ($label_id as $k => $value) {
  506. $label_id[$k] = (int)$value;
  507. if (!$labelRepository->exists((int)$value))
  508. return app('json')->fail('标签不存在');
  509. }
  510. $label_id = implode(',', $label_id);
  511. $this->repository->update($id, compact('label_id'));
  512. return app('json')->success('修改成功');
  513. }
  514. /**
  515. * @param UserLabelRepository $labelRepository
  516. * @return mixed
  517. * @throws DbException
  518. * @author xaboy
  519. * @day 2020-05-08
  520. */
  521. public function batchChangeLabel(UserLabelRepository $labelRepository)
  522. {
  523. $label_id = (array)$this->request->param('label_id', []);
  524. $ids = (array)$this->request->param('ids', []);
  525. if (!count($ids))
  526. return app('json')->fail('数据不存在');
  527. foreach ($label_id as $k => $value) {
  528. $label_id[$k] = (int)$value;
  529. if (!$labelRepository->exists((int)$value))
  530. return app('json')->fail('标签不存在');
  531. }
  532. $this->repository->batchChangeLabelId($ids, $label_id);
  533. return app('json')->success('修改成功');
  534. }
  535. /**
  536. * @param $id
  537. * @return mixed
  538. * @throws DataNotFoundException
  539. * @throws DbException
  540. * @throws FormBuilderException
  541. * @throws ModelNotFoundException
  542. * @author xaboy
  543. * @day 2020-05-08
  544. */
  545. public function changeLabelForm($id)
  546. {
  547. if (!$this->repository->exists($id))
  548. return app('json')->fail('数据不存在');
  549. return app('json')->success(formToData($this->repository->changeLabelForm($id)));
  550. }
  551. /**
  552. * @return mixed
  553. * @throws DataNotFoundException
  554. * @throws DbException
  555. * @throws FormBuilderException
  556. * @throws ModelNotFoundException
  557. * @author xaboy
  558. * @day 2020-05-08
  559. */
  560. public function batchChangeLabelForm()
  561. {
  562. $ids = $this->request->param('ids', '');
  563. $ids = array_filter(explode(',', $ids));
  564. if (!count($ids))
  565. return app('json')->fail('数据不存在');
  566. return app('json')->success(formToData($this->repository->changeLabelForm($ids)));
  567. }
  568. /**
  569. * 批量微信入账公证处
  570. * @return mixed
  571. * @author php迷途小书童
  572. * @created 2021/3/10 15:37
  573. */
  574. public function batchGzc()
  575. {
  576. $ids = $this->request->param('ids', '');
  577. $type = $this->request->param('type', '');
  578. $ids = array_filter(explode(',', $ids));
  579. if (!count($ids))
  580. return app('json')->fail('数据不存在');
  581. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  582. foreach ($ids as $id) {
  583. $user = $this->repository->get($id);
  584. switch ($type) {
  585. case 'WX':
  586. if (!$user->wechat_user_id)
  587. return app('json')->fail('账号:'.$user->account.'暂未微信授权,操作停止');
  588. $pay_user_id = $user->wechat_user_id;
  589. break;
  590. case 'ALI':
  591. if (!$user->ali_user_id)
  592. return app('json')->fail('账号:'.$user->account.'暂未支付宝授权,操作停止');
  593. $pay_user_id = $user->ali_user_id;
  594. break;
  595. default:
  596. return app('json')->fail('请求参数错误');
  597. break;
  598. }
  599. $count = OrderMerchant::getDB()
  600. ->where('pay_user_id', $pay_user_id)
  601. ->where('paid', 1)
  602. ->where('gzc', 0)
  603. ->count();
  604. if (!$count)
  605. return app('json')->fail('账号:'.$user->account.'暂无要发起的入账信息,操作停止');
  606. $certification = UserCertification::getDB()
  607. ->where('uid', $user->uid)
  608. ->find();
  609. if (!$certification)
  610. return app('json')->fail('账号:'.$user->account.'暂未实名认证,操作停止');
  611. $OrderMerchantRepository->batchGzc($certification,$user,$type);
  612. }
  613. return app('json')->success('发起成功');
  614. }
  615. /**
  616. * @return mixed
  617. * @throws DataNotFoundException
  618. * @throws DbException
  619. * @throws FormBuilderException
  620. * @throws ModelNotFoundException
  621. * @author xaboy
  622. * @day 2020-05-08
  623. */
  624. public function batchChangeGroupForm()
  625. {
  626. $ids = $this->request->param('ids', '');
  627. $ids = array_filter(explode(',', $ids));
  628. if (!count($ids))
  629. return app('json')->fail('数据不存在');
  630. return app('json')->success(formToData($this->repository->changeGroupForm($ids)));
  631. }
  632. /**
  633. * @param $id
  634. * @param UserGroupRepository $groupRepository
  635. * @return mixed
  636. * @throws DbException
  637. * @author xaboy
  638. * @day 2020-05-07
  639. */
  640. public function changeGroup($id, UserGroupRepository $groupRepository)
  641. {
  642. $group_id = (int)$this->request->param('group_id', 0);
  643. if (!$this->repository->exists($id))
  644. return app('json')->fail('数据不存在');
  645. if ($group_id && !$groupRepository->exists($group_id))
  646. return app('json')->fail('分组不存在');
  647. $this->repository->update($id, compact('group_id'));
  648. return app('json')->success('修改成功');
  649. }
  650. /**
  651. * @param UserGroupRepository $groupRepository
  652. * @return mixed
  653. * @throws DbException
  654. * @author xaboy
  655. * @day 2020-05-07
  656. */
  657. public function batchChangeGroup(UserGroupRepository $groupRepository)
  658. {
  659. $group_id = (int)$this->request->param('group_id', 0);
  660. $ids = (array)$this->request->param('ids', []);
  661. if (!count($ids))
  662. return app('json')->fail('数据不存在');
  663. if ($group_id && !$groupRepository->exists($group_id))
  664. return app('json')->fail('分组不存在');
  665. $this->repository->batchChangeGroupId($ids, $group_id);
  666. return app('json')->success('修改成功');
  667. }
  668. /**
  669. * @param $id
  670. * @return mixed
  671. * @throws FormBuilderException
  672. * @throws DataNotFoundException
  673. * @throws DbException
  674. * @throws ModelNotFoundException
  675. * @author xaboy
  676. * @day 2020-05-07
  677. */
  678. public function changeGroupForm($id)
  679. {
  680. if (!$this->repository->exists($id))
  681. return app('json')->fail('数据不存在');
  682. return app('json')->success(formToData($this->repository->changeGroupForm($id)));
  683. }
  684. /**
  685. * @param $id
  686. * @return mixed
  687. * @throws FormBuilderException
  688. * @author xaboy
  689. * @day 2020-05-07
  690. */
  691. public function changeNowMoneyForm($id)
  692. {
  693. if (!$this->repository->exists($id))
  694. return app('json')->fail('数据不存在');
  695. return app('json')->success(formToData($this->repository->changeNowMoneyForm($id)));
  696. }
  697. /**
  698. * @param $id
  699. * @param UserNowMoneyValidate $validate
  700. * @return mixed
  701. * @throws DataNotFoundException
  702. * @throws DbException
  703. * @throws ModelNotFoundException
  704. * @author xaboy
  705. * @day 2020-05-07
  706. */
  707. public function changeNowMoney($id, UserNowMoneyValidate $validate)
  708. {
  709. $data = $this->request->params(['now_money', 'type']);
  710. $validate->check($data);
  711. if (!$this->repository->exists($id))
  712. return app('json')->fail('数据不存在');
  713. $this->repository->changeNowMoney($id, $this->request->adminId(), $data['type'], $data['now_money']);
  714. return app('json')->success('修改成功');
  715. }
  716. /**
  717. * @param $id
  718. * @return mixed
  719. * @throws FormBuilderException
  720. * @author xaboy
  721. * @day 2020-05-07
  722. */
  723. public function changeProForm($id)
  724. {
  725. if (!$this->repository->exists($id))
  726. return app('json')->fail('数据不存在');
  727. return app('json')->success(formToData($this->repository->changeProForm($id)));
  728. }
  729. /*
  730. * 更改用户推荐信息
  731. * cabbage
  732. * 2020-11-04
  733. * */
  734. public function changePro($id,UserRepository $repository)
  735. {
  736. $spread_account = $this->request->param('spread_account');
  737. if (!$spread_account || !$id){
  738. return app('json')->fail('参数丢失');
  739. }
  740. if($repository->update_spread($id,$spread_account)){
  741. return app('json')->success("修改成功");
  742. }else{
  743. return app('json')->fail("失败");
  744. }
  745. }
  746. /**
  747. * 修改用户奖励表单
  748. * @param $id
  749. * @return mixed
  750. * @throws FormBuilderException
  751. */
  752. public function changeAwardForm($id)
  753. {
  754. if (!$this->repository->exists($id))
  755. return app('json')->fail('数据不存在');
  756. return app('json')->success(formToData($this->repository->changeAwardForm($id)));
  757. }
  758. /**
  759. * 修改用户奖励
  760. * @param $id
  761. * @param UserRepository $repository
  762. * @return mixed
  763. */
  764. public function changeAward($id,UserRepository $repository)
  765. {
  766. $type = $this->request->param('type');
  767. $award_type = $this->request->param('award_type');
  768. $num = $this->request->param('num');
  769. $mark = $this->request->param('mark','');
  770. $admin_id = $this->request->param('admin_id');
  771. if (!$id || !$award_type || !$num){
  772. return app('json')->fail('参数丢失');
  773. }
  774. if($repository->changeAward($id,$type,$award_type,$num,$mark,$admin_id)){
  775. return app('json')->success("修改成功");
  776. }else{
  777. return app('json')->fail("失败");
  778. }
  779. }
  780. /**
  781. * @param $id
  782. * @return mixed
  783. * @throws DataNotFoundException
  784. * @throws DbException
  785. * @throws FormBuilderException
  786. * @throws ModelNotFoundException
  787. * @author xaboy
  788. * @day 2020-05-08
  789. */
  790. public function changePassForm($id)
  791. {
  792. if (!$this->repository->exists($id))
  793. return app('json')->fail('数据不存在');
  794. return app('json')->success(formToData($this->repository->changePassForm($id)));
  795. }
  796. /*
  797. * 更改用户密码
  798. * cabbage
  799. * 2021-2-23
  800. * */
  801. public function changePass($id,UserRepository $repository)
  802. {
  803. $pass_word = $this->request->param('pass_word');
  804. if (!$pass_word || !$id){
  805. return app('json')->fail('参数丢失');
  806. }
  807. if($repository->changePass($id,$pass_word)){
  808. return app('json')->success("修改成功");
  809. }else{
  810. return app('json')->fail("失败");
  811. }
  812. }
  813. /**
  814. * @param WechatNewsRepository $wechatNewsRepository
  815. * @param WechatUserRepository $wechatUserRepository
  816. * @return mixed
  817. * @author xaboy
  818. * @day 2020-05-11
  819. */
  820. public function sendNews(WechatNewsRepository $wechatNewsRepository, WechatUserRepository $wechatUserRepository)
  821. {
  822. $ids = array_filter(array_unique(explode(',', $this->request->param('ids'))));
  823. $news_id = (int)$this->request->param('news_id', 0);
  824. if (!$news_id)
  825. return app('json')->fail('请选择图文消息');
  826. if (!$wechatNewsRepository->exists($news_id))
  827. return app('json')->fail('数据不存在');
  828. if (!count($ids))
  829. return app('json')->fail('请选择微信用户');
  830. $wechatUserRepository->sendNews($news_id, $ids);
  831. return app('json')->success('发送成功');
  832. }
  833. // public function promoterList()
  834. // {
  835. // $where = $this->request->params(['keyword', 'user_type', 'status', 'sex', 'group_id']);
  836. //// $where['is_promoter'] = 1;
  837. // [$page, $limit] = $this->getPage();
  838. // return app('json')->success($this->repository->getList($where, $page, $limit));
  839. // }
  840. public function promoterList()
  841. {
  842. $where = $this->request->params(['keyword']);
  843. // $where['is_promoter'] = 1;
  844. [$page, $limit] = $this->getPage();
  845. return app('json')->success($this->repository->getAgent($where, $page, $limit));
  846. }
  847. public function promoterAgent()
  848. {
  849. $where = $this->request->params(['keyword', 'identity']);
  850. // $where['is_promoter'] = 1;
  851. [$page, $limit] = $this->getPage();
  852. return app('json')->success($this->repository->getAgentList($where, $page, $limit));
  853. }
  854. public function getPromoter($id)
  855. {
  856. // $where = $this->request->params(['id']);
  857. $where['id'] =$id;
  858. // [$page, $limit] = $this->getPage();s
  859. return app('json')->success($this->repository->getonePromoter($where));
  860. }
  861. public function updateAgent($id)
  862. {
  863. $where = $this->request->params(["status"]);
  864. $res = $this->repository->updateAgent($where,$id);
  865. if($res['code'] == 400){
  866. return app('json')->fail($res['msg']);
  867. }
  868. return app('json')->success("审核成功");
  869. }
  870. /*线下支付*/
  871. public function xianPay($id){
  872. $mark = input("mark");
  873. $res = $this->repository->xianPayAgent($id,$mark);
  874. if($res['code'] == 400){
  875. return app('json')->fail($res['msg']);
  876. }
  877. return app('json')->success("线下支付成功");
  878. }
  879. public function detail($id)
  880. {
  881. if (!$this->repository->exists($id))
  882. return app('json')->fail('数据不存在');
  883. $data = $this->repository->userOrderDetail($id);
  884. $data['enterprise_user'] = null;
  885. $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
  886. $ylj=Db::name("user_bill")->where($where)->whereIn('status',[0,1])->sum('number');
  887. $data['ylj']=$ylj?$ylj:0;
  888. return app('json')->success($data);
  889. }
  890. public function order($id, StoreOrderRepository $repository)
  891. {
  892. if (!$this->repository->exists($id))
  893. return app('json')->fail('数据不存在');
  894. [$page, $limit] = $this->getPage();
  895. return app('json')->success($repository->userList($id, $page, $limit));
  896. }
  897. public function coupon($id, StoreCouponUserRepository $repository)
  898. {
  899. if (!$this->repository->exists($id))
  900. return app('json')->fail('数据不存在');
  901. [$page, $limit] = $this->getPage();
  902. return app('json')->success($repository->userList($id, $page, $limit));
  903. }
  904. public function bill($id, UserBillRepository $repository)
  905. {
  906. if (!$this->repository->exists(intval($id)))
  907. return app('json')->fail('数据不存在');
  908. [$page, $limit] = $this->getPage();
  909. return app('json')->success($repository->userList([
  910. 'now_money' => 0,
  911. 'status' => 1
  912. ], $id, $page, $limit));
  913. }
  914. /**
  915. * @return mixed
  916. * @author xaboy
  917. * @day 2020/6/22
  918. */
  919. public function new_bill($id, UserBillRepository $billRepository)
  920. {
  921. [$page, $limit] = $this->getPage();
  922. $where = [
  923. // 'now_money' => $this->request->param('type', 0),
  924. 'status' => $this->request->param('status'),
  925. // 'mer_id' => $this->request->merId()
  926. 'not_commission_type' => [5, 7, 17, 19],
  927. ];
  928. if ($this->request->param('is_red') == true) {
  929. $where['is_red_brokerage'] = 1;
  930. }
  931. $bill_list = $billRepository->userList($where, $id, $page, $limit);
  932. foreach ($bill_list['list'] as $key => $item) {
  933. if ($item['status'] == 1) $bill_list['list'][$key]['jiesuan_string'] = "已结算";
  934. if ($item['status'] == 0) $bill_list['list'][$key]['jiesuan_string'] = "未结算";
  935. if ($item['status'] == -1) $bill_list['list'][$key]['jiesuan_string'] = "已失效";
  936. }
  937. return app('json')->success($bill_list);
  938. }
  939. /*
  940. * 用户养老金信息
  941. * @author cabbage
  942. * @date 2020-11-03
  943. * */
  944. public function annuity($id, UserRepository $repository)
  945. {
  946. if (!$this->repository->exists(intval($id)))
  947. return app('json')->fail('数据不存在');
  948. return app('json')->success($repository->get_yanglao($id));
  949. }
  950. /**
  951. * 养老金明细
  952. */
  953. public function annuitylog($id, UserRepository $repository){
  954. [$page, $limit] = $this->getPage();
  955. $where=["uid"=>$id,"type"=>"commission","commission_type"=>5];
  956. $res = $repository->yanglaolog($where,$page,$limit);
  957. return app('json')->success($res);
  958. }
  959. /*用户银行卡信息*/
  960. public function getAccount($id){
  961. $where['user_id']=$id;
  962. $data = app()->make(UserExtractRepository::class)->list($where);
  963. return app('json')->success($data);
  964. }
  965. /*设置用户身份*/
  966. /*
  967. * pay:1-付费。2-未付费
  968. * type:3-银卡。4-金卡。5-商户。6-渠道商
  969. * */
  970. public function setIdentity(){
  971. $data = $this->request->params(["uid","pay","type","dc_id","recommend_phone"]);
  972. $dc_id = $data['dc_id'];
  973. if(empty($data['uid'])){
  974. return app('json')->fail('参数错误');
  975. }
  976. $time = date('Y-m-d', time());
  977. $time = strtotime($time);
  978. $end_time = $time + 31536000 - 1;
  979. $recommend = Db::name('user') -> where('account',$data['recommend_phone']) -> value('uid');
  980. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  981. $access = new Access();
  982. //付费
  983. if($data['pay'] == 1){
  984. switch ($data['type']){
  985. case 3:
  986. case 4:
  987. if($data['type'] == 3){
  988. $order['pay_price'] = '399';
  989. }else{
  990. $order['pay_price'] = '999';
  991. }
  992. $order['uid'] = $data['uid'];
  993. $order['order_id'] = 0;
  994. $order['order_sn'] = 'sIO'.$storeOrderRepository->getNewOrderId();
  995. $order['mer_id'] = 0;
  996. $order['dacang_id'] = $dc_id;
  997. if($data['type'] == 3){
  998. $storeOrderRepository -> dacang_yin($order,0);
  999. }elseif($data['type'] == 4){
  1000. $storeOrderRepository -> dacang($order,0);
  1001. }
  1002. break;
  1003. case 5:
  1004. //赠送商户
  1005. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1006. if(!$merchant)
  1007. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
  1008. $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
  1009. if(!$mer){
  1010. Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>2]);
  1011. }else{
  1012. Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 2) ->update();
  1013. }
  1014. $order_sn = 'sIM'.$storeOrderRepository->getNewOrderId();
  1015. $insertData=[
  1016. 'mer_id'=>0,
  1017. 'pay_price'=>systemConfig("annual"),
  1018. 'status'=>1,
  1019. 'order_no'=>$order_sn,
  1020. 'uid'=>$data['uid']
  1021. ];
  1022. $id = Db::name('merchant_annual_cost_order')->insertGetId($insertData);
  1023. $access->nianfei_yj($id);
  1024. break;
  1025. case 6:
  1026. //赠送返本商户
  1027. $mer = Db::name('user_mer') -> where('uid',$data['uid']) -> find();
  1028. if(!$mer){
  1029. Db::name('user_mer') -> insert(['uid'=>$data['uid'],'mer'=>10]);
  1030. }else{
  1031. Db::name('user_mer') -> where('uid',$data['uid'])->inc('mer', 10) ->update();;
  1032. }
  1033. //赠送商户
  1034. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1035. if(!$merchant)
  1036. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'activation_code'=>rand('000000000','999999999')]);
  1037. //赠送大仓会员资格
  1038. $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
  1039. $dc_id = 1;
  1040. //如果不是金卡会员,赠送金卡会员一年
  1041. if (!$dacang_user) {
  1042. Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>1]);
  1043. }else{
  1044. //如果是银卡会员,变成金卡,一年 || 是否已过期,如果已过期,赠送金卡会员一年
  1045. if($dacang_user['type'] == 2 || $dacang_user['end_time'] < $time){
  1046. Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>1]);
  1047. }
  1048. }
  1049. $order_sn = 'sIC'.$storeOrderRepository->getNewOrderId();
  1050. $insertData=[
  1051. 'pay_price'=>systemConfig("channel_price"),
  1052. 'status'=>1,
  1053. 'order_no'=>$order_sn,
  1054. 'uid'=>$data['uid']
  1055. ];
  1056. Db::name('channel_order')->insertGetId($insertData);
  1057. //渠道商
  1058. $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
  1059. if($channel_user){
  1060. Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
  1061. }else{
  1062. Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
  1063. }
  1064. $access->channel_fenyong($order_sn);
  1065. break;
  1066. }
  1067. return app('json')->success('付费身份设置成功');
  1068. }else{
  1069. //未付费
  1070. switch ($data['type']){
  1071. case 3:
  1072. case 4:
  1073. $dacang_user = Db::name('da_cang_user')->where('uid', $data['uid'])->find();
  1074. $type = $data['type'] == 3 ? 2 : 1;
  1075. //如果原来有大仓会员。修改
  1076. if ($dacang_user) {
  1077. Db::name('da_cang_user')->where('uid', $data['uid'])->where('dc_id', $dc_id)->update(['end_time' => $end_time,'status'=>1,'type'=>$type]);
  1078. } else {
  1079. //新会员
  1080. Db::name('da_cang_user')->insert(['uid' => $data['uid'], 'ctime' => time(), 'end_time' => $end_time, 'dc_id' => $dc_id,'status'=>1,'type'=>$type]);
  1081. }
  1082. break;
  1083. case 5:
  1084. //赠送商户
  1085. $merchant=Db::name('merchant')->where('uid',$data['uid'])->find();
  1086. if(!$merchant)
  1087. Db::name('merchant_intention')->insert(['uid'=>$data['uid'],'status'=>3,'activation_code'=>rand('000000000','999999999')]);
  1088. break;
  1089. case 6:
  1090. //渠道商
  1091. $channel_user=Db::name('channel_user')->where('uid',$data['uid']) -> find();
  1092. if($channel_user){
  1093. Db::name('channel_user')->where('uid',$data['uid'])->update(['status'=>1]);
  1094. }else{
  1095. Db::name('channel_user')->insert(['uid'=>$data['uid'],'status'=>1,'ctime'=>time(),'recommend_uid'=>$recommend]);
  1096. }
  1097. }
  1098. return app('json')->success('未付费身份设置成功');
  1099. }
  1100. }
  1101. public function gongfu_user(){
  1102. $data = $this->request->params(["uid","red","type"]);
  1103. if(empty($data['uid']) || empty($data['type'])){
  1104. return app('json')->fail('参数错误');
  1105. }
  1106. $type = $data['type'];
  1107. $red = $data['red'];
  1108. $uid = $data['uid'];
  1109. $check = Db::name('user_rich')->where('uid',$uid)->find();
  1110. if($check){
  1111. $update['type'] = $type;
  1112. Db::name('user_rich')->where('uid',$uid)->update($update);
  1113. }else{
  1114. Db::name('user_rich')->insert(['uid' => $uid, 'type' => $type]);
  1115. }
  1116. if ($red > 0){
  1117. Db::name('user_rich')->where('uid',$uid)->inc('red', $red)->update();
  1118. Db::name('user_rich_log')->insert([
  1119. 'uid' => $uid,
  1120. 'red' => $red,
  1121. 'pm' => 1,
  1122. 'time' => time(),
  1123. 'order_id' => 0,
  1124. 'mark' => '系统赠送红积分'
  1125. ]);
  1126. }
  1127. return app('json')->success('身份设置成功');
  1128. }
  1129. public function bangfu(){
  1130. $data = $this->request->params(["uid"]);
  1131. if(empty($data['uid'])){
  1132. return app('json')->fail('参数错误');
  1133. }
  1134. $uid = $data['uid'];
  1135. $check = Db::name('user_bangfu') -> where('uid', $uid) -> find();
  1136. if (!$check){
  1137. Db::name('user_bangfu')->insert([
  1138. 'uid' => $uid,
  1139. 'time' => time(),
  1140. 'status' => 1
  1141. ]);
  1142. }
  1143. return app('json')->success('身份设置成功');
  1144. }
  1145. public function bangfu_list(){
  1146. [$page, $limit] = $this->getPage();
  1147. $list = Db::name('user_bangfu')
  1148. -> alias('ub')
  1149. -> join('user u', 'u.uid = ub.uid')
  1150. -> leftJoin('user_rich ur', 'ub.uid = ur.uid')
  1151. -> field('u.nickname,u.account,ub.status,ur.type,ub.id as uid')
  1152. -> page($page, $limit)
  1153. -> select();
  1154. return app('json')->success($list);
  1155. }
  1156. public function bangfu_examine(){
  1157. $data = $this->request->params(["uid","status"]);
  1158. if(empty($data['uid'])){
  1159. return app('json')->fail('参数错误');
  1160. }
  1161. $uid = $data['uid'];
  1162. $check = Db::name('user_bangfu') -> where('id', $uid) -> find();
  1163. if (!$check){
  1164. return app('json')->fail('不存在');
  1165. }
  1166. $save = Db::name('user_bangfu') -> where('uid', $uid) -> update(['status'=>$data['status']]);
  1167. if ($save){
  1168. return app('json')->success('修改成功');
  1169. }
  1170. return app('json')->fail('出错');
  1171. }
  1172. public function importExcel()
  1173. {
  1174. $file = request()->file('file');
  1175. if(!$file){
  1176. return app('json')->fail('请上传文件');
  1177. }
  1178. $extension = pathinfo($file->getOriginalName(), PATHINFO_EXTENSION);
  1179. if ($extension != 'xlsx' && $extension != 'xls') {
  1180. return app('json')->fail('请上传xlx或xlsx文件');
  1181. }
  1182. // 创建一个新的Excel读取器对象
  1183. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  1184. $objPHPExcel = $objReader->load($file);
  1185. // 选择活动工作表
  1186. $objPHPExcel->setActiveSheetIndex(0);
  1187. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  1188. // 循环遍历行和列
  1189. $yonghu=[];
  1190. foreach ($sheetData as $k=>$row) {
  1191. if($k==1){
  1192. continue;
  1193. }
  1194. if($row['A'] && $row['A']!=NULL && $row['A']!=''){
  1195. $yonghu[]=array('a'=>$row['A'],'b'=>$row['B']);
  1196. }
  1197. }
  1198. if(count($yonghu)<1){
  1199. return app('json')->fail('未获取到数据');
  1200. }
  1201. $repository = app()->make(UserRepository::class);
  1202. foreach ($yonghu as $k=>$v){
  1203. $user = $repository->accountByUser($v['a']);
  1204. if ($user){
  1205. // return app('json')->fail('手机号已存在');
  1206. $yonghu[$k]['user'] = $user;
  1207. }else{
  1208. $yonghu[$k]['user'] = $repository->registr($v['a'],'A123456','APP',0);
  1209. }
  1210. }
  1211. foreach ($yonghu as $v){
  1212. $user=$v['user'];
  1213. $spread_uid=$v['user']['spread_uid'];
  1214. if($v['b'] && $v['b']!=null && $v['b']!=''){
  1215. $pid=Db::name('user')->where('account',$v['b'])->value('uid');
  1216. if($pid){
  1217. $repository->bindSpread($user, intval($pid));
  1218. $spread_uid=$pid;
  1219. }
  1220. }
  1221. $mer_count=Db::name('merchant')->where('uid',$user['uid'])->count();
  1222. if(!$mer_count){
  1223. // $code_insert['uid']=$v['uid'];
  1224. // $code_insert['code']=time().'_'.$this->generateRandomCode(20);
  1225. // $code_insert['ctime']=time();
  1226. // $code_insert['type']=2;
  1227. // $re=Db::name('activation_code')->insertGetId($code_insert);
  1228. $mer_insert['uid']=$user['uid'];
  1229. $mer_insert['spread_uid']=$spread_uid;
  1230. $mer_id=Db::name('merchant')->insertGetId($mer_insert);
  1231. $merchant_admin_insert['mer_id']=$mer_id;
  1232. $merchant_admin_insert['uid']= $user['uid'];
  1233. $merchant_admin_insert['account']= $user['account'];
  1234. $merchant_admin_insert['real_name']= $user['account'];
  1235. $merchant_admin_insert['phone']= $user['account'];
  1236. $merchant_admin_insert['level']= 0;
  1237. $re=Db::name('merchant_admin')->insertGetId($merchant_admin_insert);
  1238. $merchant_intention['mer_id']=$mer_id;
  1239. $merchant_intention['uid']= $user['uid'];
  1240. $merchant_intention['phone']= $user['account'];
  1241. Db::name('merchant_intention')->insertGetId($merchant_intention);
  1242. // insert into rrx_merchant_admin(mer_id,uid,account,pwd,phone,real_name,level) values (#{mer_id},#{uid},#{account},#{pwd},#{phone},#{real_name},#{level})
  1243. }
  1244. }
  1245. return app('json')->success('导入成功');
  1246. }
  1247. public function getImAdmin(){
  1248. try {
  1249. $data = json_decode('{
  1250. "im_pass": 873947,
  1251. "im_user_id": "admin",
  1252. "im_uuid": "53d0f370-f104-11ee-8cd6-45641584429c"
  1253. }',true);
  1254. return app('json')->success($data);
  1255. $im = new Im();
  1256. $data = [];
  1257. $data['im_pass'] = mt_rand(100000,999999);
  1258. $data['im_user_id'] = 'admin';
  1259. $data['im_uuid']= $im->createImUser('useradmin', 'admin',$data['im_pass']);
  1260. return app('json')->success($data);
  1261. } catch (\Exception $e) {
  1262. Db::name('log')->insert(['data'=>'注册异常'.$e->getFile().$e->getMessage().$e->getLine()]);
  1263. }
  1264. return app('json')->fail('注册失败');
  1265. }
  1266. public function enterpriseUserScoreApi(){
  1267. [$page, $limit] = $this->getPage();
  1268. $where = $this->request->params(['uid']);
  1269. $list=Db::name('user_sign_score')->where($where)->page($page, $limit)->order('id desc')->select();
  1270. foreach ($list as $k=>$v){
  1271. $v['pm_text']='收入';
  1272. if($v['pm']==2 || $v['pm']==4){
  1273. $v['pm_text']='支出';
  1274. $v['reward_socre']='-'.$v['reward_socre'];
  1275. }else{
  1276. $v['pm_text']='收入';
  1277. $v['reward_socre']='+'.$v['reward_socre'];
  1278. }
  1279. if($v['order_id'] && empty($v['order_sn'])){
  1280. $v['order_sn']=Db::name('store_order')->where('order_id',$v['order_id'])->value('order_sn');
  1281. }
  1282. if(empty($v['order_sn'])){
  1283. $v['order_sn']='--';
  1284. }
  1285. $v['create_time'] = $v['settlement_time'];
  1286. $v['create_time'] = date("Y-m-d H:i:s", $v['addtime']);
  1287. $list[$k]=$v;
  1288. }
  1289. $data['list']=$list;
  1290. $data['count']=Db::name('user_sign_score')->where($where)->count();
  1291. return app('json')->success($data);
  1292. }
  1293. /**
  1294. * 获取合伙人分红记录
  1295. * @return mixed
  1296. * @throws DataNotFoundException
  1297. * @throws DbException
  1298. * @throws ModelNotFoundException
  1299. */
  1300. public function getWeekAwardList()
  1301. {
  1302. [$page, $limit] = $this->getPage();
  1303. $nickname = request()->param('nickname','');
  1304. $account = request()->param('account','');
  1305. $where = [];
  1306. if($nickname) $where[] = ['u.nickname','like','%'.$nickname.'%'];
  1307. if($account) $where[] = ['u.account','=',$account];
  1308. $query = Db::name('old_user_weekaward')->alias('w')
  1309. ->leftJoin('user u','w.user_id=u.uid')
  1310. ->leftJoin('old_user_starlevel star','star.id=w.user_star_id')
  1311. ->field('w.*,u.uid,u.real_name,u.nickname,star.title')
  1312. ->where($where);
  1313. $data = $query->page($page)
  1314. ->limit($limit)
  1315. ->order('w.id desc')
  1316. ->select();
  1317. $count = $query->count();
  1318. if($data) {
  1319. $data = $data->toArray();
  1320. foreach ($data as $k => $v){
  1321. $data[$k]['award_num'] = bcadd($v['award_num'],$v['award_num_sm'],2);
  1322. $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
  1323. $data[$k]['radio'] = $v['radio'] == 2 ? '已发放' : '未发放';
  1324. }
  1325. }
  1326. $return_data['list'] = $data;
  1327. $return_data['count'] = $count;
  1328. return app('json')->success($return_data);
  1329. }
  1330. /**
  1331. * 获取联创奖励记录
  1332. * @return mixed
  1333. * @throws DataNotFoundException
  1334. * @throws DbException
  1335. * @throws ModelNotFoundException
  1336. */
  1337. public function getOriginatorList()
  1338. {
  1339. [$page, $limit] = $this->getPage();
  1340. $nickname = request()->param('nickname','');
  1341. $account = request()->param('account','');
  1342. $where = [];
  1343. if($nickname) $where[] = ['u.nickname','like','%'.$nickname.'%'];
  1344. if($account) $where[] = ['u.account','=',$account];
  1345. $query = Db::name('old_user_originator')->alias('o')
  1346. ->leftJoin('user u','o.user_id=u.uid')
  1347. ->leftJoin('old_user_lianc lianc','lianc.id=o.user_lianc_id')
  1348. ->field('o.*,u.uid,u.real_name,u.nickname,lianc.title')
  1349. ->where($where);
  1350. $data = $query->page($page)
  1351. ->limit($limit)
  1352. ->order('o.id desc')
  1353. ->select();
  1354. $count = $query->count();
  1355. if($data) {
  1356. $data = $data->toArray();
  1357. foreach ($data as $k=>$v){
  1358. $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
  1359. }
  1360. }
  1361. $return_data['list'] = $data;
  1362. $return_data['count'] = $count;
  1363. return app('json')->success($return_data);
  1364. }
  1365. /**
  1366. * 获取股权分红记录
  1367. * @return mixed
  1368. * @throws DataNotFoundException
  1369. * @throws DbException
  1370. * @throws ModelNotFoundException
  1371. */
  1372. public function getStockList()
  1373. {
  1374. [$page, $limit] = $this->getPage();
  1375. $nickname = request()->param('nickname','');
  1376. $account = request()->param('account','');
  1377. $where = [];
  1378. if($nickname) $where[] = ['u.nickname','like','%'.$nickname.'%'];
  1379. if($account) $where[] = ['u.account','=',$account];
  1380. $query = Db::name('old_user_stock')->alias('o')
  1381. ->leftJoin('user u','o.user_id=u.uid')
  1382. ->field('o.*,u.uid,u.real_name,u.nickname')
  1383. ->where($where);
  1384. $data = $query->page($page)
  1385. ->limit($limit)
  1386. ->order('o.id desc')
  1387. ->select();
  1388. $count = $query->count();
  1389. if($data) {
  1390. $data = $data->toArray();
  1391. foreach ($data as $k=>$v){
  1392. $data[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
  1393. $data[$k]['update_time'] = date('Y-m-d H:i:s',$v['update_time']);
  1394. }
  1395. }
  1396. $return_data['list'] = $data;
  1397. $return_data['count'] = $count;
  1398. return app('json')->success($return_data);
  1399. }
  1400. }