User.php 69 KB

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