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