User.php 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/18
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use app\common\repositories\article\AgreementRepository;
  12. use app\common\repositories\merchant\order\OrderGzcRepository;
  13. use app\common\repositories\merchant\order\OrderMerchantRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\user\UnionUsersRepository;
  16. use app\controller\api\merchant\sxy\Access;
  17. use app\controller\api\store\product\DaTaoKe;
  18. use app\controller\api\store\product\Jd;
  19. use app\controller\api\store\product\TaoBao;
  20. use app\controller\api\store\product\TaoKe;
  21. use app\controller\api\store\product\Vip;
  22. use app\model\common\UserThirdModel;
  23. use app\traits\GzcApiRequest;
  24. use app\traits\HuiPay;
  25. use crmeb\basic\BaseController;
  26. use app\common\repositories\user\UserBillRepository;
  27. use app\common\repositories\user\UserRepository;
  28. use app\common\repositories\user\UserVisitRepository;
  29. use crmeb\services\QrcodeService;
  30. use crmeb\services\WechatService;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use think\App;
  33. use think\facade\Db;
  34. use think\Exception;
  35. use think\exception\ValidateException;
  36. use think\facade\Cache;
  37. use BaiduAi\controller\Ocr;
  38. use think\facade\Log;
  39. use think\facade\Request as r;
  40. class User extends BaseController
  41. {
  42. use HuiPay;
  43. public $repository;
  44. private $merId;
  45. private $source;
  46. public function __construct(App $app, UserRepository $repository)
  47. {
  48. parent::__construct($app);
  49. $this->repository = $repository;
  50. $this->source = $this->request->header('source');
  51. $this->merId = $this->request->header('merId');
  52. }
  53. /**
  54. * 创建环信账户
  55. * @return mixed
  56. */
  57. public function hxim_create()
  58. {
  59. $uid = $this->request->uid();
  60. try {
  61. $im = new Im();
  62. $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find();
  63. if (isset($user['im_uuid']) && $user['im_user_id']) {
  64. return app('json')->success($user);
  65. }
  66. $im_user_id = 'user' . $user['uid'];
  67. $data = [];
  68. $data['im_pass'] = mt_rand(100000, 999999);
  69. $data['im_user_id'] = $im_user_id;
  70. // 获取用户是否存在
  71. $imUser = $im->getImUser('user' . $uid);
  72. if (isset($imUser['activated']) && $imUser['activated'] == true) {
  73. $data['im_uuid'] = $imUser['uuid'];
  74. } else {
  75. $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
  76. }
  77. Db::name('User')->where(['uid' => $uid])->update([
  78. 'im' => 1,
  79. 'im_uuid' => $data['im_uuid'],
  80. 'im_userid' => $im_user_id,
  81. 'im_password' => $data['im_pass']
  82. ]);
  83. return app('json')->success($data);
  84. } catch (\Exception $e) {
  85. Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
  86. }
  87. return app('json')->fail('注册失败');
  88. }
  89. /**
  90. * @return mixed
  91. * @author xaboy
  92. * @day 2020/6/22
  93. */
  94. public function we_com()
  95. {
  96. $where2['mer_id'] = $this->merId;
  97. $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
  98. return app('json')->success($user);
  99. }
  100. public function spread_image()
  101. {
  102. $type = $this->request->param('type');
  103. $res = $type == 'routine'
  104. ? $this->repository->routineSpreadImage($this->request->userInfo())
  105. : $this->repository->wxSpreadImage($this->request->userInfo());
  106. return app('json')->success($res);
  107. }
  108. /**
  109. * @return mixed
  110. * 分享每日海报
  111. */
  112. public function share_day()
  113. {
  114. /**
  115. * 1242
  116. * 2208
  117. */
  118. $user = $this->request->userInfo();
  119. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  120. $siteUrl = systemConfig('site_url');
  121. $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
  122. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
  123. if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
  124. $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
  125. $qrcode = $imageInfo['dir'];
  126. dump($qrcode);
  127. $config = array(
  128. 'image' => array(
  129. array(
  130. 'url' => $qrcode,//二维码资源
  131. 'stream' => 0,
  132. 'left' => 533,
  133. 'top' => 1941,
  134. 'right' => 0,
  135. 'bottom' => 0,
  136. 'width' => 184,
  137. 'height' => 182,
  138. 'opacity' => 100
  139. )
  140. ),
  141. 'background' => $filename
  142. );
  143. $data = setSharePoster($config, 'routine/spread/poster');
  144. dump($data);
  145. return app('json')->success($data);
  146. }
  147. public function spread_info()
  148. {
  149. $user = $this->request->userInfo();
  150. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
  151. $data = [
  152. 'lock_brokerage' => $user->lock_brokerage,
  153. 'one_level_count' => $user->one_level_count,
  154. 'two_level_count' => $user->two_level_count,
  155. 'spread_total' => $user->spread_total,
  156. 'yesterday_brokerage' => $user->yesterday_brokerage,
  157. 'total_extract' => $user->total_extract,
  158. 'total_brokerage' => $user->total_brokerage,
  159. 'brokerage_price' => $user->brokerage_price,
  160. 'member_brokerage_price' => $user->member_brokerage_price,
  161. 'now_money' => $user->now_money,
  162. 'broken_day' => (int)systemConfig('lock_brokerage_timer')
  163. ];
  164. return app('json')->success($data);
  165. }
  166. public function spread_info_yhc()
  167. {
  168. log::info("============ddddddddd");
  169. $user = $this->request->userInfo();
  170. if($user->uid>0){
  171. //已经入账积分
  172. $data['total_source']=$user->score;
  173. //为生效积分
  174. $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
  175. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  176. return app('json')->success($data);
  177. }
  178. // if ($this->source == 'yhc' && $this->merId) {
  179. // $where['mer_id'] = $this->merId;
  180. // $where['uid'] = $user->uid;
  181. // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
  182. // if ($enterprise_user) {
  183. // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
  184. // $data['unsettled_balance'] = 0;//未结算
  185. // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
  186. // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
  187. // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
  188. // $data['identity'] = $enterprise_user['identity'];
  189. // $data['level'] = $enterprise_user['level'];
  190. // $data['partnership'] = $enterprise_user['partnership'];
  191. // $data['green_integral'] = $enterprise_user['green_integral'];
  192. // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
  193. // $data['operate'] = $enterprise_user['operate'];
  194. // $data['operate_icon'] = '';
  195. // $data['operate_text'] = '';
  196. // $member_settings = merchantConfig($this->merId, 'member_settings');
  197. // if ($data['operate'] == 101) {
  198. // $data['operate_icon'] = $member_settings['yy_one_img'];
  199. // $data['operate_text'] = $member_settings['yy_one_text'];
  200. // }
  201. // if ($data['operate'] == 102) {
  202. // $data['operate_icon'] = $member_settings['yy_two_img'];
  203. // $data['operate_text'] = $member_settings['yy_two_text'];
  204. // }
  205. //
  206. //
  207. // $data['nickname'] = $user->nickname;
  208. // $data['avatar'] = $enterprise_user['avatar'];
  209. //
  210. // $arr = $this->jisuan_fans($user->uid);
  211. // $data['fans_num'] = count($arr);//粉丝总数
  212. //
  213. // $yanglao = 0;
  214. // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
  215. // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  216. // $yanglao += $offLine1;
  217. // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  218. // $yanglao += $offLine2;
  219. //
  220. //
  221. // $data['ylj'] = set_price_rtrim($yanglao);
  222. //
  223. // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
  224. //
  225. //
  226. // $data['uid'] = $enterprise_user['uid'];
  227. // if ($enterprise_user['identity'] > 100) {
  228. // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
  229. // if (!$data['identity_data']) {
  230. // $data['identity_data'] = null;
  231. // $data['identity'] = '100';
  232. // }
  233. // } else {
  234. // $data['identity_data'] = null;
  235. // }
  236. //
  237. // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
  238. //
  239. //
  240. // return app('json')->success($data);
  241. // }
  242. // }
  243. return app('json')->fail('用户不存在');
  244. }
  245. /**
  246. * @param UserBillRepository $billRepository
  247. * @return mixed
  248. * @author xaboy
  249. * @day 2020/6/22
  250. */
  251. public function bill(UserBillRepository $billRepository)
  252. {
  253. [$page, $limit] = $this->getPage();
  254. $where = [
  255. // 'now_money' => $this->request->param('type', 0),
  256. 'status' => $this->request->param('status'),
  257. ];
  258. if ($this->request->param('is_red') == true) {
  259. $where['is_red_brokerage'] = 1;
  260. }
  261. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  262. }
  263. /**
  264. * @param UserBillRepository $billRepository
  265. * @return mixed
  266. * @author xaboy
  267. * @day 2020/6/22
  268. */
  269. public function brokerage_list(UserBillRepository $billRepository)
  270. {
  271. [$page, $limit] = $this->getPage();
  272. return app('json')->success($billRepository->userList([
  273. 'category' => 'brokerage',
  274. ], $this->request->uid(), $page, $limit));
  275. }
  276. /**
  277. * @return mixed
  278. * @throws \think\db\exception\DataNotFoundException
  279. * @throws \think\db\exception\DbException
  280. * @throws \think\db\exception\ModelNotFoundException
  281. * @author xaboy
  282. * @day 2020/6/22
  283. */
  284. public function spread_order()
  285. {
  286. [$page, $limit] = $this->getPage();
  287. return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
  288. }
  289. /**
  290. * TODO
  291. * @return mixed
  292. * @author Qinii
  293. * @day 2020-06-18
  294. */
  295. public function binding()
  296. {
  297. $data = $this->request->params(['phone', 'sms_code']);
  298. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  299. $user = $this->repository->accountByUser($data['phone']);
  300. if ($user) {
  301. $data = ['phone' => $data['phone']];
  302. } else {
  303. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  304. }
  305. $this->repository->update($this->request->uid(), $data);
  306. return app('json')->success('绑定成功');
  307. }
  308. /**
  309. * TODO
  310. * @return mixed
  311. * @author Qinii
  312. * @day 2020-06-18
  313. */
  314. public function binding_verify()
  315. {
  316. $data = $this->request->params(['user_id', 'captcha']);
  317. $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
  318. $data['sms_code'] = $data['captcha'];
  319. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  320. return app('json')->success('验证成功');
  321. }
  322. public function checkSmsCode($phone, $code)
  323. {
  324. $sms_key = 'api.auth.sms.' . $phone;
  325. if (!$cache_code = Cache::get($sms_key)) return false;
  326. if ($code != $cache_code) return false;
  327. Cache::delete($sms_key);
  328. return true;
  329. }
  330. /**
  331. * @return mixed
  332. * @throws \think\db\exception\DataNotFoundException
  333. * @throws \think\db\exception\DbException
  334. * @throws \think\db\exception\ModelNotFoundException
  335. * @author xaboy
  336. * @day 2020/6/22
  337. */
  338. public function spread_list()
  339. {
  340. [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
  341. $uid = $this->request->uid();
  342. [$page, $limit] = $this->getPage();
  343. return app('json')->success($level == 2
  344. ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
  345. : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
  346. }
  347. /**
  348. * @return mixed
  349. * @author xaboy
  350. * @day 2020/6/22
  351. */
  352. public function spread_top()
  353. {
  354. [$page, $limit] = $this->getPage();
  355. $type = $this->request->param('type', 0);
  356. return app('json')->success($type == 1
  357. ? $this->repository->spreadMonthTop($page, $limit)
  358. : $this->repository->spreadWeekTop($page, $limit));
  359. }
  360. /**
  361. * @return mixed
  362. * @author xaboy
  363. * @day 2020/6/22
  364. */
  365. public function brokerage_top()
  366. {
  367. [$page, $limit] = $this->getPage();
  368. $type = $this->request->param('type', 0);
  369. return app('json')->success($type == 1
  370. ? $this->repository->brokerageMonthTop($page, $limit)
  371. : $this->repository->brokerageWeekTop($page, $limit));
  372. }
  373. public function history(UserVisitRepository $repository)
  374. {
  375. $uid = $this->request->uid();
  376. [$page, $limit] = $this->getPage();
  377. return app('json')->success($repository->getHistory($uid, $page, $limit));
  378. }
  379. public function deleteHistory($id, UserVisitRepository $repository)
  380. {
  381. $uid = $this->request->uid();
  382. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  383. return app('json')->fail('数据不存在');
  384. $repository->delete($id);
  385. return app('json')->success('删除成功');
  386. }
  387. public function account()
  388. {
  389. $user = $this->request->userInfo();
  390. if (!$user->phone) return app('json')->fail('请绑定手机号');
  391. return app('json')->success($this->repository->selfUserList($user->phone));
  392. }
  393. public function switchUser()
  394. {
  395. $uid = (int)$this->request->param('uid');
  396. if (!$uid) return app('json')->fail('用户不存在');
  397. $userInfo = $this->request->userInfo();
  398. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  399. $user = $this->repository->switchUser($userInfo, $uid);
  400. $tokenInfo = $this->repository->createToken($user);
  401. $this->repository->loginAfter($user);
  402. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  403. }
  404. /**
  405. * 签到 获取积分
  406. * @return mixed
  407. * @throws \think\db\exception\DataNotFoundException
  408. * @throws \think\db\exception\DbException
  409. * @throws \think\db\exception\ModelNotFoundException
  410. */
  411. public function sub_signin()
  412. {
  413. $member_id = $this->request->uid();
  414. if (!$member_id) return app('json')->fail('用户不存在');
  415. $res = $this->repository->sub_signin($member_id);
  416. return app('json')->success($res);
  417. }
  418. /**
  419. * 获取用户签到记录
  420. * data1 开始时间
  421. * data2 结束时间
  422. * @return mixed
  423. * @throws \think\db\exception\DataNotFoundException
  424. * @throws \think\db\exception\DbException
  425. * @throws \think\db\exception\ModelNotFoundException
  426. */
  427. public function get_signin()
  428. {
  429. $member_id = $this->request->uid();
  430. if (!$member_id) return app('json')->fail('用户不存在');
  431. $where = [];
  432. $data1 = input('data1');
  433. $data2 = input('data2');
  434. if ($data1 && $data2) {
  435. $where["data1"] = $data1;
  436. $where["data2"] = $data2;
  437. }
  438. $res = $this->repository->get_signin($member_id, $where);
  439. return app('json')->success($res);
  440. }
  441. /**
  442. * 提交实名认证
  443. *
  444. * @return void
  445. */
  446. public function add_certification()
  447. {
  448. $member_id = $this->request->uid();
  449. $type = input("type", 0);
  450. if ($type == 1) {
  451. $data = $this->repository->get_cer(["uid" => $member_id]);
  452. return app('json')->success($data);
  453. }
  454. if (!$member_id) return app('json')->fail('用户不存在');
  455. $params = $this->request->params([
  456. 'user_name',
  457. 'mobile',
  458. 'user_card',
  459. 'card_positive',
  460. 'card_reverse',
  461. ]);
  462. $params['create_time'] = time();
  463. $params['uid'] = $member_id;
  464. $baidu = new Ocr();
  465. $image = file_get_contents($params['card_positive']);
  466. $idCardSide = "front";
  467. $result = $baidu->idcard($image, $idCardSide);
  468. $real_user_name = $result['words_result']['姓名']['words'] ?? '';
  469. $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
  470. if ($real_user_name != $params['user_name']) {
  471. return app('json')->fail('姓名或身份证号输入有误~');
  472. }
  473. if ($real_user_card != $params['user_card']) {
  474. return app('json')->fail('姓名或身份证号输入有误~');
  475. }
  476. if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
  477. $params['status'] = 1;
  478. $res = $this->repository->add_cer($params, $member_id);
  479. if ($res) {
  480. return app('json')->success($res);
  481. } else {
  482. return app('json')->fail('认证失败');
  483. }
  484. } else {
  485. return app('json')->fail('认证失败,请重新认证');
  486. }
  487. }
  488. /**
  489. * 申请代理
  490. * name:公司名称
  491. * identity:身份
  492. * license:营业执照
  493. */
  494. public function apply_agent()
  495. {
  496. $name = input("name", "");
  497. $identity = input("identity", 1);
  498. $license = input("license", "");
  499. $province_id = input("province_id", "");
  500. $city_id = input("city_id", "");
  501. $area_id = input("area_id", "");
  502. $street_id = input("street_id", "");
  503. $spread_account = input("spread_account", "");
  504. $member_id = $this->request->uid();
  505. if ($identity != 6 && (!$name || !$identity || !$license)) {
  506. return app('json')->fail('请检查参数');
  507. }
  508. if ($identity == 6 && (!$name || !$identity)) {
  509. return app('json')->fail('请检查参数');
  510. }
  511. $data = [
  512. "name" => $name,
  513. "identity" => $identity,
  514. "license" => $license,
  515. "user_id" => $member_id,
  516. "province_id" => $province_id,
  517. "city_id" => $city_id,
  518. "area_id" => $area_id,
  519. "street_id" => $street_id,
  520. 'spread_account' => $spread_account,
  521. "add_time" => time(),
  522. "update_time" => time()
  523. ];
  524. $res = $this->repository->agent($data);
  525. if ($res['code'] == 400) {
  526. return app('json')->fail($res['msg']);
  527. }
  528. return app('json')->success("申请成功", $res);
  529. }
  530. /*查询是否有已申请或者审核中的代理信息*/
  531. public function isAgent()
  532. {
  533. $uid = $this->request->uid();
  534. $data = $this->repository->isAgent($uid);
  535. return app("json")->success($data);
  536. }
  537. /*查询是否有审核成功的未支付或支付失败的订单*/
  538. public function AgentPayDetail()
  539. {
  540. $uid = $this->request->uid();
  541. if (!$uid) {
  542. return app('json')->fail('请检查参数');
  543. }
  544. $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
  545. $data = $this->repository->getAgentPayDetail($where);
  546. return app('json')->success("成功", $data);
  547. }
  548. /**
  549. * 获取信息 全民营销首页
  550. * @return mixed
  551. */
  552. public function get_agent_info()
  553. {
  554. $member_id = $this->request->uid();
  555. $res = $this->repository->get_agent_info($member_id);
  556. if ($res) {
  557. return app('json')->success($res);
  558. } else {
  559. return app('json')->fail('获取失败');
  560. }
  561. }
  562. /**
  563. * 推广统计
  564. * search 搜索
  565. * @return mixed
  566. */
  567. public function get_extension_info()
  568. {
  569. $search = input("search", "");
  570. $where = $this->request->params(["identity"]);
  571. $member_id = $this->request->uid();
  572. $res = $this->repository->get_extension_info($member_id, $search, $where);
  573. if ($res) {
  574. return app('json')->success($res);
  575. } else {
  576. return app('json')->fail('获取失败');
  577. }
  578. }
  579. /**
  580. * 收益统计
  581. * type 搜索
  582. * @return mixed
  583. */
  584. public function get_profit_info()
  585. {
  586. $where = $this->request->params([
  587. 'commission_type',
  588. 'date_on',
  589. 'date_off',
  590. 'order'
  591. ]);
  592. $member_id = $this->request->uid();
  593. $res = $this->repository->get_profit_info($member_id, $where);
  594. if ($res) {
  595. return app('json')->success($res);
  596. } else {
  597. return app('json')->fail('获取失败');
  598. }
  599. }
  600. /**
  601. * 订单统计
  602. * search 搜索
  603. * @return mixed
  604. */
  605. public function get_tuiguang_order()
  606. {
  607. $member_id = $this->request->uid();
  608. $res = $this->repository->get_tuiguang_order($member_id);
  609. if ($res) {
  610. return app('json')->success($res);
  611. } else {
  612. return app('json')->fail('获取失败');
  613. }
  614. }
  615. /*
  616. * 攒金明细统计
  617. * */
  618. public function get_commission_all()
  619. {
  620. $uid = $this->request->uid();
  621. $where['date_on'] = 1;
  622. $where['date_off'] = 0;
  623. // $where['commission_type'] = '';
  624. $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
  625. $where['order'] = $date['date'];
  626. $res = $this->repository->get_profit_info($uid, $where);
  627. return app('json')->success($res);
  628. }
  629. /*
  630. * 攒金明细列表
  631. * */
  632. public function get_commission_list()
  633. {
  634. $uid = $this->request->uid();
  635. [$where['page'], $where['limit']] = $this->getPage();
  636. $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
  637. $where['type'] = $data['type'];//0线上;1线下
  638. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  639. $res = $this->repository->get_tuiguang_list($uid, $where);
  640. return app('json')->success($res);
  641. }
  642. /*
  643. * 越攒越多佣金
  644. * */
  645. public function get_com_list()
  646. {
  647. $uid = $this->request->uid();
  648. [$where['page'], $where['limit']] = $this->getPage();
  649. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  650. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  651. $res = $this->repository->get_com_list($uid, $where);
  652. return app('json')->success($res);
  653. }
  654. /*
  655. * 越攒越多统计
  656. * */
  657. public function get_com_all()
  658. {
  659. $uid = $this->request->uid();
  660. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  661. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  662. $res = $this->repository->get_com_all($uid, $where);
  663. return app('json')->success($res);
  664. }
  665. /**
  666. * 养老金详情
  667. * @return mixed
  668. */
  669. public function get_yanglao()
  670. {
  671. $member_id = $this->request->uid();
  672. $res = $this->repository->get_yanglao($member_id);
  673. if ($res) {
  674. return app('json')->success($res);
  675. } else {
  676. return app('json')->fail('获取失败');
  677. }
  678. }
  679. /**
  680. * 养老金明细
  681. */
  682. public function yanglaolog()
  683. {
  684. $member_id = $this->request->uid();
  685. [$page, $limit] = $this->getPage();
  686. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
  687. if ($this->source == 'yhc' && $this->merId) {
  688. $where['mer_id'] = $this->merId;
  689. }
  690. $month = $this->request->param('month', '');//年月搜索
  691. $status = $this->request->param('status', 1);
  692. //1-全部 2-已结算 3-未结算 4-已取消
  693. if ($status == 2) {
  694. $where['status'] = 1;
  695. } else if ($status == 3) {
  696. // $where['gzc']=0;
  697. $where['status'] = 0;
  698. } else if ($status == 4) {
  699. $where['status'] = -1;
  700. }
  701. $source = $this->request->param('source', -1);
  702. if ($source > -1) {
  703. $where['source'] = $source;
  704. }
  705. $res = $this->repository->yanglaolog($where, $page, $limit, $month);
  706. if ($res) {
  707. return app('json')->success($res);
  708. } else {
  709. return app('json')->fail('获取失败');
  710. }
  711. }
  712. /*养老金详情*/
  713. public function YangLaoDetail($id)
  714. {
  715. $member_id = $this->request->uid();
  716. $data = $this->request->params([
  717. 'type',
  718. ]);
  719. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
  720. $res = $this->repository->yanglaoDetail($where);
  721. return app('json')->success($res);
  722. }
  723. /**
  724. * 消费明细
  725. * @return mixed
  726. */
  727. public function tripartite()
  728. {
  729. $member_id = $this->request->uid();
  730. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
  731. $res = $this->repository->yanglaolog($where);
  732. if ($res) {
  733. return app('json')->success($res);
  734. } else {
  735. return app('json')->fail('获取失败');
  736. }
  737. }
  738. /**
  739. * 提现明细
  740. * @return mixed
  741. */
  742. public function withdrawal()
  743. {
  744. $member_id = $this->request->uid();
  745. $data = $this->request->params([
  746. 'type',
  747. ]);
  748. $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
  749. if ($this->source == 'yhc') {
  750. $where['mer_id'] = $this->merId;
  751. }
  752. $res = $this->repository->withdrawal_user($where);
  753. if ($res) {
  754. return app('json')->success($res);
  755. } else {
  756. return app('json')->fail('获取失败');
  757. }
  758. }
  759. /**
  760. * 提现详情
  761. * @return mixed
  762. * @author cabbage
  763. * @day 2020/10/31
  764. */
  765. public function withdrawalDetail()
  766. {
  767. $member_id = $this->request->uid();
  768. $extract_id = input("extract_id", 0);
  769. return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
  770. }
  771. /*
  772. * 修改个人信息*/
  773. public function updateUser()
  774. {
  775. $data = $this->request->params([
  776. 'nickname',
  777. 'avatar',
  778. 'sex',
  779. 'birthday',
  780. 'addres',
  781. 'mark'
  782. ]);
  783. $uid = $this->request->uid();
  784. $res = '';
  785. if ($this->source == 'yhc') {
  786. $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
  787. unset($data['avatar']);
  788. }
  789. $data = $this->repository->updateUser($uid, $data);
  790. if ($data || $res) {
  791. return app("json")->success("修改成功", $data);
  792. }
  793. return app("json")->fail("未做任何修改");
  794. }
  795. /*积分记录*/
  796. public function socreList()
  797. {
  798. [$page, $limit] = $this->getPage();
  799. $uid = $this->request->uid();
  800. $data = $this->repository->socreList($uid, $page, $limit);
  801. return app("json")->success($data);
  802. }
  803. function jisuan_fans($uid)
  804. {
  805. $where22['node_uid'] = $uid;
  806. $where22['mer_id'] = $this->merId;
  807. $arr = $this->jisuantuandui($where22);
  808. $where['puid'] = $uid;
  809. $where['mer_id'] = $this->merId;
  810. $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量
  811. $result = array_unique(array_merge($arr, $direct_fans));
  812. return $result;
  813. }
  814. function jisuantuandui($where, $data = [])
  815. {
  816. $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
  817. $arr = array_merge($data, $enterprise_user_team);
  818. foreach ($enterprise_user_team as $v) {
  819. $where['node_uid'] = $v;
  820. $arr = $this->jisuantuandui($where, $arr);
  821. }
  822. return $arr;
  823. }
  824. /**
  825. * 一壶茶-团队列表
  826. */
  827. public function team_list()
  828. {
  829. $uid = $this->request->uid();
  830. $where['puid'] = $uid;
  831. $where['mer_id'] = $this->merId;
  832. $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量
  833. $arr = $this->jisuan_fans($uid);
  834. $data['fans_num'] = count($arr);//粉丝总数
  835. [$page, $limit] = $this->getPage();
  836. $where2['eu.mer_id'] = $this->merId;
  837. $type = $this->request->param('type', 0);
  838. $enterprise_user_team = DB::name('enterprise_user')
  839. ->alias('eu')
  840. ->join('user u', 'eu.uid=u.uid')
  841. ->where($where2)
  842. ->when($type < 1 || $type == 2, function ($q) use ($arr) {
  843. $q->whereIn('eu.uid', $arr);
  844. })
  845. ->when($type == 1, function ($q) use ($uid) {
  846. $q->whereIn('eu.puid', $uid);
  847. })
  848. ->when($type == 2, function ($q) use ($uid) {
  849. $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
  850. })
  851. ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
  852. ->order('eu.enterprise_user_id desc')
  853. ->paginate($limit)
  854. ->each(function ($item) {
  855. $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  856. return $item;
  857. });
  858. $data['team_list'] = $enterprise_user_team;
  859. $data['effective_fans_num'] = DB::name('enterprise_user')
  860. ->alias('eu')
  861. ->join('user u', 'eu.uid=u.uid')
  862. ->where($where2)
  863. ->whereIn('eu.uid', $arr)
  864. ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
  865. ->count();//有效粉丝数量
  866. return app("json")->success($data);
  867. }
  868. public function team_details()
  869. {
  870. $uid = $this->request->param('uid', 0);
  871. $where2['eu.uid'] = $uid;
  872. $where2['eu.mer_id'] = $this->merId;
  873. $enterprise_user_team = DB::name('enterprise_user')
  874. ->alias('eu')
  875. ->join('user u', 'eu.uid=u.uid')
  876. ->where($where2)
  877. ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
  878. ->find();;
  879. if ($enterprise_user_team) {
  880. $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
  881. $enterprise_user_team['p_nickname'] = '';
  882. $enterprise_user_team['p_phone'] = '';
  883. $yanglao = 0;
  884. $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
  885. $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  886. $yanglao += $offLine1;
  887. $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  888. $yanglao += $offLine2;
  889. $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
  890. if ($enterprise_user_team['puid'] > 0) {
  891. $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
  892. if ($user) {
  893. $enterprise_user_team['p_nickname'] = $user['nickname'];
  894. $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
  895. }
  896. }
  897. }
  898. return app("json")->success($enterprise_user_team);
  899. }
  900. /**
  901. * 率积分明细
  902. */
  903. public function green_integral_list()
  904. {
  905. $pm = $this->request->param('pm');
  906. $status = $this->request->param('status');
  907. [$page, $limit] = $this->getPage();
  908. $uid = $this->request->uid();
  909. log::info("green_integral_list==={$uid}");
  910. $where['uid'] = $uid;
  911. // $where['mer_id'] = $this->merId;
  912. // if ($pm == 1) {
  913. // $pm_arr = [1, 3];
  914. // } else {
  915. // $pm_arr = [2, 4];
  916. // }
  917. if ($pm==0){
  918. $data = DB::name('user_sign_score')->where($where)->where('pm', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  919. }
  920. if($pm==1){
  921. $data = DB::name('user_sign_score')->where($where)->where('pm', 2)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  922. }
  923. if($pm==2){
  924. $data = DB::name('user_sign_score')->where($where)->where('status', -1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  925. }
  926. log::info("=======date==={$data}");
  927. return app("json")->success($data);
  928. }
  929. public function user_invite_profit_list()
  930. {
  931. $uid = $this->request->uid();
  932. [$page, $limit] = $this->getPage();
  933. $commission_type = $this->request->param('commission_type', 0);
  934. if ($commission_type) {
  935. $where['commission_type'] = $commission_type;
  936. }
  937. $month = $this->request->param('month', '') ?: date('Y-m');
  938. $startMonth = date('Y-m-01 00:00:00', strtotime($month));
  939. $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
  940. $data['yanglao_clear_all'] = Db::name('user_bill')
  941. ->where('uid', $uid)
  942. ->whereBetween('create_time', [$startMonth, $endMonth])
  943. ->where('commission_type', 5)
  944. ->where('pm', 1)
  945. ->where('status', 1)
  946. ->sum('number');
  947. $data['yanglao_nclear_all'] = Db::name('user_bill')
  948. ->where('uid', $uid)
  949. ->whereBetween('create_time', [$startMonth, $endMonth])
  950. ->where('commission_type', 5)
  951. ->where('pm', 1)
  952. ->where('status', 0)
  953. ->sum('number');
  954. $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
  955. $where['uid'] = $uid;
  956. $data['totel_money'] = Db::name('user_bill')->where($where)
  957. ->whereNotIn('commission_type', [5, 7, 17, 19])
  958. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  959. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  960. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  961. $query->where('commission_type', '<>', 5)
  962. ->whereBetween('create_time', [$startMonth, $endMonth]);
  963. })
  964. ->sum('number');
  965. $pageInfo = Db::name('user_bill')
  966. ->where($where)
  967. ->whereNotIn('commission_type', [5, 7, 17, 19])
  968. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  969. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  970. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  971. $query->where('commission_type', '<>', 5)
  972. ->whereBetween('create_time', [$startMonth, $endMonth]);
  973. })
  974. ->order('bill_id desc')
  975. ->paginate($limit);
  976. $data_arr = [];
  977. foreach ($pageInfo->items() as $k => $v) {
  978. $v['money'] = set_price_rtrim($v['number']);
  979. $v['order_money'] = set_price_rtrim(0);
  980. $v['commission_rate'] = set_price_rtrim(0);
  981. $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
  982. if (!empty($order)) {
  983. $v['order_money'] = set_price_rtrim($order['total_price']);
  984. $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
  985. }
  986. if ($v['status'] == 0) {
  987. // $v['create_time'] = '--';
  988. }
  989. if ($v['status'] == 1) {
  990. // $v['create_time'] = $v['take_time'];
  991. }
  992. $data_arr[] = $v;
  993. }
  994. $data['pageInfo']['current_page'] = $pageInfo->currentPage();
  995. $data['pageInfo']['data'] = $data_arr;
  996. $data['pageInfo']['last_page'] = $pageInfo->lastPage();
  997. return app("json")->success($data);
  998. }
  999. /*导航转链-用于用户下单绑定*/
  1000. public function changeLink()
  1001. {
  1002. $uid = $this->request->uid();
  1003. if (!$uid) {
  1004. return app("json")->error("请登录");
  1005. }
  1006. $data = $data = $this->request->params([
  1007. 'url',
  1008. 'name'
  1009. ]);
  1010. $data['url'] = urldecode($data['url']);
  1011. $data['name'] = urldecode($data['name']);
  1012. if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
  1013. if ($data['name'] == '京东') {
  1014. $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
  1015. }
  1016. if ($data['name'] == '拼多多') {
  1017. $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
  1018. }
  1019. if ($data['name'] == '唯品会') {
  1020. $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
  1021. }
  1022. if ($data['name'] == '苏宁易购') {
  1023. $url = $data['url'];
  1024. //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
  1025. }
  1026. if ($data['name'] == '饿了么') {//获取饿了么官方活动链接
  1027. //如果用户没有拉取relation_id,
  1028. $where = ['uid' => $uid, 'type' => 5];
  1029. $isRelation = UserThirdModel::where($where)->find();
  1030. if ($isRelation) {
  1031. $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
  1032. if ($result['code'] == 0) {
  1033. return \app('json')->fail("获取饿了么链接出错", $result['raw']);
  1034. }
  1035. $url = $result['link'];
  1036. } else {//如果还没有获取用户的relation_id还需要拉淘宝授权
  1037. $state = "{$uid}_h5";
  1038. $url = \app()->make(TaoBao::class)->getAuthUrl($state);
  1039. }
  1040. }
  1041. }
  1042. return app("json")->success($url);
  1043. }
  1044. /*获取协议*/
  1045. public function xieyi()
  1046. {
  1047. $data = $this->request->params([
  1048. 'type'
  1049. ]);
  1050. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
  1051. return app("json")->success($data);
  1052. }
  1053. /**
  1054. * 支付宝获取授权
  1055. * @return mixed
  1056. * @author php迷途小书童
  1057. * @created 2021/1/16 17:03
  1058. */
  1059. public function alipayAuthorization(UserRepository $userRepository)
  1060. {
  1061. $authorization_code = $this->request->param('code');
  1062. $type = $this->request->param('type', 'h5');
  1063. $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
  1064. return app("json")->success($paramStr);
  1065. }
  1066. /**
  1067. * 微信获取授权
  1068. * @return mixed
  1069. * @author php迷途小书童
  1070. * @created 2021/1/16 19:08
  1071. */
  1072. public function wechatAuthorization()
  1073. {
  1074. $request = $this->request;
  1075. $wxConfig = [
  1076. "appid" => "wx66f5f8def2b755da",
  1077. "appsecret" => "891572d83222105a635cf9f502363ff8"
  1078. ];
  1079. $oauth = WechatService::create()->getApplication()->oauth;
  1080. // dump($oauth);
  1081. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1082. try {
  1083. $wechatInfo = $oauth->user()->getOriginal();
  1084. } catch (\Exception $e) {
  1085. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1086. }
  1087. if (!isset($wechatInfo['nickname'])) {
  1088. return app('json')->fail('授权失败[002]');
  1089. }
  1090. return app("json")->success($wechatInfo);
  1091. }
  1092. /**
  1093. * 更新绑定微信支付宝账号
  1094. * type=1 微信 2 支付宝
  1095. * openid openid
  1096. */
  1097. public function updateAccount(UserRepository $userRepository)
  1098. {
  1099. $type = $this->request->param('type');
  1100. $openid = $this->request->param('openid');//前端传的是unionid
  1101. $nickname = $this->request->param('nickname');
  1102. $avater = $this->request->param('avater');
  1103. $alinfo = $this->request->param('alinfo');
  1104. $uid = $this->request->uid();
  1105. $user = $this->request->userInfo();
  1106. if (!$type) {
  1107. return app("json")->fail("失败");
  1108. }
  1109. makeLock()->lock();
  1110. try {
  1111. if ($type == 1) {
  1112. $data = ["wechat_user_id" => $openid];
  1113. $unionId = $openid;
  1114. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  1115. if ($check) throw new \Exception("此微信号已被绑定");
  1116. } else {
  1117. $alinfo = json_decode($alinfo, true);
  1118. if (!$alinfo) throw new \Exception("参数异常");
  1119. $data = ["ali_user_id" => $alinfo["userId"]];
  1120. $unionId = $alinfo["userId"];
  1121. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  1122. if ($check) throw new \Exception("此支付宝号已被绑定");
  1123. $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  1124. // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]);
  1125. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  1126. $avater = empty($paramStr["avatar"]) ? "http://app.bjtdba.com/uploads/def/20201118/5984361a2e00f5407776bcd6eaaae1ce.png" : $paramStr["avatar"];
  1127. }
  1128. $data2 = [
  1129. "type" => $type,
  1130. "uid" => $uid,
  1131. "nickname" => $nickname,
  1132. "avater" => $avater,
  1133. ];
  1134. $result = $this->repository->updateUser($uid, $data, $data2);
  1135. if (!$result) throw new \Exception("修改失败");
  1136. $userRepository = app()->make(UserRepository::class);
  1137. $userInfo = $userRepository->getOne(['uid' => $uid]);
  1138. //绑定线下充值金额
  1139. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1140. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1141. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  1142. if ($notBind) {
  1143. $orderMerchantRepository->doBindUser($userInfo, $type);
  1144. }
  1145. } catch (\Throwable $e) {
  1146. makeLock()->unlock();
  1147. return app("json")->fail("失败" . $e->getMessage());
  1148. }
  1149. makeLock()->unlock();
  1150. return app("json")->success("修改成功", $data);
  1151. }
  1152. /**
  1153. * 获取账号绑定信息
  1154. * @return mixed
  1155. */
  1156. public function getAccount()
  1157. {
  1158. $uid = $this->request->uid();
  1159. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  1160. $data = $this->repository->getAccount($uid);
  1161. if ($data) {
  1162. return app("json")->success("查询成功", $data);
  1163. }
  1164. return app("json")->fail("未绑定");
  1165. }
  1166. /*
  1167. * 养老金统计
  1168. * */
  1169. public function get_yanglao_statistics()
  1170. {
  1171. $uid = $this->request->uid();
  1172. //线下数量
  1173. // 查询未结算
  1174. $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  1175. $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  1176. $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  1177. $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  1178. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  1179. $res = GzcApiRequest::checkAmount($userInfo);
  1180. $gzc = $res['extendData']['amount'] * 0.01;
  1181. // PCPC-中信公证处
  1182. $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  1183. // 总养老金
  1184. $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  1185. // 一壶茶平台养老金
  1186. $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  1187. // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  1188. $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  1189. // 已结算养老金 已入账
  1190. $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  1191. // 已入账养老金
  1192. $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  1193. // 一壶茶平台未入账养老金
  1194. $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  1195. // 待发起
  1196. $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  1197. return app("json")->success("查询成功", $data);
  1198. }
  1199. public function num($data, $field)
  1200. {
  1201. $sum = 0;
  1202. foreach ($data as $item) {
  1203. $sum += $item[$field];
  1204. }
  1205. return $sum;
  1206. }
  1207. //志愿者升级
  1208. public function changeVolunteer()
  1209. {
  1210. $uid = $this->request->uid();
  1211. //志愿者条件
  1212. $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1213. $volunteer_class = new Volunteer();
  1214. $volunteer = $volunteer_class->volunteer($uid);
  1215. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1216. $data['grade'] = 0;
  1217. $data['self_yanglao'] = $volunteer['self_yanglao'];
  1218. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  1219. return app('json')->success($data);
  1220. }
  1221. $volunteer_class->grade($uid, 1, $volunteer);
  1222. return app('json')->success('申请成功');
  1223. }
  1224. public function GZC($uid)
  1225. {
  1226. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1227. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1228. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1229. $where = [
  1230. 'uid' => $uid,
  1231. 'pm' => 1,
  1232. 'status' => 1,
  1233. 'type' => 'commission'
  1234. ];
  1235. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  1236. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  1237. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  1238. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  1239. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  1240. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  1241. $is_implement = 1;
  1242. if ($item['source'] == 0) {
  1243. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  1244. if ($order_data['uid'] == $item['uid']) {
  1245. $is_implement = 0;
  1246. } else {
  1247. $is_implement = 1;
  1248. }
  1249. } else {
  1250. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  1251. if ($order_data['uid'] == $item['uid']) {
  1252. $is_implement = 0;
  1253. } else {
  1254. $is_implement = 1;
  1255. }
  1256. }
  1257. if ($is_implement == 1) {
  1258. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  1259. $create = [
  1260. 'uid' => $online['uid'],
  1261. 'platform_no' => $orderId,
  1262. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  1263. 'user_name' => $certification['user_name'],
  1264. 'mobile' => $certification['mobile'],
  1265. 'user_card' => $certification['user_card'],
  1266. 'pension' => $item['number'],
  1267. 'order_type' => 2,
  1268. 'out_trade_no' => $online['order_sn']
  1269. ];
  1270. $OrderGzcRepository->create($create);
  1271. }
  1272. });
  1273. }
  1274. //20220712版签到
  1275. public function new_sign()
  1276. {
  1277. return app('json')->fail('不允许签到');
  1278. $uid = $this->request->uid();//签到用户
  1279. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户
  1280. //前6天积分
  1281. $score = [
  1282. 2,//1
  1283. 4,//2
  1284. 6,//3
  1285. 10,//4
  1286. 14,//5
  1287. 20//6
  1288. ];
  1289. //7-30天积分
  1290. $scoreS = 3;
  1291. //额外积分
  1292. $scoreExtra = [
  1293. 7 => 38,
  1294. 14 => 68,
  1295. 21 => 128,
  1296. 30 => 188
  1297. ];
  1298. $today_signintime = strtotime(date('Y-m-d', time()));
  1299. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  1300. if (!empty($today_signin_info)) {
  1301. return app('json')->fail('今天已经签到过了');
  1302. } else {
  1303. //查询昨天是否已经签到了
  1304. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  1305. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  1306. $has_qian = 1;
  1307. if (!empty($yes_signin_info)) {
  1308. $has_qian = $yes_signin_info['continuity_day'] + 1;
  1309. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  1310. }
  1311. if ($has_qian <= 6) {
  1312. $get_score = $score[$has_qian - 1];
  1313. } else {
  1314. $get_score = $scoreS;
  1315. if (isset($scoreExtra[$has_qian])) {
  1316. $get_score = $scoreS + $scoreExtra[$has_qian];
  1317. }
  1318. }
  1319. $userRepository = app()->make(UserRepository::class);
  1320. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '');
  1321. //首次签到
  1322. if ($user['first_sign'] == 0) {
  1323. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  1324. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  1325. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  1326. }
  1327. //非首次签到,第一天,断签
  1328. //好友连续签到3天 奖励50
  1329. //好友连续签到14天 奖励100
  1330. //好友联系签到30天 奖励300
  1331. if ($user['first_sign'] < 2) {
  1332. if ($has_qian == 3) {
  1333. $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  1334. } elseif ($has_qian == 14) {
  1335. $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  1336. } elseif ($has_qian == 30) {
  1337. $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  1338. Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  1339. }
  1340. }
  1341. return app('json')->success('签到成功', ['score' => $get_score]);
  1342. }
  1343. }
  1344. public function new_sign_info()
  1345. {
  1346. $uid = $this->request->uid();
  1347. //查询今天是否已经签到
  1348. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  1349. //查询昨天是否已经签到了
  1350. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  1351. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  1352. $data = [
  1353. 'today' => 0,
  1354. 'day' => 0
  1355. ];
  1356. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  1357. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  1358. if ($today_signin_info) {
  1359. $data['today'] = 1;
  1360. $data['day'] = $data['day'] + 1;
  1361. }
  1362. return app('json')->success($data);
  1363. }
  1364. /**
  1365. * 积分列表
  1366. * @return mixed
  1367. * @throws \think\db\exception\DataNotFoundException
  1368. * @throws \think\db\exception\DbException
  1369. * @throws \think\db\exception\ModelNotFoundException
  1370. */
  1371. public function sign_list()
  1372. {
  1373. [$page, $limit] = $this->getPage();
  1374. $uid = $this->request->uid();
  1375. $month = $this->request->param('month', '') ?: date('Y-m');
  1376. $status = $this->request->param('status');
  1377. $pm = $this->request->param('pm');
  1378. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  1379. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  1380. $count = Db::name('user_sign_score')
  1381. ->whereBetween('addtime', [$startMonth, $endMonth])
  1382. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  1383. $query->where('status', $status);
  1384. })
  1385. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  1386. $query->where('pm', $pm);
  1387. })
  1388. ->where('uid', $uid)->count();
  1389. $list = Db::name('user_sign_score')
  1390. ->whereBetween('addtime', [$startMonth, $endMonth])
  1391. ->where('uid', $uid)
  1392. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  1393. $query->where('status', $status);
  1394. })
  1395. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  1396. $query->where('pm', $pm);
  1397. })
  1398. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  1399. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  1400. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  1401. if (!empty($item['order_id'])) {
  1402. //线上订单
  1403. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  1404. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  1405. } elseif ($item['order_type'] == 'order_merchant') {
  1406. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  1407. } elseif ($item['order_type'] == 'extract') {
  1408. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  1409. } else {
  1410. $item['order_sn'] = '';
  1411. }
  1412. } else {
  1413. $item['order_sn'] = '';
  1414. }
  1415. return $item;
  1416. });
  1417. $data['list'] = $list;
  1418. $data['count'] = $count;
  1419. return app('json')->success($data);
  1420. }
  1421. public function getAmountFromGzc()
  1422. {
  1423. $uid = $this->request->uid();
  1424. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  1425. $res = GzcApiRequest::checkAmount($userInfo);
  1426. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  1427. }
  1428. public function check_user_annual_fee()
  1429. {
  1430. //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  1431. //UPDATE `renrenxiang`.`rrx_user_pension_account` SET `start_time` = '2023-04-07 00:00:00', `end_time` = '2024-04-07 23:59:59', `status` = 1, `give` = 1 WHERE `id` > 0;
  1432. $uid = $this->request->uid();
  1433. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  1434. $data = [
  1435. "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常
  1436. ];
  1437. // //未交年费
  1438. // if (!$check || $check["status"] == 0) {
  1439. // $data["status"] = 0;
  1440. // return app('json')->success($data);
  1441. // }
  1442. // //到期时间小于当前时间。年费到期
  1443. // if (strtotime($check['end_time']) < time()){
  1444. // $data["status"] = 1;
  1445. // return app('json')->success($data);
  1446. // }
  1447. // $data["start_time"] = $check['start_time'];
  1448. // $data["end_time"] = $check['end_time'];
  1449. //
  1450. // //检查实名认证
  1451. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  1452. // if (!$checkCertification){
  1453. // $data["status"] = 2;
  1454. // return app('json')->success($data);
  1455. // }
  1456. return app('json')->success($data);
  1457. }
  1458. /**
  1459. *
  1460. * @remarks 创建年费订单
  1461. * @author 小菜菜
  1462. * @created 2023/04/10 14:37
  1463. */
  1464. public function create_annual_order()
  1465. {
  1466. $uid = $this->request->uid();
  1467. $type = $this->request->param('type', 1);
  1468. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1469. if ($type == 1) $price = "12.00";
  1470. elseif ($type == 2) $price = systemConfig('offline_a');
  1471. elseif ($type == 3) $price = systemConfig('offline_b');
  1472. elseif ($type == 4) $price = systemConfig('offline_c');
  1473. else return app('json')->fail("参数错误");
  1474. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  1475. //到期时间小于当前时间。年费到期
  1476. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  1477. return app('json')->fail("账户已开通,不可重复开通账户");
  1478. }
  1479. $insertData = [
  1480. 'pay_price' => $price,
  1481. 'status' => 0,
  1482. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  1483. 'uid' => $uid,
  1484. 'type' => $type,
  1485. ];
  1486. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  1487. try {
  1488. return app('json')->success(['order_id' => $order_id]);
  1489. } catch (\Exception $e) {
  1490. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  1491. }
  1492. }
  1493. /**
  1494. * @remarks 会员支付
  1495. * @author Tang
  1496. * @created 2021/8/27 9:18
  1497. */
  1498. public function pay_user_annual()
  1499. {
  1500. try {
  1501. $oid = r::param('oid', '');
  1502. $code = r::param('code', '');
  1503. $payType = r::param('type', '');//wx.ALI
  1504. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  1505. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  1506. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  1507. $access = new Access();
  1508. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  1509. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  1510. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  1511. return app('json')->success($res);
  1512. } catch (\Exception $exception) {
  1513. return app('json')->fail();
  1514. }
  1515. }
  1516. /**
  1517. * @remarks 会员支付 线下
  1518. * @author Tang
  1519. * @created 2021/8/27 9:18
  1520. */
  1521. public function pay_user_annual_offline()
  1522. {
  1523. try {
  1524. $oid = r::param('oid', '');
  1525. $payType = r::param('type', '');//WX.ALI
  1526. $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id
  1527. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  1528. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  1529. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  1530. if (!$order) return app('json')->fail('订单不存在或已支付');
  1531. if ($order['type'] == 1) {
  1532. $title = "开通账户";
  1533. } elseif ($order['type'] == 2) {
  1534. $title = "大礼包1";
  1535. } elseif ($order['type'] == 3) {
  1536. $title = "大礼包2";
  1537. } elseif ($order['type'] == 4) {
  1538. $title = "大礼包3";
  1539. } else {
  1540. return app('json')->fail('订单异常');
  1541. }
  1542. if ($order['type'] > 1) {
  1543. //本人给养老金10%
  1544. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金
  1545. $commission = 0;
  1546. //上级给佣金10%
  1547. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  1548. //推广员id
  1549. $spread_uid = $order_user["spread_uid"];
  1550. if (!empty($spread_uid)) {
  1551. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金
  1552. }
  1553. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  1554. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  1555. } else {
  1556. $pt = "12.00";
  1557. $merchant_money = "0.00";
  1558. }
  1559. if ($payType == 'WX') {
  1560. $pay_wx = systemConfig('pay_wx');
  1561. //微信
  1562. if ($pay_wx == 3) {
  1563. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  1564. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1565. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  1566. } else {
  1567. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  1568. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1569. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  1570. }
  1571. $type = '2';
  1572. $pay_channel = 'wx_pub';
  1573. $expend = [
  1574. 'open_id' => $pay_user_id
  1575. ];
  1576. } elseif ($payType == 'ALI') {
  1577. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  1578. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  1579. $type = '1';
  1580. $pay_channel = 'alipay_pub';
  1581. $expend = [
  1582. 'buyer_id' => $pay_user_id
  1583. ];
  1584. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  1585. }
  1586. if ($merchant_money == '0.00') {
  1587. $div_members = [
  1588. [
  1589. 'member_id' => 0,
  1590. 'amount' => $pt,
  1591. 'fee_flag' => 'Y'
  1592. ]
  1593. ];
  1594. } else {
  1595. $div_members = [
  1596. [
  1597. 'member_id' => $member_id,
  1598. 'amount' => $merchant_money,
  1599. 'fee_flag' => 'Y'
  1600. ],
  1601. [
  1602. 'member_id' => 0,
  1603. 'amount' => $pt,
  1604. 'fee_flag' => 'N'
  1605. ]
  1606. ];
  1607. }
  1608. $params = [
  1609. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  1610. 'app_id' => $app_id,
  1611. 'pay_channel' => $pay_channel,
  1612. 'pay_amt' => (string)$order['pay_price'],
  1613. 'goods_title' => "储蓄保",
  1614. 'goods_desc' => $title,
  1615. 'device_info' => [
  1616. 'device_ip' => app('request')->ip()
  1617. // 'device_ip'=>'115.171.134.68'
  1618. ],
  1619. 'expend' => json_encode($expend),
  1620. 'div_members' => json_encode($div_members),
  1621. 'fee_mode' => 'I',
  1622. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  1623. ];
  1624. $res = $this->Payment_create_traits($params, $type, $key);
  1625. if (!empty($res['error_code'])) {
  1626. return app('json')->fail($res['return_msg']);
  1627. } else {
  1628. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  1629. return app('json')->success($res);
  1630. }
  1631. } catch (\Exception $exception) {
  1632. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  1633. return app('json')->fail();
  1634. }
  1635. }
  1636. public function red_log()
  1637. {
  1638. $uid = $this->request->uid();
  1639. [$page, $limit] = $this->getPage();
  1640. $user_rich_log = Db::name('user_rich_log')->where('uid', $uid)->field('uid,red,pm,time,mark')->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  1641. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  1642. $item['red'] = set_price_rtrim($item['red']);
  1643. return $item;
  1644. });
  1645. return app('json')->success($user_rich_log);
  1646. }
  1647. public function apply_bang_fu()
  1648. {
  1649. $uid = $this->request->uid();
  1650. $check = Db::name('user_rich')->where('uid', $uid)->find();
  1651. if ($check['type'] < 3) {
  1652. return app('json')->fail("不满足申请条件");
  1653. }
  1654. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  1655. if ($check == 0) {
  1656. return app('json')->fail("审核中");
  1657. }
  1658. if ($check == 1) {
  1659. return app('json')->fail("已是帮扶中心");
  1660. }
  1661. if ($check == 2) {
  1662. return app('json')->fail("审核被拒绝");
  1663. }
  1664. $bang_fu_number = systemConfig("bang_fu_number");
  1665. //检测用户是否满足条件
  1666. $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己
  1667. //条件
  1668. if ($number >= $bang_fu_number) {
  1669. // echo '满足';
  1670. Db::name('user_bangfu')->insert([
  1671. 'uid' => $uid,
  1672. 'time' => time(),
  1673. 'status' => 0
  1674. ]);
  1675. return app('json')->success("提交申请成功");
  1676. }
  1677. return app('json')->fail("不满足申请条件");
  1678. // echo '不满足';
  1679. }
  1680. //获得满足 1+5 的下级数量
  1681. public function getNumber($uid, $bang_fu_number): int
  1682. {
  1683. $number = 0;
  1684. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  1685. $count = count($getUid);
  1686. if ($count >= 5) {
  1687. $number = 1;
  1688. foreach ($getUid as $value) {
  1689. $number += $this->getNumber($value['uid'], $bang_fu_number);
  1690. if ($number >= $bang_fu_number) {
  1691. break;
  1692. }
  1693. }
  1694. }
  1695. return $number;
  1696. }
  1697. /**
  1698. * 积分明细
  1699. * @return mixed
  1700. */
  1701. public function score_info()
  1702. {
  1703. $uid = $this->request->uid();;
  1704. $data['score'] = decimal2(Db::name('user_sign_score')
  1705. ->where('uid', $uid)
  1706. ->where('status', 1)
  1707. ->where('pm', 1)
  1708. ->sum('reward_socre'));;
  1709. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  1710. ->where('uid', $uid)
  1711. ->where('status', -1)
  1712. ->where('pm', 1)
  1713. ->sum('reward_socre'));
  1714. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  1715. ->where('uid', $uid)
  1716. ->where('pm', 2)
  1717. ->sum('reward_socre'));
  1718. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  1719. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  1720. $data['score'] = decimal2($data['score']);
  1721. Db::name('user')->where('uid', $uid)->update([
  1722. 'score' => $score
  1723. ]);
  1724. //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  1725. return app('json')->success($data);
  1726. }
  1727. /**
  1728. * 新版我的团队
  1729. */
  1730. public function get_team_list()
  1731. {
  1732. $data = [];
  1733. [$page, $limit] = $this->getPage();
  1734. $uid = $this->request->uid();
  1735. $type = intval($this->request->param('type'));
  1736. //查询团队列表
  1737. $userRepository = app()->make(UserRepository::class);
  1738. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  1739. $data['fans_count'] = count($chilid_userids);
  1740. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  1741. $data['direct_count'] = count($direct_uid_list);
  1742. $valid_uid_list = Db::name('store_order')
  1743. ->whereIn('uid', $chilid_userids)
  1744. ->where('paid', 1)
  1745. ->group('uid')
  1746. ->column('uid');
  1747. $data['valid_count'] = count($valid_uid_list);
  1748. $data['count'] = Db::name('user')
  1749. ->whereIn('uid', $chilid_userids)
  1750. ->count();
  1751. $data['list'] = Db::name('user')
  1752. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  1753. ->page($page, $limit)
  1754. ->whereIn('uid', $chilid_userids)
  1755. ->when($type == 1, function ($query) use ($direct_uid_list) {
  1756. return $query->whereIn('uid', $direct_uid_list);
  1757. })
  1758. ->when($type == 2, function ($query) use ($valid_uid_list) {
  1759. return $query->whereIn('uid', $valid_uid_list);
  1760. })
  1761. ->order('uid DESC')
  1762. ->select()
  1763. ->toArray();
  1764. foreach ($data['list'] as &$user) {
  1765. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  1766. }
  1767. return app('json')->success($data);
  1768. }
  1769. /**
  1770. * 我的粉丝详情
  1771. */
  1772. public function get_team_info()
  1773. {
  1774. $uid = $this->request->param('uid', '');
  1775. if (!$uid)
  1776. return app('json')->fail("uid不正确");
  1777. $userRepository = app()->make(UserRepository::class);
  1778. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  1779. if (!in_array($uid, $chilid_userids))
  1780. return app('json')->fail("该用户不在所属团队内");
  1781. $data = Db::name('user')
  1782. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  1783. ->where('uid', $uid)
  1784. ->find();
  1785. $data['regimental_commander_count'] = Db::name('user')
  1786. ->where('spread_uid', $uid)
  1787. ->where('user_group', 2)
  1788. ->count();
  1789. $data['clear_order_amount'] = Db::name('store_order')
  1790. ->where('uid', $uid)
  1791. ->where('is_settlement', 1)
  1792. ->sum('pay_price');
  1793. $data['mybuy_order_amount'] = Db::name('store_order')
  1794. ->where('uid', $uid)
  1795. ->where('paid', 1)
  1796. ->sum('pay_price');
  1797. $spread_user = Db::name('user')
  1798. ->field('nickname as spread_nickname,phone as spread_phone')
  1799. ->where('uid', $data['spread_uid'])
  1800. ->find();
  1801. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  1802. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  1803. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  1804. $data = array_merge($data, $spread_user);
  1805. if (in_array($data['user_group'], [5, 6])) {
  1806. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  1807. $data['area_name'] = join($data['area_name']);
  1808. $data['area_bonus_money'] = Db::name('user_bill')
  1809. ->where('uid', $uid)
  1810. ->sum('number');
  1811. }
  1812. unset($data['manage_address']);
  1813. if (in_array($data['user_group'], [4])) {
  1814. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  1815. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  1816. $data['mer_name'] = $merchant['mer_name'] ?? '';
  1817. }
  1818. return app('json')->success($data);
  1819. }
  1820. /**
  1821. * 我的佣金
  1822. */
  1823. public function get_brokerage_info()
  1824. {
  1825. $uid = $this->request->uid();
  1826. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  1827. $data['sum_amount'] = Db::name('user_bill')
  1828. ->where('uid', $uid)
  1829. ->where('commission_type', '<>', 5)
  1830. ->where('pm', 1)
  1831. ->sum('number');
  1832. $data['no_clear_amount'] = Db::name('user_bill')
  1833. ->where('uid', $uid)
  1834. ->where('commission_type', '<>', 5)
  1835. ->where('pm', 1)
  1836. ->where('status', 0)
  1837. ->sum('number');
  1838. $data['withdraw_amount'] = Db::name('user_extract')
  1839. ->where('uid', $uid)
  1840. ->whereIn('status', [0, 1])
  1841. ->sum('extract_price');
  1842. return app('json')->success($data);
  1843. }
  1844. public function get_token_by_phone(UserRepository $repository){
  1845. $user = $repository->accountByUser($this->request->param('phone'));
  1846. $tokenInfo = $repository->createToken($user);
  1847. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1848. }
  1849. }