User.php 94 KB

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