User.php 75 KB

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