User.php 83 KB

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