Auth.php 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-06
  7. *
  8. *
  9. */
  10. namespace app\controller\api;
  11. use AlibabaCloud\Client\AlibabaCloud;
  12. use app\common\dao\store\order\StoreOrderDao;
  13. use app\common\model\user\User;
  14. use app\common\repositories\merchant\order\OrderGzcRepository;
  15. use app\common\repositories\merchant\order\OrderMerchantRepository;
  16. use app\common\repositories\store\order\StoreGroupOrderRepository;
  17. use app\common\repositories\store\order\StoreOrderRepository;
  18. use app\common\repositories\store\order\StoreOrderStatusRepository;
  19. use app\common\repositories\store\order\StoreRefundOrderRepository;
  20. use app\common\repositories\user\UnionUsersRepository;
  21. use app\common\repositories\user\UserRepository;
  22. use app\common\repositories\wechat\RoutineQrcodeRepository;
  23. use app\common\repositories\wechat\WechatUserRepository;
  24. use app\controller\api\user\Volunteer;
  25. use app\controller\api\util\Signature;
  26. use app\models\routine\RoutineQrcode;
  27. use app\traits\GongApiRequest;
  28. use app\traits\GzcApiRequest;
  29. use app\traits\HaikeApiRequest;
  30. use app\traits\HuiPay;
  31. use app\validate\api\UserAuthValidate;
  32. use Carbon\Carbon;
  33. use crmeb\basic\BaseController;
  34. use crmeb\services\AliYunSmsService;
  35. use crmeb\services\MiniProgramService;
  36. use crmeb\services\WechatService;
  37. use crmeb\services\YunxinSmsService;
  38. use applet\WXBizDataCrypt;
  39. use Gregwar\Captcha\CaptchaBuilder;
  40. use Gregwar\Captcha\PhraseBuilder;
  41. use PhpOffice\PhpSpreadsheet\IOFactory;
  42. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  43. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  44. use Symfony\Component\HttpFoundation\Request;
  45. use think\App;
  46. use think\db\exception\DataNotFoundException;
  47. use think\db\exception\DbException;
  48. use think\db\exception\ModelNotFoundException;
  49. use think\Env;
  50. use think\Exception;
  51. use think\exception\HttpResponseException;
  52. use think\facade\Cache;
  53. use think\facade\Db;
  54. use think\facade\Log;
  55. use think\Filesystem;
  56. use think\Response;
  57. /**
  58. * Class Auth
  59. * @package app\controller\api
  60. * @author xaboy
  61. * @day 2020-05-06
  62. */
  63. class Auth extends BaseController
  64. {
  65. use HaikeApiRequest;
  66. use HuiPay;
  67. protected $merId;
  68. protected $source;
  69. public function __construct(App $app)
  70. {
  71. parent::__construct($app);
  72. $this->source = $this->request->header('source');
  73. $this->merId = $this->request->header('merId');
  74. }
  75. /**
  76. * 计算国盛小程序市场管理分红
  77. */
  78. public function gscm($mer_id=1){
  79. // $enterprise=Db::name('enterprise')->where('type',1)->select();
  80. $enterprise=Db::name('enterprise')->where('mer_id',$mer_id)->where('type',1)->find();
  81. if(!$enterprise){
  82. return false;
  83. }
  84. $reward[6]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',6)->column('uid');
  85. $reward[5]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',5)->column('uid');
  86. $reward[4]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',4)->column('uid');
  87. $reward[3]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',3)->column('uid');
  88. $reward[2]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',2)->column('uid');
  89. $reward[1]=Db::name('enterprise_user')->where('mer_id',$mer_id)->where('identity',1)->column('uid');
  90. // $uids = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2],$reward[1]);
  91. $uids_money=[];
  92. $enterprise_money=Db::name('enterprise_bill')->where('mer_id',$mer_id)->sum('money');
  93. $amoney=$enterprise_money*0.05;
  94. $divvy=decimal2($amoney*0.3);//平均分红
  95. $jiaquan_divvy=$amoney-$divvy;//加权分红
  96. //平均分红金额不足每人0.01 就不分了
  97. if($divvy > 0 || decimal2($divvy/(count($reward[6])*6+count($reward[5])*5+count($reward[4])*4+count($reward[3])*3+count($reward[2])*2+count($reward[1]))) > 0 ){
  98. //0-普通用户 1-微店 2-云店 3-旗舰店 4-消费合伙人 5-创业合伙人 6-股东合伙人
  99. for ($i=6;$i>0;$i--) {
  100. if ($i == 6) {
  101. $mergedArray = $reward[6];
  102. }elseif($i==5){
  103. $mergedArray = array_merge($reward[6],$reward[5]);
  104. }elseif($i==4){
  105. $mergedArray = array_merge($reward[6],$reward[5],$reward[4]);
  106. }elseif($i==3){
  107. $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3]);
  108. }elseif($i==2){
  109. $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2]);
  110. }else{
  111. $mergedArray = array_merge($reward[6],$reward[5],$reward[4],$reward[3],$reward[2],$reward[1]);
  112. }
  113. $fenhong=decimal2($divvy/count($mergedArray));
  114. foreach ($mergedArray as $v){
  115. if(!isset($uids_money[$v])){
  116. $uids_money[$v]=$fenhong;
  117. }else{
  118. $uids_money[$v]+=$fenhong;
  119. }
  120. }
  121. }
  122. dump($uids_money);
  123. }
  124. }
  125. function jisuantuandui($where,$data=[]){
  126. $enterprise_user_team=DB::name('enterprise_user')->where($where)->column('uid');
  127. $arr=array_merge($data,$enterprise_user_team);
  128. foreach ($enterprise_user_team as $v){
  129. $where['node_uid']=$v;
  130. $arr=$this->jisuantuandui($where,$arr);
  131. }
  132. return $arr;
  133. }
  134. public function importExcel()
  135. {
  136. $file = request()->file('file');
  137. // 创建一个新的Excel读取器对象
  138. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  139. $objPHPExcel = $objReader->load($file);
  140. // 选择活动工作表
  141. $objPHPExcel->setActiveSheetIndex(0);
  142. $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
  143. // 循环遍历行和列
  144. $yonghu=[];
  145. foreach ($sheetData as $k=>$row) {
  146. if($k==1){
  147. continue;
  148. }
  149. if($row['A'] && $row['A']!=NULL && $row['A']!=''){
  150. $yonghu[]=array('a'=>$row['A'],'b'=>$row['B']);
  151. }
  152. }
  153. $repository = app()->make(UserRepository::class);
  154. foreach ($yonghu as $k=>$v){
  155. $user = $repository->accountByUser($v['a']);
  156. if ($user){
  157. // return app('json')->fail('手机号已存在');
  158. $yonghu[$k]['user'] = $user;
  159. }else{
  160. $yonghu[$k]['user'] = $repository->registr($v['a'],'A123456','APP',0);
  161. }
  162. }
  163. foreach ($yonghu as $v){
  164. $user=$v['user'];
  165. if($v['b'] && $v['b']!=null && $v['b']!=''){
  166. $pid=Db::name('user')->where('account',$v['b'])->value('uid');
  167. if($pid){
  168. $repository->bindSpread($user, intval($pid));
  169. }
  170. }
  171. }
  172. }
  173. public function test()
  174. {
  175. $this->importExcel();
  176. echo '导入成功';
  177. die;
  178. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  179. // $storeOrderRepository->yihuchashengji();//一壶茶身份升级
  180. // $storeOrderRepository->yunyingjiangli();//运营中心奖励
  181. // $storeOrderRepository->yihuchafenxiang();//一壶茶分红逻辑memberSettings
  182. // $this->jinjian();die;
  183. var_dump(11);
  184. die;
  185. $order_id = (int)$this->request->param('id');
  186. $order=Db::name('store_order')->find($order_id);
  187. if(!$order){
  188. return '订单不存在';
  189. }
  190. //在rrx_store_order_product 表中查到product_id ,在rrx_store_product 查spu_id 在rrx_douhuomall表中查goods_id
  191. $out_order_no=$order['douhuomall_order_no'];
  192. $after_type='1';//1=未收货退款,2=退货退款,3=换货补发,4=不退货仅退款
  193. $explain='测试退货';
  194. $can_after_data=GongApiRequest::is_can_after( $out_order_no);
  195. dump($can_after_data);
  196. if(isset($can_after_data['result']['order_goods'])){
  197. foreach ($can_after_data['result']['order_goods'] as $v){
  198. $order_goods_id=$v['order_goods_id'];
  199. $after_num=$v['after_num'];
  200. $res=GongApiRequest::apply_after_sales( $order_goods_id,$out_order_no, $after_type, $explain, $after_num);
  201. dump($res);
  202. }
  203. }
  204. //
  205. // $storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
  206. // $res=$storeGroupOrderRepository->ProductOutCancel(6105);
  207. // $res = GongApiRequest::order_details('wx1698916402673749101');
  208. $res2=GongApiRequest::after_status_new($out_order_no);
  209. dump($res2);
  210. // dump($repository->getBangFu(9640));
  211. // dump($userRepository -> getCountUId(18));
  212. // echo '开发者测试';
  213. // echo systemConfig("pay_wx");
  214. // $res = [
  215. // "completeDateTime"=>"2022-05-31 14:27:09",
  216. // "remark"=>"1",
  217. // "orderAmount"=>"100",
  218. // "merchantId"=>"899104033",
  219. // "requestId"=>"wx1653980751822534740_5366",
  220. // "hmac"=>"yivznJKbCfPpnXpwsalGDz7tnRyjr9pqbeVSkVKZ5VvtnJqn4helUkGC+S2tsaF8oknwvN\/ZeoDcgtRPqT1uanOWyalSFip6qxkBDkbc\/sJBVMCR2vzp38+YEHbusuxH1O9D696bt\/PSuhFjItD9pFi+Qteha1zN8X4oxpWFEob4wOVcFnMHLkgehNoWy1NRqjz+RmD6osAzJrIS27RJmUaqt83e0ejcjfEzAEw74rq4Yafyx9PohjvF35iwVLCpOcdyxVsfuJ4D59ayqsgUs0\/80GMRvNkgXrO6bsN7m1t6PLSQgPkD6ruEX\/i4l4uhrpHLvnpc4wl9YsGS1k4SrQ==",
  221. // "clearingOrg"=>"UNION_PAY",
  222. // "totalRefundCount"=>"0",
  223. // "serialNumber"=>"ddd",
  224. // "realBankSerialNumber"=>"4200001429202205315964134213",
  225. // "orderCurrency"=>"CNY",
  226. // "realBankRequestNumber"=>"1531522625975881728N",
  227. // "totalRefundAmount"=>"0",
  228. // "paymentModeAlias"=>"MINIAPPS_WEIXIN_PAY",
  229. // "status"=>"SUCCESS"
  230. // ];
  231. // $requestId = [];
  232. // if(strpos($res['requestId'],'_') !== false){
  233. // $requestId = explode("_",$res['requestId']);
  234. // }
  235. // if($res['status'] == 'SUCCESS'){
  236. // Db::name('store_group_order') -> where('group_order_sn',$requestId[0]) -> update(['rand'=>$requestId[1],'serialNumber'=>$res['serialNumber']]);
  237. // $pay_type = $res['paymentModeAlias'] == 'MINIAPPS_WEIXIN_PAY' ? 1 : 4;
  238. // event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
  239. // }
  240. // Db::name('test') -> insert(['date'=>date('Y-m-d H:i:s')]);
  241. // try {
  242. // $merch_no = $this->request->param('merch_no');
  243. // $mer_name = $this->request->param('mer_name');
  244. // $mer_short_name = $this->request->param('mer_short_name');
  245. // $response = $this->merchantModify(['merch_no' => $merch_no,'mer_name' => $mer_name, 'mer_short_name' => $mer_short_name,'agent_apply_no' => (string)time()]);
  246. // return app('json')->success($response);
  247. // } catch (\Throwable $e) {
  248. // return app('json')->fail($e->getMessage());
  249. // }
  250. }
  251. //商户进件
  252. private function jinjian(){
  253. // $returndata=[
  254. // 'request_id'=>time().rand(111111,999999),
  255. // 'usr_phone'=>'15732652759',
  256. // 'cont_name'=>'吴国珍',
  257. // 'cont_phone'=>'13911251783',
  258. // 'customer_email'=>'312009092@qq.com',
  259. // 'mer_name'=>'北京天地博爱科技有限公司',
  260. // 'mer_short_name'=>'天地博爱科技',
  261. // 'reg_addr'=>'北京市北京经济技术开发区科创十三街31号院二区14号楼9层901-3(北京自贸试验区高端产业片区亦庄组团)',
  262. // 'cust_addr'=>'北京市北京经济技术开发区科创十三街31号院二区14号楼9层901-3(北京自贸试验区高端产业片区亦庄组团)',
  263. // 'cust_tel'=>'010-53327000',
  264. // 'legal_name'=>'吴国珍',
  265. // 'legal_type'=>0,
  266. // 'legal_idno'=>'321123196710192020',
  267. // 'legal_mp'=>'13911251783',
  268. // 'legal_start_cert_id_expires'=>'20061129',
  269. // 'legal_id_expires'=>'20261129',
  270. // 'card_id_mask'=>'629966688',
  271. // 'card_name'=>'北京天地博爱科技有限公司',
  272. // 'bank_acct_type'=>'1',
  273. // 'bank_code'=>'03050000',
  274. // 'prov_code'=>'0011',//省份编码 (省市编码),
  275. // 'area_code'=>'1100',//地区编码 (省市编码)
  276. // 'license_code'=>'91110105697724649E',
  277. // 'mer_valid_date'=>'20291118',
  278. // 'mer_start_valid_date'=>'20091119',
  279. // 'entry_mer_type'=>'1',
  280. // 'rsa_public_key'=>'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTpMESsdhyjKQC+y1G++eXCEu5pXqK7fvkZJdubSTCQn/RM3soOMcCwTekULCxEUwM0SnPxFLcZuP/a8w87zWeAXoBCPJl1gVK4KZ+3tWq/BJPCET3Vy66M7pXfXL+ekd8gf2LWtEfpJoAn59guVfsbTOp44ppDkrb3SuXDcKhQIDAQAB'
  281. // ];
  282. $returndata=[
  283. 'request_id'=>time().rand(111111,999999),
  284. 'usr_phone'=>'13911251783',//注册手机号
  285. 'cont_name'=>'陈立军',//联系人姓名
  286. 'cont_phone'=>'13911251783',//联系人手机号码
  287. 'customer_email'=>'312009092@qq.com',//电子邮箱
  288. 'mer_name'=>'河北省一壶茶电子商务有限公司',//商户名称
  289. 'mer_short_name'=>'一壶茶电子商务',//商户简称 商户简称,长度为10个中文
  290. 'reg_addr'=>'河北省秦皇岛市经济技术开发区华山中路8号银通大厦',//注册地址
  291. 'cust_addr'=>'河北省秦皇岛市经济技术开发区华山中路8号银通大厦',//经营地址
  292. 'cust_tel'=>'010-53327000',//商户电话
  293. 'legal_name'=>'陈立军',//法人/负责人 姓名
  294. 'legal_type'=>0,//法人/负责人证件号码
  295. 'legal_idno'=>'130302196709281432',//法人/负责人证件号码
  296. 'legal_mp'=>'13911251783',//法人/负责人手机号
  297. 'legal_start_cert_id_expires'=>'20230310',//法人/负责人身份证有效期(始),格式 YYYYMMDD
  298. 'legal_id_expires'=>'20991231',//法人/负责人身份证有效期(至),格式 YYYYMMDD
  299. 'card_id_mask'=>'13050163560800002447',//结算银行卡号
  300. 'card_name'=>'河北省一壶茶电子商务有限公司',//结算银行卡开户姓名
  301. 'bank_acct_type'=>'1',//结算银行账户类型,1 : 对公, 2 : 对私。小微只能是对私
  302. 'bank_code'=>'01050000',//结算银行卡所属银行code
  303. 'prov_code'=>'0013',//结算银行卡省份编码,
  304. 'area_code'=>'1308',//结算银行卡省份编码
  305. 'license_code'=>'91130301MAD48PT00A',//营业执照编码
  306. 'mer_valid_date'=>'20991231',//商户有效日期(至),格式 YYYYMMDD(若为长期有效,固定为“20991231”;若开户企业类商户,必填)
  307. 'mer_start_valid_date'=>'20231107',//商户有效日期(至),格式 YYYYMMDD(若为长期有效,固定为“20991231”;若开户企业类商户,必填)
  308. 'entry_mer_type'=>'1',//商户类型:1-企业;2-小微。默认为企业
  309. 'rsa_public_key'=>'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxTpMESsdhyjKQC+y1G++eXCEu5pXqK7fvkZJdubSTCQn/RM3soOMcCwTekULCxEUwM0SnPxFLcZuP/a8w87zWeAXoBCPJl1gVK4KZ+3tWq/BJPCET3Vy66M7pXfXL+ekd8gf2LWtEfpJoAn59guVfsbTOp44ppDkrb3SuXDcKhQIDAQAB'
  310. ];
  311. dump($returndata);
  312. $arr= $this->incoming_parts($returndata,'config');
  313. dump($arr);die;
  314. }
  315. /**
  316. * 业绩奖-服务中心分红-发放
  317. * @return mixed
  318. */
  319. public function yihuchafenxiang(){
  320. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  321. $storeOrderRepository->yihuchafenxiang();
  322. $storeOrderRepository->yunyingjiangli();
  323. return app('json')->success('业绩奖-服务中心分红-运营中心-发放完成');
  324. }
  325. /**
  326. * 一壶茶身份升级
  327. * @return mixed
  328. */
  329. public function yihuchashengji(){
  330. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  331. $storeOrderRepository->yihuchashengji();
  332. return app('json')->success('一壶茶身份升级-完成');
  333. }
  334. public function shareImgesList(){
  335. $where['mer_id']=$this->merId;
  336. $where['status']=0;
  337. $classify=$this->request->param('classify',0);
  338. if($classify){
  339. $where['classify']=$classify;
  340. }
  341. $pageNum=$this->request->param('pageNum',1);
  342. $limit=$this->request->param('pageSize',10);
  343. $type=$this->request->param('type',0);
  344. if($type){
  345. $where['type']=$type;
  346. }
  347. $data['pageInfo']['list']=Db::name('share_posters')->where($where)->page($pageNum,$limit)->order('sort desc,id desc')->select();
  348. $data['pageInfo']['total']=Db::name('share_posters')->where($where)->count();
  349. return app('json')->success($data);
  350. }
  351. public function classifyList(){
  352. $data=Db::name('share_posters_classify')->field('id,name')->where('mer_id',$this->merId)->where('is_del',0)->order('sort desc,id desc')->select();
  353. return app('json')->success($data);
  354. }
  355. public function agreement_detail(){
  356. $type = $this->request->param('type',1);
  357. // $where['mer_id']=$this->merId;
  358. $where['type']=$type;
  359. $data=Db::name('enterprise_agreement')->where($where)->find();
  360. if(!$data){
  361. $data['title']='';
  362. $data['content']='';
  363. }
  364. return app('json')->success($data);
  365. }
  366. public function agreement(){
  367. $type = $this->request->param('type',1);
  368. // $where['mer_id']=$this->merId;
  369. $where['type']=$type;
  370. $data=Db::name('enterprise_agreement')->where($where)->find();
  371. if(!$data){
  372. $data['title']='';
  373. $data['content']='';
  374. }
  375. $html='<!DOCTYPE html>
  376. <html lang="en">
  377. <head>
  378. <meta charset="UTF-8">
  379. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  380. <title>'.$data['title'].'</title>
  381. <style>
  382. body {
  383. font-family: Arial, sans-serif;
  384. margin: 0;
  385. padding: 0;
  386. }
  387. .container {
  388. margin: 0 auto;
  389. padding: 20px;
  390. }
  391. </style>
  392. </head>
  393. <body>
  394. <div class="container">
  395. '.$data['content'].'
  396. </div>
  397. </body>
  398. </html';
  399. return $html;
  400. }
  401. /**
  402. * @param UserRepository $repository
  403. * @return mixed
  404. * @throws DbException
  405. * @author xaboy
  406. * @day 2020/6/1
  407. */
  408. public function login(UserRepository $repository)
  409. {
  410. $account = $this->request->param('phone');
  411. if (!$account)
  412. return app('json')->fail('请输入账号');
  413. $user = $repository->accountByUser($this->request->param('phone'));
  414. //13231658486 周总 张玉庭 13839803521 13083849831
  415. if($account != 13231658486){
  416. if (!$user)
  417. return app('json')->fail('账号或密码错误');
  418. if (!password_verify($pwd = (string)$this->request->param('password'), $user['pwd']))
  419. return app('json')->fail('账号或密码错误');
  420. $type = $this->request->param('type',0);
  421. if ($type==2){
  422. if ($user["identity"]==0||$user["identity"]==4||$user["identity"]==5){
  423. return app('json')->fail('账号或密码错误');
  424. }
  425. }
  426. }
  427. $user = $repository->mainUser($user);
  428. $pid = $this->request->param('spread', 0);
  429. $repository->bindSpread($user, intval($pid));
  430. $tokenInfo = $repository->createToken($user);
  431. $repository->loginAfter($user);
  432. return app('json')->success($repository->returnToken($user, $tokenInfo));
  433. }
  434. /**
  435. * 手机号注册
  436. * @param UserRepository $repository
  437. * @return mixed
  438. * @throws DbException
  439. * @author xaboy
  440. * @day 2020/6/1
  441. */
  442. public function register(UserAuthValidate $validate, UserRepository $repository)
  443. {
  444. // $repository->insterUser(16328, 14395);
  445. // return "=====";
  446. $data = $this->request->params(['phone', 'sms_code', 'spread', 'password',"spread_phone","type","mer_id"]);
  447. $type=$data['type']??'';
  448. unset($data['type']);
  449. $validate->sceneSmslogin()->check($data);
  450. $domain = $this->request->domain();
  451. if($data['sms_code'] == '6865' && strpos($domain, 'test.hebeiyhc.com') !== false) {
  452. // 域名中包含 "test.hebeiyhc.com'" 字符串
  453. }else if (!$this->checkSmsCode($data['phone'], $data['sms_code']) ){
  454. return app('json')->fail('验证码不正确');
  455. }
  456. $user = $repository->accountByUser($data['phone']);
  457. if ($user)
  458. return app('json')->fail('手机号已存在');
  459. if ($data["spread_phone"]){
  460. $spread_user = $repository->accountByUser($data['spread_phone']);
  461. if ($spread_user ){
  462. $data['spread']=$spread_user["uid"];
  463. }else{
  464. return app('json')->fail('推荐人手机号填写错误');
  465. }
  466. }
  467. // Log::info($data);
  468. $user = $repository->registr($data['phone'], $data['password'],'APP',"","",1,0);
  469. // $repository->registr($data['phone'], $data['password'],'APP',$data['spread']);
  470. $repository->addagent($user);
  471. $user = $repository->mainUser($user);
  472. // $repository->bindSpread($user, intval($data['spread']));
  473. // $repository->spread_log($user, intval($data['spread']));
  474. $tokenInfo = $repository->createToken($user);
  475. $repository->loginAfter($user);
  476. //type==2 事业二部注册并绑定推荐关系
  477. // if($type==2){
  478. // $mer_data=Db::name('merchant')->where('mer_id',$data['mer_id'])->value('merchant_type');
  479. // if($mer_data==2){
  480. // try {
  481. // $eb_user=Db::name('user')->where('account',$data['phone'])->find();
  482. //// Db::name('log')->insert(['data'=>'推荐人ID'.$eb_user['spread_uid']]);
  483. // $users = app()->make(\app\controller\api\entropybarter\User::class);
  484. // $users->bangding($eb_user['uid'],$eb_user['spread_uid'],276);
  485. // $users->bangding($eb_user['uid'],$eb_user['spread_uid'],236);
  486. // }catch (Exception $exception){
  487. // Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  488. // }
  489. // }
  490. // }
  491. // if ($type == "marketing"){
  492. // $spread = Db::name("User") -> alias("u") -> leftjoin("MarketingUser mu","u.uid = mu.uid") -> where("u.uid",$data['spread']) -> field("u.uid,mu.spread_list") -> find();
  493. // $spread_list = explode(',',$spread['spread_list']);
  494. // if (!empty($spread_list)){
  495. // $spread_list[] = "[" . $spread['uid'] . "]";
  496. // }else{
  497. // array_push($spread_list,"[".$spread['uid']."]");
  498. // }
  499. // $spread_list = array_filter($spread_list);
  500. // $data = [
  501. // "uid" => $user->uid,
  502. // "spread_uid" => $spread['uid'],
  503. // "spread_list" => implode(",",$spread_list)
  504. // ];
  505. // Db::name("MarketingUser") -> insert($data);
  506. // }
  507. $result = $repository->returnToken($user, $tokenInfo);
  508. $result['uid'] = $user->uid;
  509. return app('json')->success($result);
  510. }
  511. /**
  512. * 绑定邀请人
  513. */
  514. public function registerBindSpread(UserRepository $repository)
  515. {
  516. $data = $this->request->params(['uid','spread_phone']);
  517. $user=$repository->accountByUser($data['uid']);
  518. $uid=$user['uid'];
  519. $spreadphone=$user['spread_phone'];
  520. if (empty($data['spread_phone'])) {
  521. return app('json')->fail('推荐人手机号不能为空');
  522. }
  523. $spread_user=Db::name('user')->where('phone',$spreadphone)->field('uid')->find();
  524. $spreadUid=$spread_user['uid'];
  525. $spread_user = $repository->accountByUser($data['spread_phone']);
  526. if (!$spread_user) {
  527. return app('json')->fail('推荐人手机号不存在');
  528. }
  529. if ($spread_user['uid'] == $uid) {
  530. return app('json')->fail('不能绑定自己为推荐人');
  531. }
  532. $this->sign_add($spreadUid, 30,1,'邀请好友注册奖励积分','','', '', 1, '', 1);
  533. $user->spread_uid = $spreadUid;
  534. $user->spread_time = date('Y-m-d H:i:s');
  535. if($spreadUid){
  536. $user->mer_id = Db::name('user')->where('uid',$spreadUid)->value('mer_id');
  537. }
  538. $this->dao->update($spreadUid, [
  539. 'spread_count' => Db::raw('spread_count +1')
  540. ]);
  541. $user->save();
  542. //TODO 推广人月榜
  543. Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid);
  544. //TODO 推广人周榜
  545. Cache::zincrby('s_top_' . monday(), 1, $spreadUid);
  546. $this->spread_log($user,$spreadUid);
  547. $repository->bindSpread($user, intval($spread_user['uid']));
  548. return app('json')->success('绑定成功');
  549. }
  550. /**
  551. * 手机号找回密码
  552. * @param UserRepository $repository
  553. * @return mixed
  554. * @throws DbException
  555. * @author xaboy
  556. * @day 2020/6/1
  557. */
  558. public function reset(UserAuthValidate $validate, UserRepository $repository){
  559. $data = $this->request->params(['account', 'captcha', 'code', 'password']);
  560. $data['phone'] = $data['account'];
  561. $data['sms_code'] = $data['captcha'];
  562. $validate->sceneSmslogin()->check($data);
  563. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  564. return app('json')->fail('验证码不正确');
  565. $user = $repository->accountByUser($data['account']);
  566. if ($user){
  567. $res = $repository->resetPassword($data['account'], $data['password'], $user['uid']);
  568. if($res){
  569. return app('json')->success('重置成功');
  570. }
  571. }
  572. return app('json')->error('重置失败');
  573. }
  574. /**
  575. * 旧密码找回密码
  576. * @param UserRepository $repository
  577. * @return mixed
  578. * @throws DbException
  579. * @author xaboy
  580. * @day 2021/1/21
  581. */
  582. public function oldreset(UserRepository $repository){
  583. $user = $this->request->userInfo()
  584. ->hidden(['label_id', 'group_id', 'card_id', 'last_time', 'last_ip', 'status', 'spread_uid', 'spread_time', 'real_name', 'brokerage_price']);
  585. $user->append(['account','pwd','phone',"uid"]);
  586. $user=$user->toArray();
  587. // $user = $this->request->userInfo()->hidden(['account','pwd','phone',"uid"]);
  588. // $user=$this->request->userInfo();
  589. $data = $this->request->params(['passwordold', 'password']);
  590. if (!$user)
  591. return app('json')->fail('密码错误');
  592. if (!password_verify($pwd = (string)$data["passwordold"], $user['pwd']))
  593. return app('json')->fail('密码错误1');
  594. // UserRepository $repository
  595. $user = $repository->accountByUser($user['account']);
  596. if ($user){
  597. $res = $repository->resetPassword($user['account'], $data['password'], $user['uid']);
  598. if($res){
  599. return app('json')->success('重置成功');
  600. }
  601. }
  602. return app('json')->error('重置失败');
  603. }
  604. /*手机号验证
  605. * @author cabbage
  606. * */
  607. public function checkAccount(UserAuthValidate $validate, UserRepository $repository){
  608. $data = $this->request->params(['account', 'captcha']);
  609. $data['phone'] = $data['account'];
  610. $data['sms_code'] = $data['captcha'];
  611. $validate->sceneSmslogin()->check($data);
  612. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  613. return app('json')->fail('验证码不正确');
  614. $user = $repository->accountByUser($data['account']);
  615. if ($user) {
  616. return app('json')->success('验证成功');
  617. }else{
  618. return app('json')->error('旧手机验证失败');
  619. }
  620. }
  621. /**
  622. * 更换手机号
  623. * @param UserRepository $repository
  624. * @return mixed
  625. * @throws DbException
  626. * @author cabbage
  627. */
  628. public function changeAccount(UserAuthValidate $validate,UserRepository $repository){
  629. $data = $this->request->params(['account', 'new_account','captcha']);
  630. $data['phone'] = $data['new_account'];
  631. $data['sms_code'] = $data['captcha'];
  632. $validate->sceneSmslogin()->check($data);
  633. if (!$this->checkSmsCode($data['new_account'], $data['captcha']))
  634. return app('json')->fail('验证码不正确');
  635. $user = $repository->accountByUser($data['account']);
  636. if ($user){
  637. $res = $repository->resetAccount($data['new_account'],$user['uid'],$user['identity']);
  638. if($res){
  639. return app('json')->success('重置成功');
  640. }
  641. }
  642. return app('json')->error('重置失败');
  643. }
  644. /**
  645. * 获取用户信息
  646. * @return mixed
  647. * @author xaboy
  648. * @day 2020/6/1
  649. */
  650. public function userInfo()
  651. {
  652. $user = $this->request->userInfo()
  653. ->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  654. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  655. $data=$user->toArray();
  656. $is_merchant=Db::name("merchant_intention")->where(["uid"=>$user["uid"],"is_branch"=>0])->order("mer_intention_id desc")->value("status");
  657. $data["is_merchant"]=$is_merchant===0||$is_merchant>0?$is_merchant:-1;
  658. $data['phone1'] =substr($data['phone'], 0, 3) . '****' . substr($data['phone'], 7, 4);
  659. $data['longtime'] = intval((time()- strtotime($data['create_time'])) / 86400);
  660. $is_ertification=Db::name("user_certification")->where("uid",$user["uid"])->value("status");
  661. $data["is_ertification"]=$is_ertification>0||$is_ertification===0?$is_ertification:-1;
  662. $mer_staff=Db::name("store_staff")->where(["uid"=>$user["uid"]])->value("department");
  663. $data["is_mer_staff"]=$mer_staff?explode(",",$mer_staff):0;
  664. $volunteer = Db::name("volunteer") -> where(["uid"=>$user["uid"]]) -> value("grade");
  665. $data['volunteer'] = $volunteer ?? 0;
  666. if($data['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  667. $data['avatar']=Db::name('user_account')->where('type',1)->where('uid',$data['uid'])->value('avater');
  668. if(empty($data['avatar'])){
  669. $data['avatar']=Db::name('user_account')->where('type',2)->where('uid',$data['uid'])->value('avater');
  670. if(empty($data['avatar'])){
  671. $data['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  672. }
  673. }
  674. }
  675. //养老金展示
  676. // $data['annuity'] = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',1) -> sum('number');
  677. $a = Db::name('user_bill')->where('uid', $user['uid'])->where('commission_type', 5)->where('pm', 1)->whereIn('status', [0, 1])->sum('number');
  678. $b = Db::name('user_bill')->where('uid', $user['uid'])->where('commission_type', 5)->where('pm', 0)->whereIn('status', [0, 1])->sum('number');
  679. $data['annuity'] = $a - $b;
  680. //上级身份是否大仓会员
  681. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$user["uid"])->find();
  682. //渠道商
  683. $is_channel = Db::name('channel_user') -> where('uid',$user["uid"])->where('status',1)->find();
  684. //红积分
  685. $red = Db::name('user_rich') -> where('uid',$user['uid'])->value('red');
  686. $data['is_da_cang_vip'] = 0;
  687. $data['is_channel'] = 0;
  688. $data['red'] = 0;
  689. if($is_da_cang_vip){
  690. $data['is_da_cang_vip'] = $is_da_cang_vip['type'];
  691. }
  692. if($is_channel){
  693. $data['is_channel'] = 1;
  694. }
  695. if ($red){
  696. $data['red'] = $red;
  697. }
  698. $aa = Db::name('user') -> where('uid',$user['uid'])->find();//查询用户个人数据
  699. $teamsnums = $this->getteamsnum($user['uid']);
  700. //$team_userinfo_old_jbp1 = $this->getPerformance($teamid);//获取旧表总大小部门人数
  701. //$data['team_number'] = $this->getBreak($user['uid']);//获取新表大小部门总人数
  702. $data['team_number'] = $teamsnums;
  703. $data['is_bangfu'] = Db::name('user_bangfu') -> where('uid',$user["uid"])->value('status')==1;
  704. // $data['area_manage'] = Db::name('area_manage')->field('type,code_list')->where('uid',$user["uid"])->find();
  705. // if($data['area_manage']){
  706. // $area_manage = Db::name('regions')->field('type,code_list')->where('id','in',$data['area_manage']['code_list'])->cache('code1:'.$data['area_manage']['code_list'],7200)->column('name,id');
  707. // if($area_manage){
  708. // $area_manage = array_column($area_manage,'name','id');
  709. // $code_list = explode(',',$data['area_manage']['code_list']);
  710. // $data['area_manage']['area_name'] = count($code_list) == 2 ? [$area_manage[$code_list[0]], $area_manage[$code_list[1]]] : [$area_manage[$code_list[0]], $area_manage[$code_list[1]], $area_manage[$code_list[2]]];
  711. // }
  712. // }
  713. $user_rich=Db::name('user_rich')->where('uid', $user['uid'])->field('type,stockholder,is_huitian')->find();
  714. $data['user_rich_type']= (isset($user_rich) )?$user_rich['type']:0;
  715. $data['stockholder']= (isset($user_rich) )?$user_rich['stockholder']:0;
  716. // $area_manage_type=Db::name('area_manage')->where('uid', $user["uid"])->value('type');
  717. //类型 district-区/县代 city-市代',
  718. // $data['area_manage_type']=$area_manage_type??'';
  719. // $data['member_brokerage_price']=set_price_rtrim($data['member_brokerage_price']);
  720. //积分
  721. $data['score']=set_price_rtrim($data['score']);
  722. //2025新增 贡献值,红包,京东,vr,复购金
  723. // 老逻辑 需要废弃
  724. // if( $user['user_group'] <= 2 ){
  725. // $data['contribute'] = $user['contribute'] + $user['per_contribute'];
  726. // }else{
  727. // $data['contribute'] = $user['contribute'];
  728. // }
  729. $date['contribute']=set_price_rtrim($data['contribute']);//贡献值
  730. $data['repurchase_price']=set_price_rtrim($data['repurchase_price']);//复购余额
  731. $data['jingdou']=set_price_rtrim($data['jingdou']);//京豆
  732. $data['vr']=set_price_rtrim($data['vr']);//购物金
  733. $data['hongbao']=set_price_rtrim($data['hongbao']);//红包
  734. $data['fugou']=set_price_rtrim($data['fugou']);//复购金
  735. $data['brokerage_price']=set_price_rtrim($data['brokerage_price']);//养老金
  736. $data['annuity'] = set_price_rtrim($data['annuity']);//养老金
  737. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',0) -> sum('number');
  738. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',1) -> sum('number');
  739. // $data['brokerage_price'] = $a +$b;
  740. $data['brokerage_price'] = $aa['brokerage_price'];
  741. $data['isOld']=($data['is_old']);//
  742. $data['exchange']=0;
  743. $data['withdraw']=0;
  744. $data['user_group']=set_price_rtrim($data['user_group']);
  745. if($this->source=='yhc'){
  746. $data['avatar']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  747. $data['exchange']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('exchange');
  748. //withdraw 是否可以提现 0-可以 1-禁止
  749. $data['withdraw']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('withdraw');
  750. }
  751. //普通用户,根据我的贡献值升级(个人消费贡献值+直推的消费产生的贡献值)
  752. $my_con = [];
  753. if($aa['user_group'] < 2){
  754. $my_con = [2,3];
  755. }else if($aa['user_group'] == 2){
  756. $my_con = [3];
  757. }
  758. $data['con_level'] = [
  759. 'my_con' => $aa['contribute'],//我的贡献值
  760. 'my_recon_con' => $aa['per_contribute'],//我推荐的贡献值
  761. 'curr_level' => $aa['user_group'],//当前用户级别身份
  762. 'change_level' => $my_con //可选的等级身份(业务员、业务经理)
  763. ];
  764. return app('json')->success($data );
  765. }
  766. public function updateUserCon(){
  767. $data = $this->request->params(['change_level','uid']);
  768. $uid = $data['uid'];
  769. if(empty($uid)){
  770. return app('json')->fail('找不到该用户!');
  771. }
  772. // $user = $this->request->userInfo();
  773. //var_dump($data);
  774. //var_dump($user);
  775. $aa = Db::name('user') -> where('uid',$uid)->find();//查询用户个人数据
  776. if(empty($aa)){
  777. return app('json')->fail('找不到该用户!');
  778. }
  779. // if(empty($data['my_con']) || empty($data['my_recon_con']) || empty($data['curr_level']) || empty($data['change_level'])){
  780. // return app('json')->fail('参数有误!');
  781. // }
  782. if($data['change_level'] <= $aa['user_group']){
  783. return app('json')->fail('升级失败,请重新选择!');
  784. }
  785. $dev_amount = 0;//需扣除的贡献值
  786. if($data['change_level'] == 2){
  787. $dev_amount = 1180;
  788. }else if($data['change_level'] == 3){
  789. $dev_amount = 11800;
  790. }
  791. //可升级用的贡献值
  792. $con_amount = $aa['contribute'] + $aa['per_contribute'];
  793. $cur_amount = $con_amount - $dev_amount;
  794. if( $cur_amount < 0){
  795. return app('json')->fail('升级失败,贡献值不足!');
  796. }
  797. // 判断总贡献值是否足够
  798. //推荐的贡献值够扣
  799. $yue_amount = $aa['per_contribute'] - $dev_amount;
  800. if( $yue_amount >= 0){
  801. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=> $yue_amount, 'user_group'=>$data['change_level']]);//查询用户个人数据
  802. if($aa){
  803. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  804. return app('json')->success('升级成功');
  805. }
  806. }else{
  807. //推荐的贡献值不够扣
  808. $yue_amount = $aa['contribute'] + $aa['per_contribute'] - $dev_amount;
  809. if( $yue_amount == 0){
  810. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>0 , 'user_group'=>$data['change_level']]);//
  811. if($aa){
  812. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  813. return app('json')->success('升级成功');
  814. }
  815. }else if($yue_amount > 0){
  816. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>$yue_amount, 'user_group'=>$data['change_level']]);//查询用户个人数据
  817. if($aa){
  818. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  819. return app('json')->success('升级成功');
  820. }
  821. }
  822. }
  823. }
  824. public function con_logs($uid,$num,$order_id,$order_type,$mark,$status = -1,$state){
  825. $con_data = Db::name('user')->where("uid",$uid)->find();
  826. $con = [
  827. 'uid'=>$uid,
  828. 'number'=>$num,//赠送数量
  829. 'status'=>$status,//红包状态
  830. 'mark'=>$mark,//备注
  831. 'desc'=>'',//描述
  832. 'order_id'=>$order_id,//订单id
  833. 'surplus'=> $con_data['contribute'],//剩余
  834. 'order_type'=>$order_type,//订单类型
  835. 'type'=>$state,//1增加,2消耗
  836. 'settlement_time'=>date('Y-m-d H:i:s'),
  837. 'addtime'=>time()
  838. ];
  839. Db::name('user_sign_gongxian')->insert($con);
  840. }
  841. public function getteamsnum($teamid){
  842. // $subordinate_members = Db::name('user')
  843. // ->alias('u')
  844. // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  845. // ->where("u.spread_uid", $teamid)
  846. // ->where("so.mer_id", 496)
  847. // ->group('u.uid')
  848. //
  849. // ->select();
  850. //
  851. //
  852. // $total_amount_pv_team = 0;
  853. // $team_count_total = 0;
  854. //
  855. // foreach ($subordinate_members as $k => $v) {
  856. // $t_teams_pv = $this->calculatePerformance($v['uid']);
  857. // $total_amount_pv_team += $t_teams_pv['total_performance'];
  858. // $team_count_total += $t_teams_pv['team_count'];
  859. //
  860. //
  861. // }
  862. return Db::name('user')->where(['level_id'=>$teamid])->count();
  863. }
  864. //计算自己和自己团队下面的业绩。新表
  865. public function calculatePerformance($uid)
  866. {
  867. // 初始化业绩数组
  868. $performance = [
  869. 'personal_performance' => 0, // 个人业绩
  870. 'team_performance' => 0, // 团队业绩
  871. 'total_performance' => 0, // 总业绩
  872. 'team_count' => 0, // 加上自己的团队数量
  873. ];
  874. // 定义业绩换算规则
  875. $performanceMapping = [
  876. 1180 => 700,
  877. 10620 => 6300,
  878. 11800 => 7000
  879. ];
  880. // 计算个人业绩
  881. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  882. if ($personalOrder) {
  883. // 将浮点数转换为整数
  884. $totalPrice = (int)$personalOrder['total_price'];
  885. if (isset($performanceMapping[$totalPrice])) {
  886. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  887. }
  888. }
  889. // 计算旗下团队成员的业绩
  890. $teamOrders = Db::name('user')
  891. ->alias('u')
  892. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  893. ->where("u.spread_uid", $uid) // 查询旗下会员
  894. ->where("so.mer_id", 496)
  895. // ->where("so.douhuomall", 1)
  896. // ->where("so.douhuomall_status", 9)
  897. // ->where("so.status", 0)
  898. ->select();
  899. $teamOrders_count = Db::name('user')
  900. ->alias('u')
  901. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  902. ->where("u.spread_uid", $uid) // 查询旗下会员
  903. ->where("so.mer_id", 496)
  904. // ->where("so.douhuomall", 1)
  905. // ->where("so.douhuomall_status", 9)
  906. // ->where("so.status", 0)
  907. ->count();
  908. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  909. foreach ($teamOrders as $order) {
  910. if ($order['total_price']) {
  911. // 将浮点数转换为整数
  912. $totalPrice = (int)$order['total_price'];
  913. if (isset($performanceMapping[$totalPrice])) {
  914. $performance['team_performance'] += $performanceMapping[$totalPrice];
  915. }
  916. }
  917. }
  918. // 计算总业绩
  919. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  920. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  921. return $performance;
  922. }
  923. //获取大小部门业绩(新表)
  924. public function getbig_samll_datas($subordinate_members){
  925. //单独写一个方法获取大小部门的数据
  926. $arr_team = [];
  927. foreach ($subordinate_members as $k => $v) {
  928. //计算自己和旗下的业绩
  929. $arr_team[] = $this->calculatePerformance($v['uid']);
  930. }
  931. // 初始化变量
  932. $maxPerformance = 0;
  933. $maxIndex = -1;
  934. // 找出 total_performance 最高的记录
  935. foreach ($arr_team as $index => $item) {
  936. if ($item['total_performance'] > $maxPerformance) {
  937. $maxPerformance = $item['total_performance'];
  938. $maxIndex = $index;
  939. }
  940. }
  941. // 如果找到了最高记录
  942. if ($maxIndex !== -1) {
  943. // 提取最高记录
  944. $maxRecord = $arr_team[$maxIndex];
  945. // 从原数组中移除该记录
  946. unset($arr_team[$maxIndex]);
  947. // 重新索引数组
  948. $arr_team = array_values($arr_team);
  949. } else {
  950. // 如果没有找到记录,可以设置一个默认值
  951. $maxRecord = null;
  952. }
  953. // 计算大部门和小部门的汇总信息
  954. $majorDepartmentSummary = [
  955. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  956. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  957. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  958. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  959. "data" => $maxRecord ? [$maxRecord] : []
  960. ];
  961. $minorDepartmentSummary = [
  962. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  963. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  964. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  965. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  966. "data" => $arr_team
  967. ];
  968. // 输出结果
  969. // echo "大部门汇总信息:\n";
  970. // print_r($majorDepartmentSummary);
  971. // echo "小部门汇总信息:\n";
  972. // print_r($minorDepartmentSummary);
  973. return array($majorDepartmentSummary,$minorDepartmentSummary);
  974. }
  975. public function getBreak($uid,$list=[],$count=0){
  976. $sql = "select getUserLevelId($uid) as count";
  977. $count = Db::query($sql);
  978. return count(explode(",",$count[0]['count'])) - 1;
  979. }
  980. /**
  981. * 整合用户登录token
  982. * @return mixed
  983. * @author xaboy
  984. * @day 2020/6/1
  985. */
  986. public function tokenList()
  987. {
  988. $user = $this->request->userInfo()->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  989. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  990. $userInfo = $user->toArray();
  991. $temp = $this->curl_java_login($userInfo['phone']);
  992. $data['mweb_info'] = [];
  993. if(isset($temp['data'])){
  994. $data['mweb_info'] = $temp['data'];
  995. }
  996. $data['merchant_info'] = [];
  997. return app('json')->success($data);
  998. }
  999. function curl_java_login($phone){
  1000. $curl = curl_init();
  1001. curl_setopt_array($curl, array(
  1002. CURLOPT_URL => env('APP_URL') . '/gateway/userCenter_service/userLogOnService/userPhoneLogOn',
  1003. CURLOPT_RETURNTRANSFER => true,
  1004. CURLOPT_ENCODING => '',
  1005. CURLOPT_MAXREDIRS => 10,
  1006. CURLOPT_TIMEOUT => 0,
  1007. CURLOPT_FOLLOWLOCATION => true,
  1008. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1009. CURLOPT_CUSTOMREQUEST => 'POST',
  1010. CURLOPT_POSTFIELDS =>'{"phone":'.$phone.',"sms_code":"9527","type":"1"}',
  1011. CURLOPT_HTTPHEADER => array(
  1012. 'Content-Type: application/json'
  1013. ),
  1014. ));
  1015. $response = curl_exec($curl);
  1016. curl_close($curl);
  1017. $response = json_decode($response, true);
  1018. return $response;
  1019. }
  1020. /**
  1021. * 获取用户信息
  1022. * @return mixed
  1023. * @author xaboy
  1024. * @day 2020/6/1
  1025. */
  1026. public function userVolunteer()
  1027. {
  1028. $uid = $this->request->uid();
  1029. $volunteer = Db::name("volunteer") -> where(["uid"=>$uid]) -> find();
  1030. // $volunteer_class = app()->make(Volunteer::class);
  1031. $volunteer_class = new Volunteer();
  1032. $volunteerData = $volunteer_class -> volunteer($uid);
  1033. $data['grade'] = 0;
  1034. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  1035. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  1036. if($volunteer){
  1037. $data = $volunteer;
  1038. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  1039. if($volunteer['grade'] == 1){
  1040. $data['condition_one'] = systemConfig("a_volunteer_achievement");//团队养老金要求
  1041. $data['condition_two'] = systemConfig("a_volunteer_number");//团队人数要求
  1042. }
  1043. if($volunteer['grade'] == 2){
  1044. $data['condition_one'] = systemConfig("b_volunteer_achievement");//团队养老金要求
  1045. $data['condition_two'] = systemConfig("b_volunteer_number");//团队人数要求
  1046. }
  1047. if($volunteer['grade'] == 3){
  1048. $data['condition_one'] = systemConfig("c_volunteer_achievement");//团队养老金要求
  1049. $data['condition_two'] = systemConfig("c_volunteer_number");//团队人数要求
  1050. }
  1051. if($volunteer['grade'] == 4){
  1052. $data['condition_one'] = systemConfig("d_volunteer_achievement");//团队养老金要求
  1053. $data['condition_two'] = systemConfig("d_volunteer_number");//团队人数要求
  1054. }
  1055. }
  1056. return app('json')->success($data);
  1057. }
  1058. /**
  1059. * @param UserRepository $repository
  1060. * @return mixed
  1061. * @author xaboy
  1062. * @day 2020/6/1
  1063. */
  1064. public function logout(UserRepository $repository)
  1065. {
  1066. $repository->clearToken($this->request->token());
  1067. return app('json')->success('退出登录');
  1068. }
  1069. /**
  1070. * @return mixed
  1071. * @throws DataNotFoundException
  1072. * @throws DbException
  1073. * @throws ModelNotFoundException
  1074. * @author xaboy
  1075. * @day 2020-05-11
  1076. */
  1077. public function auth()
  1078. {
  1079. $request = $this->request;
  1080. $oauth = WechatService::create()->getApplication()->oauth;
  1081. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1082. try {
  1083. $wechatInfo = $oauth->user()->getOriginal();
  1084. } catch (\Exception $e) {
  1085. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1086. }
  1087. if (!isset($wechatInfo['nickname'])) {
  1088. return app('json')->fail('授权失败[002]');
  1089. }
  1090. /** @var WechatUserRepository $make */
  1091. $make = app()->make(WechatUserRepository::class);
  1092. $user = $make->syncUser($wechatInfo['openid'], $wechatInfo);
  1093. if (!$user)
  1094. return app('json')->fail('授权失败[003]');
  1095. /** @var UserRepository $make */
  1096. $userRepository = app()->make(UserRepository::class);
  1097. $user[1] = $userRepository->mainUser($user[1]);
  1098. $pid = $this->request->param('spread', 0);
  1099. $userRepository->bindSpread($user[1], intval($pid));
  1100. $tokenInfo = $userRepository->createToken($user[1]);
  1101. $userRepository->loginAfter($user[1]);
  1102. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1103. }
  1104. protected function returnToken($user, $tokenInfo)
  1105. {
  1106. $CommonRepository = app()->make(Common::class);
  1107. $access_token ='75_-8y0OT8i5w72EkPCLpCQoGFGa2Ir42T8RHvqZPLJ4sjn27s6Aj7RUEO5yJX77pzHVoo34zXpeBS0M-gdNegdCRB4FWhkAqxmuhdrANkenSHdrmEvPSWQex4OKFQXLBfAEAJXN';
  1108. var_dump($access_token);
  1109. $unionid = "oGtg_6E5SwAcXhv5Do5z3GL_UMXw";
  1110. $unionid = "o4-On50WzIkkbJsf-apbBE3VB1O0";
  1111. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $unionid . "&lang=zh_CN";
  1112. }
  1113. /**
  1114. * @return mixed
  1115. * @throws DataNotFoundException
  1116. * @throws DbException
  1117. * @throws ModelNotFoundException
  1118. * @author xaboy
  1119. * @day 2020-05-11
  1120. */
  1121. public function mpAuth()
  1122. {
  1123. list($code, $post_cache_key) = $this->request->params([
  1124. 'code',
  1125. 'cache_key',
  1126. ], true);
  1127. $session_key = Cache::get('eb_api_code_' . $post_cache_key);
  1128. if (!$code && !$session_key)
  1129. return app('json')->fail('授权失败,参数有误');
  1130. $miniProgramService = MiniProgramService::create();
  1131. if ($code && !$session_key) {
  1132. try {
  1133. $userInfoCong = $miniProgramService->getUserInfo($code);
  1134. $session_key = $userInfoCong['session_key'];
  1135. $cache_key = md5(time() . $code);
  1136. Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
  1137. } catch (\Exception $e) {
  1138. return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  1139. }
  1140. }
  1141. $data = $this->request->params([
  1142. ['spread_spid', 0],
  1143. ['spread_code', ''],
  1144. ['iv', ''],
  1145. ['encryptedData', ''],
  1146. ]);
  1147. try {
  1148. //解密获取用户信息
  1149. $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
  1150. } catch (\Exception $e) {
  1151. if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
  1152. throw $e;
  1153. }
  1154. if (!$userInfo || !isset($userInfo['openId'])) return app('json')->fail('openid获取失败');
  1155. if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
  1156. /** @var WechatUserRepository $make */
  1157. $make = app()->make(WechatUserRepository::class);
  1158. $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
  1159. if (!$user)
  1160. return app('json')->fail('授权失败');
  1161. /** @var UserRepository $make */
  1162. $userRepository = app()->make(UserRepository::class);
  1163. $user[1] = $userRepository->mainUser($user[1]);
  1164. //获取是否有扫码进小程序
  1165. if (isset($data['spread_code']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']))) {
  1166. $data['spread_spid'] = $info['third_id'];
  1167. }
  1168. $userRepository->bindSpread($user[1], intval($data['spread_spid']));
  1169. $tokenInfo = $userRepository->createToken($user[1]);
  1170. $userRepository->loginAfter($user[1]);
  1171. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1172. }
  1173. public function getCaptcha()
  1174. {
  1175. $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
  1176. $key = uniqid(microtime(true), true);
  1177. Cache::set('api_captche' . $key, $codeBuilder->getPhrase(), 300);
  1178. $captcha = $codeBuilder->build()->inline();
  1179. $code = $codeBuilder->getPhrase();
  1180. return app('json')->success(compact('key', 'code', 'captcha'));
  1181. }
  1182. protected function checkCaptcha($uni, string $code): bool
  1183. {
  1184. $cacheName = 'api_captche' . $uni;
  1185. if (!Cache::has($cacheName)) return false;
  1186. $key = Cache::get($cacheName);
  1187. $code = mb_strtolower($code, 'UTF-8');
  1188. $res = password_verify($code, $key);
  1189. if ($res) Cache::delete($cacheName);
  1190. return $res;
  1191. }
  1192. /**
  1193. * 获取验签公钥
  1194. * @return Response
  1195. */
  1196. public function getPublicKey(): Response
  1197. {
  1198. $path = env('RSA_PUBLIC_KEY_PATH');
  1199. if (empty($path)) {
  1200. return json([
  1201. 'code' => 500,
  1202. 'msg' => '公钥路径未配置',
  1203. 'data' => null
  1204. ]);
  1205. }
  1206. if (!file_exists($path)) {
  1207. return json([
  1208. 'code' => 500,
  1209. 'msg' => '公钥文件不存在: ' . $path,
  1210. 'data' => null
  1211. ]);
  1212. }
  1213. $publicKey = file_get_contents($path);
  1214. return json([
  1215. 'code' => 200,
  1216. 'msg' => 'success',
  1217. 'data' => [
  1218. 'publicKey' => $publicKey
  1219. ]
  1220. ]);
  1221. }
  1222. public function verify(UserAuthValidate $validate)
  1223. {
  1224. $data = $this->request->params(['phone', 'code', 'key',"type", 'areaCode']);
  1225. $validate->sceneVerify()->check($data);
  1226. log::info("发送短信方法");
  1227. if ($data['type']=="login"){
  1228. $count=Db::name("user")->where("phone", $data["phone"])->count();
  1229. if (!$count){
  1230. return app('json')->make(405, '该手机号未注册,请去注册');
  1231. }
  1232. $sms_num_key = 'api.auth.num.' . $data['phone'];
  1233. $num = Cache::get($sms_num_key) ?: 0;
  1234. log::info("num{$num}");
  1235. if ($num > 9) {
  1236. if (!$data['code'])
  1237. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  1238. if (!$this->smslogin($data['phone'], $data['code'])) {
  1239. return app('json')->fail('登录验证码输入有误');
  1240. }
  1241. }
  1242. }
  1243. if ($data['type']=="register"){
  1244. $count=Db::name("user")->where("phone", $data["phone"])->count();
  1245. if ($count){
  1246. return app('json')->make(405, '该手机号已注册,请直接登录');
  1247. }
  1248. $sms_num_key = 'api.auth.num.' . $data['phone'];
  1249. $num = Cache::get($sms_num_key) ?: 0;
  1250. log::info("num{$num}");
  1251. if ($num > 9) {
  1252. if (!$data['code'])
  1253. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  1254. if (!$this->registersmscode($data['phone'], $data['code'])) {
  1255. return app('json')->fail('注册验证码输入有误');
  1256. }
  1257. }
  1258. }
  1259. $sms_key = 'api.auth.sms.' . $data['phone'];
  1260. $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
  1261. $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ;
  1262. $res = app()->make(AliYunSmsService::class)->send(($data['areaCode'] ?? '') . $data['phone'], $sms_code);
  1263. if($res['Code']!='OK'){
  1264. Db::name('log')->insert(['data'=>'幸福保短信发送失败:'.json_encode($res,256)]);
  1265. return app('json')->fail('操作过于频繁,请稍后重试~');
  1266. }
  1267. log::info("sms_key==={$sms_key}" );
  1268. log::info("sms_code==={$sms_code}" );
  1269. log::info("sms_time==={$sms_time}" );
  1270. Cache::set($sms_key, $sms_code,$sms_time * 60);
  1271. Cache::set($sms_num_key, $num + 1, 300);
  1272. //'短信发送成功'
  1273. return app('json')->success('短信发送成功');
  1274. }
  1275. /**
  1276. * 一壶茶查询邀请人信息 1-根据手机号查询uid 2-根据uid查手机号
  1277. * @return mixed
  1278. * @throws DataNotFoundException
  1279. * @throws DbException
  1280. * @throws ModelNotFoundException
  1281. */
  1282. public function query_uid(){
  1283. $phone = $this->request->param('phone');
  1284. $uid = $this->request->param('uid',0);
  1285. $share_id = $this->request->param('share_id',0);
  1286. $type = $this->request->param('type',1);//1-根据手机号查询uid 2-根据uid查手机号 3-通过share_id 查询用户信息
  1287. if($this->source=='yhc' && $this->merId) {
  1288. $user=$this->inviter_verification($type,$uid,$phone,$share_id);
  1289. if($user!=false){
  1290. return app('json')->success('获取成功',$user);
  1291. }
  1292. }
  1293. return app('json')->fail('邀请人不存在');
  1294. }
  1295. private function inviter_verification($type,$uid='',$phone='',$share_id=''){
  1296. if($type==2) {
  1297. $where['uid'] = $uid;
  1298. }else if($type==3){
  1299. $where['uid'] = Db::name('product_share')->where('id', $share_id)->value('uid');
  1300. }else{
  1301. $where['account']=$phone;
  1302. }
  1303. $user =Db::name('user')->field('uid,account as phone')->where($where)->find();
  1304. if(!$user){
  1305. return false;
  1306. }
  1307. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1308. if(!$user2){
  1309. return false;
  1310. }
  1311. return $user;
  1312. }
  1313. /**
  1314. * 一壶茶判断这个手机号是否注册过
  1315. * @return mixed
  1316. * @throws DataNotFoundException
  1317. * @throws DbException
  1318. * @throws ModelNotFoundException
  1319. */
  1320. public function query_phone()
  1321. {
  1322. $phone = $this->request->param('phone','');
  1323. if($phone==''){
  1324. //解密微信手机号
  1325. $sessionKey=$this->request->params(['sessionKey']);
  1326. $encryptedData=$this->request->params(['encryptedData']);
  1327. $iv=$this->request->params(['iv']);
  1328. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1329. return app('json')->fail('参数不正确');
  1330. }
  1331. $appid = 'wx9082e5ac2fdb513f';//幸福宝小程序appid
  1332. if($this->source=='yhc'){
  1333. $appid = 'wx9082e5ac2fdb513f';//一壶茶小程序appid
  1334. }
  1335. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1336. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1337. $iv =str_replace(' ','+', $iv['iv']);
  1338. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1339. $errCode = $pc->decryptData($encryptedData, $iv, $wx_data_str );
  1340. if ($errCode != 0) {
  1341. return app('json')->fail('没有获取到手机号');
  1342. }
  1343. // dump($data);
  1344. $wx_data=json_decode($wx_data_str,true);
  1345. if(isset($wx_data['purePhoneNumber'])){
  1346. $phone=$wx_data['purePhoneNumber'];
  1347. }
  1348. }
  1349. $validate= new UserAuthValidate();
  1350. $validate->sceneVerify()->check(['phone'=>$phone]);
  1351. if($this->source=='yhc' && $this->merId) {
  1352. $where['account']=$phone;
  1353. $user =Db::name('user')->field('uid')->where($where)->find();
  1354. if(!$user){
  1355. return app('json')->fail('未注册');
  1356. }
  1357. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1358. if($user2){
  1359. return app('json')->success('已注册');
  1360. }
  1361. }
  1362. return app('json')->fail('未注册');
  1363. }
  1364. public function smsLogin(UserAuthValidate $validate, UserRepository $repository)
  1365. {
  1366. $data = $this->request->params(['phone', 'sms_code', 'spread', 'share_id']);
  1367. // $data = $this->request->params(['phone', 'sms_code']);
  1368. $validate->sceneSmslogin()->check($data);
  1369. $domain = $this->request->domain();
  1370. //如果手机验证码错误并且验证码不是6865,进入查验团队验证码环节
  1371. if (!$this->checkSmsCode($data['phone'], $data['sms_code']) && $data['sms_code'] !== '6865') {
  1372. $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');//通过输入的手机号查询用户的uid
  1373. if($uid){
  1374. $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();//去user_zero_line表查询团队team_uid和团队自定义的验证码
  1375. $hasTeam = false; //先将用户设成不为团队成员
  1376. foreach ($allTeams as $team) {
  1377. $cacheKey = 'team_members_' . $team['team_uid'];
  1378. $member_uids = Cache::get($cacheKey);
  1379. $sql = "select getUserLevelId({$team['team_uid']}) as uids"; //查询所有团队下成员的uid
  1380. $spread_user_list = Db::query($sql);
  1381. $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
  1382. Cache::set($cacheKey, $member_uids, 300); //结果缓存5分钟
  1383. if (in_array($uid, $member_uids)){
  1384. $hasTeam = true; //若用户属于团队,将其设为团队成员
  1385. if ($data['sms_code'] != $team['custom_code']) {
  1386. return app('json')->fail('验证码不正确'); //如果与用户所属团队的验证码不一致,返回验证码不正确
  1387. }
  1388. break;
  1389. }
  1390. }
  1391. if (!$hasTeam) {
  1392. return app('json')->fail('验证码不正确');
  1393. }
  1394. } else {
  1395. return app('json')->fail('验证码不正确');
  1396. }
  1397. }
  1398. $user = $repository->accountByUser($data['phone']);
  1399. if (!$user){
  1400. return app('json')->fail('手机号未注册,请先注册');
  1401. }
  1402. // if($this->source=='yhc' && $this->merId){
  1403. // $where=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1404. // $count=Db::name('enterprise_user')->where($where)->count();
  1405. // if($count<1){
  1406. // $insert=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1407. // if (!intval($data['spread'])) {
  1408. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1409. // }else{
  1410. // $spread_uid=$data['spread'];
  1411. // }
  1412. // if($this->inviter_verification(2,$spread_uid)==false){
  1413. // return app('json')->fail('请输入正确邀请人手机号');
  1414. // }
  1415. // $insert['puid']= $spread_uid;
  1416. // $insert['node_uid']= $spread_uid;
  1417. // Db::name('enterprise_user')->insert($insert);
  1418. // }
  1419. // }
  1420. // $repository->bindSpread($user, intval($data['spread']));
  1421. $tokenInfo = $repository->createToken($user);
  1422. $repository->loginAfter($user);
  1423. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1424. }
  1425. public function registerSmscode(UserAuthValidate $validate, UserRepository $repository)
  1426. {
  1427. $data = $this->request->params(['phone', 'sms_code', 'spread_uid']);
  1428. $validate->sceneSmslogin()->check($data);
  1429. $count = Db::name('user')->where('phone', $data['phone'])->count();
  1430. if ($count > 0) {
  1431. return app('json')->fail('手机号已注册,请直接登录');
  1432. }
  1433. if (!$this->checkSmsCode($data['phone'], $data['sms_code'])) {
  1434. return app('json')->fail('验证码不正确');
  1435. }
  1436. return app('json')->success([
  1437. 'msg' => '验证码验证通过,请填写推荐人手机号完成注册',
  1438. 'phone' => $data['phone']
  1439. ]);
  1440. }
  1441. public function merJavaRegister(UserRepository $repository){
  1442. $data = $this->request->params(['phone', 'spread','token','sign']);
  1443. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  1444. // 校验sign
  1445. $checkSign = Signature::checkSign($data);
  1446. if (!$checkSign) {
  1447. Log::channel("gong")->error('sign校验失败');
  1448. return app('json')->fail('sign校验失败');
  1449. }
  1450. $user = $repository->accountByUser($data['phone']);
  1451. if (!$user) $user = $repository->registr($data['phone'], $data['password'],'MP',intval($data['spread']));
  1452. $user = $repository->mainUser($user);
  1453. $repository->bindSpread($user, intval($data['spread']));
  1454. $repository->loginAfter($user);
  1455. return app('json')->success($user);
  1456. }
  1457. /**
  1458. * @param $phone
  1459. * @param $code
  1460. * @return bool
  1461. * @author Qinii
  1462. * @day 2020-06-12
  1463. */
  1464. public function checkSmsCode($phone, $code)
  1465. {
  1466. $sms_key = 'api.auth.sms.' . $phone;
  1467. //log::info("缓存===code=={$sms_key}");
  1468. //log::info( Cache::get($sms_key));
  1469. //log::info("页面传值==={$code}");
  1470. if (!$cache_code = Cache::get($sms_key)) return false;
  1471. if ($code != $cache_code) return false;
  1472. Cache::delete($sms_key);
  1473. return true;
  1474. }
  1475. //批量生产100个账号
  1476. public function register_all(UserAuthValidate $validate, UserRepository $repository){
  1477. $datas = $this->request->params(['start', 'end','phone']);
  1478. if(mb_strlen($datas['start'].$datas['phone']) != 11 || mb_strlen($datas['end'].$datas['phone']) != 11){
  1479. return app("json")->fail('参数错误');
  1480. }
  1481. for($i=$datas['start'];$i<=$datas['end'];$i++)//这个dao是看你要生成多答少个数字,然后循环生成
  1482. {
  1483. $data=[
  1484. "phone"=>$datas['phone'].$i,
  1485. 'password'=>"123456"
  1486. ];
  1487. $user = $repository->registr($data['phone'], $data['password']);
  1488. $data=[
  1489. 'user_name'=>"测试".$i,
  1490. "mobile"=>"15555555187",
  1491. "user_card"=>"410181198508206517",
  1492. "card_positive"=>"https://app.bjtdba.com/uploads/def/20201030/088ecbdfa81534fadcc7c731d11c0594.jpg",
  1493. "card_reverse"=>"https://app.bjtdba.com/uploads/def/20201030/7546811225c6b5df37a7f41250ba3e66.jpg",
  1494. "status"=>1,
  1495. "create_time"=>time(),
  1496. "update_time"=>time(),
  1497. "uid"=>$i
  1498. ];
  1499. Db::name("user_certification")->insert($data);
  1500. }
  1501. return app("json")->success('成功');
  1502. }
  1503. public function phoneCheck(UserRepository $repository){
  1504. $data = $this->request->params(['phone']);
  1505. $user = $repository->accountByUser($data['phone']);
  1506. if($user){
  1507. return app("json")->success('手机号已注册,可直接绑定',1);
  1508. }else{
  1509. return app("json")->success('手机号未注册,请输入密码',2);
  1510. }
  1511. }
  1512. /*支付宝获取签名*/
  1513. public function aliSign(){
  1514. $repository = app()->make(UserRepository::class);
  1515. $data = $repository ->aliSign();
  1516. return app("json")->success('ok',$data);
  1517. }
  1518. /*支付宝授权登录*/
  1519. public function aliCheck(){
  1520. $data = $this->request->params(['user_id']);
  1521. if(!$data['user_id'] || $data['user_id'] == '' || $data['user_id'] =='undefined'){
  1522. return app('json')->fail("异常操作");
  1523. }
  1524. $repository = app()->make(UserRepository::class);
  1525. $result = $repository ->aliCheck($data['user_id']);
  1526. if(isset($result['code']) && $result['code'] == 200){
  1527. $user = $repository->accountByUser($result['user']['account']);
  1528. $tokenInfo = $repository->createToken($user);
  1529. $repository->loginAfter($user);
  1530. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1531. }
  1532. return app("json")->success('ok',$result);
  1533. }
  1534. /*微信信息获取*/
  1535. public function getWechat(){
  1536. $repository = app()->make(UserRepository::class);
  1537. return app('json')->success($repository->getWechat());
  1538. }
  1539. /**
  1540. * 微信授权登录 一键登录
  1541. * @return mixed
  1542. * @throws DataNotFoundException
  1543. * @throws DbException
  1544. * @throws ModelNotFoundException
  1545. */
  1546. public function wechatCheck()
  1547. {
  1548. $data = $this->request->params(['openid']);
  1549. $data['nickname'] = $this->request->param('nickname', null);
  1550. $data['avatar'] = $this->request->param('avatar', null);
  1551. if (!$data['openid'] || $data['openid'] == '' || $data['openid'] == 'undefined') {
  1552. return app('json')->fail("openid参数缺失");
  1553. }
  1554. /** @var UserRepository $repository */
  1555. $repository = app()->make(UserRepository::class);
  1556. $result = $repository->wechatCheck($data['openid'], $data['nickname'], $data['avatar']);
  1557. if (isset($result['code']) && $result['code'] == 200) {
  1558. $user = $repository->accountByUser($result['user']['account']);
  1559. $tokenInfo = $repository->createToken($user);
  1560. $repository->loginAfter($user);
  1561. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1562. }
  1563. return app("json")->fail($result['msg']);
  1564. }
  1565. public function binding_yhc(UserAuthValidate $validate, UserRepository $repository)
  1566. {
  1567. $data = $this->request->params(['phone', 'third_user_id','type']);
  1568. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1569. return app('json')->fail("绑定失败");
  1570. }
  1571. $data['password'] = '123456';//密码已经去掉了。统一默认密码
  1572. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP','',0,"https://". $this->request->host(true));//2222
  1573. if($user){
  1574. $enterprise_user= Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->find();
  1575. if(!$enterprise_user){
  1576. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1577. }else if ($enterprise_user['openid']==''){
  1578. $update = ["openid" => $data['third_user_id']];
  1579. Db::name("enterprise_user")->where(['mer_id'=>$this->merId,'uid'=>$user->uid])->update($update);
  1580. }
  1581. // $pid = $this->request->param('spread', 0);
  1582. // $repository->bindSpread($user, intval($pid));
  1583. $tokenInfo = $repository->createToken($user);
  1584. $repository->loginAfter($user);
  1585. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1586. }else{
  1587. return app('json')->fail("绑定失败");
  1588. }
  1589. }
  1590. /**
  1591. * 支付宝微信注册绑定手机号
  1592. * type 1微信2支付宝
  1593. * third_user_id 微信openid 支付宝userId
  1594. * @param UserRepository $repository
  1595. */
  1596. public function binding(UserAuthValidate $validate, UserRepository $repository)
  1597. {
  1598. $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','sms']);
  1599. $data['nickName'] = $this->request->param('nickName', null);
  1600. $data['avatarUrl'] = $this->request->param('avatarUrl', null);
  1601. $share_id = $this->request->param('share_id', null);
  1602. $spread_uid = 0;
  1603. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1604. return app('json')->fail("绑定失败");
  1605. }
  1606. $data['password'] = '123456';//密码已经去掉了。统一默认密码
  1607. $validate->sceneSmslogin()->check($data);
  1608. if($data['sms'] != 1){
  1609. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1610. return app('json')->fail('验证码不正确');
  1611. }
  1612. if (!empty($share_id)) {
  1613. $spread_uid = Db::name('product_share')->where('id', $share_id)->value('uid');
  1614. }
  1615. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true), $spread_uid);//2222
  1616. if($user){
  1617. $userRepository = app()->make(UserRepository::class);
  1618. $userInfo = $userRepository->getOne(['uid' => $user->uid ?? $user['uid']]);
  1619. //绑定线下充值金额
  1620. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1621. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1622. $notBind = $unionUsersRepository->getAllNotBind($data['third_user_id']);
  1623. if ($notBind) {
  1624. $orderMerchantRepository->doBindUser($userInfo, $data['type']);
  1625. }
  1626. $user = $repository->accountByUser($data['phone']);
  1627. if ($data['type'] == 1) {
  1628. $data1 = ["wechat_user_id" => $data['third_user_id']];
  1629. // 屎山上边堆屎
  1630. $check = Db::name('user_extract_openid')->where('uid', $user->uid)->count();
  1631. if ($check < 1) {
  1632. Db::name("user_extract_openid")->insert([
  1633. 'uid' => $user->uid,
  1634. 'openid' => $data['third_user_id'],
  1635. 'type' => 1
  1636. ]);
  1637. }
  1638. if($this->source=='yhc' && $this->merId){ //一壶茶创建用户
  1639. $enterprise_user_count = Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->count();
  1640. if($enterprise_user_count<1){
  1641. $spread_data = $this->request->params(['spread', 'share_id']);
  1642. if (!intval($spread_data['spread'])) {
  1643. $spread_uid = Db::name('product_share')->where('id', $spread_data['share_id'])->value('uid');
  1644. }else{
  1645. $spread_uid=$spread_data['spread'];
  1646. }
  1647. if($this->inviter_verification(2,$spread_uid)==false){
  1648. return app('json')->fail('请输入正确邀请人手机号');
  1649. }
  1650. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1651. }
  1652. }
  1653. } else {
  1654. $data1 = ["ali_user_id" => $data['third_user_id']];
  1655. }
  1656. $data2 = [];
  1657. if (!is_null($data['nickName']) || !is_null($data['avatarUrl'])) {
  1658. $data2 = [
  1659. "type" => $data['type'],
  1660. "uid" => $user->uid,
  1661. "nickname" => $data['nickName'],
  1662. "avater" => $data['avatarUrl'],
  1663. ];
  1664. }
  1665. $userRepository -> updateUser($user->uid,$data1,$data2);
  1666. $pid = $this->request->param('spread', 0);
  1667. $repository->bindSpread($user, intval($pid));
  1668. $tokenInfo = $repository->createToken($user);
  1669. $repository->loginAfter($user);
  1670. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1671. }else{
  1672. return app('json')->fail("绑定失败");
  1673. }
  1674. }
  1675. public function queryHaike(){
  1676. $merch_no = $this->request->params(['merch_no']);
  1677. if(!isset($merch_no['merch_no']) || empty($merch_no['merch_no'])){
  1678. return app('json')->fail("请输入商户号");
  1679. }
  1680. $res = Db::name("haike_account")->where("merch_no",$merch_no['merch_no'])->select();
  1681. if(!$res){
  1682. return app('json')->fail("这个商户号没有账单");
  1683. }
  1684. $merch = Db::name('merchant') -> where("merch_no",$merch_no['merch_no']) -> find();
  1685. $data['商户号'] = $merch_no['merch_no'];
  1686. $data['商户名称'] = $merch["mer_name"];
  1687. $data['商户手机号'] = $merch["mer_phone"];
  1688. $data['结算金额'] = 0;
  1689. $data['结算手续费'] = 0;
  1690. foreach ($res as $key => $value){
  1691. $data['结算金额'] += $value['settle_accounts'];
  1692. $data['结算手续费'] += $value['settle_accounts_fee'];
  1693. }
  1694. echo "<pre>";
  1695. dump($data);
  1696. return 1;
  1697. }
  1698. public function createUserNumberAll(){
  1699. $userRepository = app()->make(UserRepository::class);
  1700. $user = Db::name('user') -> select();
  1701. foreach($user as $key => $value){
  1702. $userRepository -> createUserNumber($value['uid']);
  1703. }
  1704. }
  1705. /**
  1706. * @param int $uid 用户ID
  1707. * @param string $score 积分
  1708. * @param int $status 积分状态
  1709. * @param string $mark 备注
  1710. * @param string $has_qian 连续签到天数
  1711. * @param string $today_signintime 签到时间
  1712. * @param int $order_id 订单ID
  1713. * @param int $pm 1-收入。2-支出
  1714. * @param string $order_type
  1715. * @throws DbException
  1716. */
  1717. public function sign_add($uid, $score, $status, $mark, $has_qian = '', $today_signintime = '', $order_id = 0, $pm = 1, $order_type = '',$type='',$settlement_time = '')
  1718. {
  1719. if(!in_array($type,[1,2])){
  1720. // 其他情况都直接返回,因为目前只有365专区购买才可以获得
  1721. return false;
  1722. }
  1723. $ins_data['uid'] = $uid;
  1724. $ins_data['continuity_day'] = $has_qian;
  1725. $ins_data['reward_socre'] = $score;
  1726. $ins_data['signin_time'] = $today_signintime;
  1727. $ins_data['addtime'] = time();
  1728. $ins_data['status'] = $status;
  1729. $ins_data['mark'] = $mark;
  1730. $ins_data['type'] = $type;
  1731. $ins_data['settlement_time'] = $settlement_time;// 结算时间 真正到了结算时间会结算
  1732. $ins_data['order_id'] = $order_id;
  1733. $ins_data['pm'] = $pm;
  1734. $ins_data['order_type'] = $order_type;
  1735. Db::name('user_sign_score')->insertGetId($ins_data);
  1736. if($pm == 1 && $status == 1){
  1737. Db::name('user')->where('uid',$uid)->inc('score', $score)->update();
  1738. }
  1739. if($pm == 2){
  1740. Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
  1741. }
  1742. }
  1743. public function yijianlogin(UserRepository $repository)
  1744. {
  1745. try {
  1746. // Db::name('log')->insert(['data'=>'一键登录进来了']);
  1747. $token = $this->request->params(['token'])['token'];
  1748. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1749. ->regionId('cn-hangzhou')
  1750. ->asDefaultClient();
  1751. $result = AlibabaCloud::rpc()
  1752. ->product('Dypnsapi')
  1753. ->scheme('https')// https | http
  1754. ->version('2017-05-25')
  1755. ->action('GetMobile')
  1756. ->method('POST')
  1757. ->host('dypnsapi.aliyuncs.com')
  1758. ->options([
  1759. 'query' => [
  1760. 'RegionId' => "cn-hangzhou",
  1761. 'AccessToken' => $token
  1762. ],
  1763. ])
  1764. ->request();
  1765. // 将返回的结果转化为数组
  1766. $result = $result->toArray();
  1767. // Db::name('log')->insert(['data'=>json_encode($result)]);
  1768. //判断当前数组不为空
  1769. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  1770. // token不为空返回手机号码
  1771. $phone = $result['GetMobileResultDTO']['Mobile'];
  1772. $user_res=Db::name('user')->where('account',$phone)->find();
  1773. if(!$user_res){
  1774. $repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
  1775. }
  1776. $user = $repository->accountByUser($phone);
  1777. $user = $repository->mainUser($user);
  1778. $tokenInfo = $repository->createToken($user);
  1779. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1780. } else {
  1781. //如果token为空
  1782. $res = [
  1783. 'state' => 0,
  1784. 'msg' => 'token无效'
  1785. ];
  1786. return app('json')->fail($res);
  1787. }
  1788. }catch (\Exception $e) {
  1789. Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1790. }
  1791. }
  1792. //小程序获取 用户手机号
  1793. public function applet_phone(UserRepository $repository)
  1794. {
  1795. try {
  1796. // Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
  1797. $sessionKey=$this->request->params(['sessionKey']);
  1798. $encryptedData=$this->request->params(['encryptedData']);
  1799. $share_id = $this->request->params(['share_id']);
  1800. $iv=$this->request->params(['iv']);
  1801. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1802. return app('json')->fail('参数不正确');
  1803. }
  1804. // $appid = 'wx82986c4471ce7efc';
  1805. // if($this->source=='yhc'){
  1806. // $appid = 'wx82986c4471ce7efc';
  1807. // }
  1808. // $appid = 'wx7b4d857deb0447f3';
  1809. $appid = 'wx9082e5ac2fdb513f';
  1810. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1811. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1812. $iv =str_replace(' ','+', $iv['iv']);
  1813. // dump($iv,$encryptedData);
  1814. // return ;
  1815. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1816. // dump($pc);
  1817. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  1818. // $data "{\"phoneNumber\":\"15350612089\",\"purePhoneNumber\":\"15350612089\",\"countryCode\":\"86\",\"watermark\":{\"timestamp\":1745288870,\"appid\":\"wx9082e5ac2fdb513f\"}}"
  1819. // dump($errCode);
  1820. if ($errCode != 0) {
  1821. return app('json')->fail('没有获取到手机号1');
  1822. }
  1823. // dump($data);
  1824. $data=json_decode($data,true);
  1825. $phone=$data['purePhoneNumber']??'';
  1826. if($phone==''){
  1827. return app('json')->fail('没有获取到手机号2');
  1828. }
  1829. if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
  1830. return app('json')->fail('手机号格式错误');
  1831. }
  1832. $user_res=Db::name('user')->where('account',$phone)->find();
  1833. if(!$user_res){
  1834. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  1835. if (!intval($spread_uid)) {
  1836. $spread_uid = 0;
  1837. }
  1838. $repository->registr($phone, 123456,'APP','','','',$spread_uid);
  1839. }
  1840. $user = $repository->accountByUser($phone);
  1841. // if($this->source=='yhc' && $this->merId){
  1842. // $where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1843. // $count=Db::name('enterprise_user')->where($where)->count();
  1844. // if($count<1){
  1845. // $insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1846. // $data = $this->request->params(['spread', 'share_id']);
  1847. //
  1848. // if(isset($data['spread']) && $data['spread']){
  1849. // $insert['puid']= $data['spread'];
  1850. // $insert['node_uid']= $data['spread'];
  1851. // }else if(isset($data['share_id']) && $data['share_id']){
  1852. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1853. // $insert['puid']= $spread_uid;
  1854. // $insert['node_uid']= $spread_uid;
  1855. // }
  1856. // if(!isset($insert['node_uid']) || !$insert['node_uid']){
  1857. // return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
  1858. // }
  1859. //
  1860. // if(isset($data['spread']) && isset($zhuce)){
  1861. // $insert['puid']= $data['spread'];
  1862. // $insert['node_uid']= $data['spread'];
  1863. // }
  1864. // Db::name('enterprise_user')->insert($insert);
  1865. // }
  1866. // }
  1867. if (!empty($user) && $user instanceof User) {
  1868. $user = $repository->mainUser($user);
  1869. $tokenInfo = $repository->createToken($user);
  1870. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1871. } else {
  1872. return app('json')->fail('未查询到用户信息');
  1873. }
  1874. }catch (Exception $exception){
  1875. Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  1876. }
  1877. }
  1878. public function phone_name()
  1879. {
  1880. try {
  1881. $phone=$this->request->params(['phone']);
  1882. if(empty($phone['phone'])){
  1883. return app('json')->fail('请填写手机号码');
  1884. }
  1885. $phone=$phone['phone'];
  1886. $uid=Db::name('user')->where('account',$phone)->find();
  1887. $user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
  1888. if(!$user_name){
  1889. $user_name=$uid['nickname'];
  1890. }
  1891. return app('json')->success($user_name);
  1892. }catch (\Exception $e) {
  1893. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1894. }
  1895. }
  1896. public function get_auth_token(){
  1897. $params=$this->request->params(['url','origin']);
  1898. try {
  1899. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1900. ->regionId('cn-hangzhou')
  1901. ->asDefaultClient()->options([
  1902. ]);
  1903. $result = AlibabaCloud::rpc()
  1904. ->product('Dypnsapi')
  1905. ->scheme('https')// https | http
  1906. ->version('2017-05-25')
  1907. ->action('GetAuthToken')
  1908. ->method('POST')
  1909. ->host('dypnsapi.aliyuncs.com')
  1910. ->options([
  1911. 'query' => [
  1912. 'Url' => $params['url'],
  1913. 'Origin' => $params['origin'],
  1914. ],
  1915. ])
  1916. ->request();
  1917. $result = $result->toArray();
  1918. return app('json')->success($result);
  1919. }catch (Exception $e) {
  1920. return app('json')->success();
  1921. }
  1922. }
  1923. public function get_phone_with_token(){
  1924. $params=$this->request->params(['token']);
  1925. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1926. ->regionId('cn-hangzhou')
  1927. ->asDefaultClient()->options([]);
  1928. $result = AlibabaCloud::rpc()
  1929. ->product('Dypnsapi')
  1930. ->scheme('https')// https | http
  1931. ->version('2017-05-25')
  1932. ->action('GetPhoneWithToken')
  1933. ->method('POST')
  1934. ->host('dypnsapi.aliyuncs.com')
  1935. ->options([
  1936. 'query' => [
  1937. 'SpToken' => $params['token'],
  1938. ],
  1939. ])
  1940. ->request();
  1941. $result = $result->toArray();
  1942. return app('json')->success($result);
  1943. }
  1944. public function getconlev(){
  1945. // $userid = 17;
  1946. // $datas = $this->getPerformance_getcon($userid);
  1947. // var_dump($datas);
  1948. $dats = db::name("store_order")->whereIn("status",[0,1,2,3])->select();
  1949. var_dump($dats);
  1950. }
  1951. /**
  1952. * 获取当前用户大小部门贡献值
  1953. */
  1954. public function getPerformance_getcon($user_id) {
  1955. $team_amount = 0;
  1956. $person_amount = 0;
  1957. $user_id = 593; //598 523 536
  1958. $result_big_team_arr = [];
  1959. $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
  1960. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  1961. $common_nums = $this->getCommonNums_getcon($user_id);
  1962. //var_dump($common_nums);
  1963. $get_teams_comm_num = 0;
  1964. $get_teams_comm_pv = 0;
  1965. $get_teams_per_num = 0;//小部门人数
  1966. //1.0系统中有下级,需要在2.0中再加下级数据
  1967. if($user_id < 611){
  1968. //梅红在2.0中的ID是780
  1969. //var_dump( $common_nums);
  1970. //用户三峡所有在2.0系统下面的业绩和人数 start
  1971. $child_nums = [];
  1972. //获取当前用户
  1973. foreach($common_nums as $v){
  1974. $child_nums[] = $this->getRecursiveChildren_getcon($v);
  1975. }
  1976. //去除空数组,并重新组合有数据的数组
  1977. $filteredData = array_filter($child_nums, function($array) {
  1978. return !empty($array); // 如果数组不为空,则保留
  1979. });
  1980. // 合并所有非空数组
  1981. foreach ($filteredData as $array) {
  1982. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  1983. }
  1984. //var_dump($result_big_team_arr);
  1985. //获取当前用户下面在2.0中的下级所有PV
  1986. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  1987. $t_pv = $this->getteampv_getcon($result_big_team_arr);
  1988. $get_teams_comm_pv = $t_pv;
  1989. //var_dump($get_teams_comm_pv);echo "ttt";
  1990. //用户伞下小部门所有在2.0系统下面的业绩和人数 end
  1991. }else{
  1992. //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  1993. $child_nums = $this->getChildren_getcon($user_id);
  1994. //获取父级子级下面的个人
  1995. $num_teams = $this->getTeamSize_getcon($child_nums);
  1996. //var_dump($num_teams);
  1997. foreach($child_nums as $v){
  1998. $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  1999. }
  2000. //$s = $this->getparents_child_pv($user_id);
  2001. //var_dump($get_teams_comm_datas);
  2002. //如果只有一个部门,就是默认大部门
  2003. if( count($get_teams_comm_datas) ==1 ){
  2004. $get_teams_comm_pv =$get_teams_comm_datas[0];
  2005. $get_teams_comm_num = $num_teams[0]['total_count'];
  2006. }else if(count($get_teams_comm_datas) >1){
  2007. // var_dump( $get_teams_comm_datas);
  2008. //获取一个最大值,设为大部门,其他的加载一块是小部门
  2009. $getss = $this->processArray_getcon($get_teams_comm_datas);
  2010. //var_dump($getss);
  2011. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  2012. unset($num_teams[$getss['max_index']]);
  2013. //获取小部门的人数
  2014. $per_num = 0;
  2015. foreach($num_teams as $k=>$v){
  2016. $per_num +=$v['total_count'];
  2017. }
  2018. //找到最大值的(大部门)
  2019. //$get_teams_comm_num = $max_value_count;
  2020. //小部门的数量
  2021. // $get_teams_per_num = $per_num;
  2022. //var_dump($getss['max_value']);
  2023. $person_amount = $getss['remaining_sum'];
  2024. $get_teams_comm_pv = $getss['max_value'];
  2025. }
  2026. }
  2027. //var_dump($get_teams_comm_pv);
  2028. //合并业绩和人数
  2029. $team_amount += $get_teams_comm_pv;
  2030. //var_dump($team_amount);
  2031. //1.0获取小区业绩
  2032. $person_nums = $this->getPersonageNums_getcon($user_id);
  2033. //var_dump($person_nums);
  2034. $result_small_team_arr = [];
  2035. //1.0系统中有下级,需要在2.0中再加下级数据
  2036. //用户三峡所有在2.0系统下面的业绩和人数 start
  2037. $child_nums_mix = [];
  2038. //获取当前用户
  2039. foreach($person_nums as $v){
  2040. $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
  2041. }
  2042. //去除空数组,并重新组合有数据的数组
  2043. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  2044. return !empty($array); // 如果数组不为空,则保留
  2045. });
  2046. // 合并所有非空数组
  2047. $result_small_team_arr = [];
  2048. foreach ($filteredData_1 as $array) {
  2049. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  2050. }
  2051. //var_dump($result_small_team_arr);
  2052. //获取当前用户下面在2.0中的下级所有PV
  2053. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  2054. $t_pv = $this->getteampv_getcon($result_small_team_arr);
  2055. $get_teams_per_pv =$t_pv;
  2056. //var_dump( $get_teams_per_pv);
  2057. //获取当前用户下面在2.0中的下级所有人数
  2058. // $get_teams_per_num += count($result_small_team_arr);
  2059. //合并业绩和人数
  2060. $person_amount += $get_teams_per_pv;
  2061. //当前会员直属的业绩(1.0大部门)
  2062. $t_pv = $this->getteampv_getcon($common_nums);
  2063. $team_amount += $t_pv;
  2064. //当前会员直属的业绩(1.0大部门)
  2065. $p_pv = $this->getteampv_getcon($person_nums);
  2066. $person_amount += $p_pv;
  2067. //var_dump($team_amount,$person_amount);
  2068. //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  2069. if($user_id < 611){
  2070. //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  2071. //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  2072. $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
  2073. $team_amount = $b_s[0];
  2074. $person_amount = $b_s[1];
  2075. }
  2076. $return_data = [
  2077. 'common_nums_pv'=> $team_amount,
  2078. 'person_nums_pv'=> $person_amount,
  2079. ];
  2080. return $return_data;
  2081. }
  2082. /**
  2083. * 获取该用户共建联盟
  2084. */
  2085. public function getCommonNums_getcon($user_id){
  2086. //先获取共建联盟下用户的id
  2087. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  2088. $new_array_ids =[];
  2089. foreach ($son_ids as $key => $value) {
  2090. # code...
  2091. $son_id = $value['id'];
  2092. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2093. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2094. if(count($son_value_ids) > 0) {
  2095. $son_value_ids = array_column($son_value_ids,"id");
  2096. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2097. }
  2098. }
  2099. return $new_array_ids;
  2100. }
  2101. /**
  2102. * 获取该用户个人联盟
  2103. */
  2104. public function getPersonageNums_getcon($user_id){
  2105. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  2106. $new_array_ids =[];
  2107. // return 3343;
  2108. foreach ($son_ids as $key => $value) {
  2109. # code...
  2110. $son_id = $value['id'];
  2111. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2112. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2113. if(count($son_value_ids) > 0) {
  2114. $son_value_ids = array_column($son_value_ids,"id");
  2115. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2116. }
  2117. }
  2118. return $new_array_ids;
  2119. }
  2120. // 根据父级uid,递归获取所有子级UID数组
  2121. public function getRecursiveChildren_getcon($parentUid) {
  2122. $result = []; // 用于存储所有子级的 uid
  2123. // 定义递归函数
  2124. $recursion = function ($parentUid) use (&$result, &$recursion) {
  2125. // 查询当前父级的所有直接子级
  2126. $children = Db::name("user")
  2127. ->where("spread_uid", $parentUid)
  2128. ->column("uid"); // 获取子级的 uid 列表
  2129. // 如果没有子级,直接返回
  2130. if (empty($children)) {
  2131. return;
  2132. }
  2133. // 遍历每个子级
  2134. foreach ($children as $childUid) {
  2135. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  2136. $recursion($childUid); // 递归查询子级的子级
  2137. }
  2138. };
  2139. // 从初始父级开始递归查询
  2140. $recursion($parentUid);
  2141. return array_unique($result); // 返回结果数组,并去重
  2142. }
  2143. //只获取数组中的业绩
  2144. public function getteampv_getcon($common_nums) {
  2145. // // 查询当前用户及其子级的所有订单
  2146. $orders_gongxian = Db::name("user_sign_gongxian")
  2147. ->whereIn('status', [1])
  2148. ->whereIn("uid", $common_nums)
  2149. ->select();
  2150. //var_dump( $common_nums);
  2151. $total_gongxian = 0;
  2152. // // 遍历订单计算业绩
  2153. foreach ($orders_gongxian as $order) {
  2154. if (strpos($order['mark'], "购买") !== false) {
  2155. $total_gongxian += $order['number'];
  2156. }
  2157. }
  2158. return $total_gongxian;
  2159. // // // 查询当前用户及其子级的所有订单
  2160. // $orders = Db::name("store_order")
  2161. // ->whereIn('status', [0, 1, 2, 3])
  2162. // ->whereIn("uid", $common_nums)
  2163. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  2164. // ->select();
  2165. // // 初始化业绩和人数
  2166. // $totalPv = 0;
  2167. // $totalUsers = count($common_nums); // 初始化人数为子级总数
  2168. // // 遍历订单计算业绩
  2169. // foreach ($orders as $order) {
  2170. // if ($order['total_price'] == 1180) {
  2171. // $totalPv += 700;
  2172. // } else if ($order['total_price'] == 11800) {
  2173. // $totalPv += 7000;
  2174. // } else if ($order['total_price'] == 10620) {
  2175. // $totalPv += 6300;
  2176. // } else if ($order['total_price'] == 2360) {
  2177. // $totalPv += 1400;
  2178. // } else if ($order['total_price'] == 9440) {
  2179. // $totalPv += 5600;
  2180. // }
  2181. // }
  2182. // // 返回业绩和人数
  2183. // return [
  2184. // 'totalPv' => $totalPv,
  2185. // 'totalUsers' => $totalUsers
  2186. // ];
  2187. }
  2188. // 2.0 根据父级uid,找到当前用户下面的UID
  2189. public function getChildren_getcon($parentUid) {
  2190. $result = []; // 用于存储所有子级的 uid
  2191. $children = Db::name("user")
  2192. ->where("spread_uid", $parentUid)
  2193. ->column("uid"); // 获取子级的 uid 列表
  2194. return $children; // 返回结果数组,并去重
  2195. }
  2196. // 递归获取所有子级 UID 的业绩
  2197. public function getTeamPv11_getcon($parentUid) {
  2198. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  2199. $children = Db::name("user")
  2200. ->where("spread_uid", $parentUid)
  2201. ->column("uid");
  2202. $allChildren = [];
  2203. foreach ($children as $childUid) {
  2204. $allChildren[] = $childUid;
  2205. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  2206. }
  2207. return $allChildren;
  2208. };
  2209. // 获取当前用户及其所有子级的 UID
  2210. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  2211. $orders_gongxian = Db::name("user_sign_gongxian")
  2212. ->whereIn('status', [1])
  2213. ->whereIn("uid", $allUids)
  2214. ->select();
  2215. $total_gongxian = 0;
  2216. // // 遍历订单计算业绩
  2217. foreach ($orders_gongxian as $order) {
  2218. if (strpos($order['mark'], "购买") !== false) {
  2219. $total_gongxian += $order['number'];
  2220. }
  2221. }
  2222. return $total_gongxian;
  2223. // // 查询当前用户及其子级的所有订单
  2224. // $orders = Db::name("store_order")
  2225. // ->whereIn('status', [0, 1, 2, 3])
  2226. // ->whereIn("uid", $allUids)
  2227. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  2228. // ->select();
  2229. // // 计算总业绩
  2230. // $totalPv = 0;
  2231. // foreach ($orders as $order) {
  2232. // switch ($order['total_price']) {
  2233. // case 1180:
  2234. // $totalPv += 700;
  2235. // break;
  2236. // case 11800:
  2237. // $totalPv += 7000;
  2238. // break;
  2239. // case 10620:
  2240. // $totalPv += 6300;
  2241. // break;
  2242. // case 2360:
  2243. // $totalPv += 1400;
  2244. // break;
  2245. // case 9440:
  2246. // $totalPv += 5600;
  2247. // break;
  2248. // }
  2249. // }
  2250. // return $totalPv;
  2251. }
  2252. //根据传递的父级数组,返回他的对应子级的个数
  2253. public function getTeamSize_getcon($parentUids) {
  2254. // 初始化结果数组
  2255. $result = [];
  2256. // 遍历每个父级ID
  2257. foreach ($parentUids as $parentUid) {
  2258. // 递归获取所有子级 UID
  2259. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  2260. $children = Db::name("user")
  2261. ->where("spread_uid", $parentUid)
  2262. ->column("uid");
  2263. // 确保返回的是数组
  2264. if (!is_array($children)) {
  2265. return [];
  2266. }
  2267. $allChildren = [];
  2268. foreach ($children as $childUid) {
  2269. $allChildren[] = $childUid;
  2270. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  2271. }
  2272. return $allChildren;
  2273. };
  2274. // 获取当前父级及其所有子级的 UID
  2275. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  2276. // 计算总个数(包括父级自身)
  2277. $totalUids = count($allUids);
  2278. // 将结果存入数组
  2279. $result[] = [
  2280. 'parent_uid' => $parentUid,
  2281. 'total_count' => $totalUids
  2282. ];
  2283. }
  2284. return $result;
  2285. }
  2286. public function processArray_getcon($array) {
  2287. // 初始化结果数组
  2288. $result = [
  2289. 'max_value' => null, // 最大值
  2290. 'max_index' => null, // 最大值的下标
  2291. 'remaining_sum' => 0 // 剩余值的总和
  2292. ];
  2293. // 检查数组是否为空
  2294. if (empty($array)) {
  2295. return $result;
  2296. }
  2297. // 找出最大值及其下标
  2298. $maxValue = $array[0];
  2299. $maxIndex = 0;
  2300. for ($i = 1; $i < count($array); $i++) {
  2301. if ($array[$i] > $maxValue) {
  2302. $maxValue = $array[$i];
  2303. $maxIndex = $i;
  2304. }
  2305. }
  2306. // 计算剩余值的总和
  2307. $remainingSum = 0;
  2308. for ($i = 0; $i < count($array); $i++) {
  2309. if ($i != $maxIndex) {
  2310. $remainingSum += $array[$i];
  2311. }
  2312. }
  2313. // 将结果存入数组
  2314. $result['max_value'] = $maxValue;
  2315. $result['max_index'] = $maxIndex;
  2316. $result['remaining_sum'] = $remainingSum;
  2317. return $result;
  2318. }
  2319. /**
  2320. * 获取流水信息
  2321. */
  2322. public function getPerformance1_getcon($user_id) {
  2323. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  2324. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  2325. // return $amount;
  2326. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  2327. $money1180Sum = 0;
  2328. foreach ($money1180Records as $record) {
  2329. $money1180Sum += $record['money'] - 300 - 180;
  2330. }
  2331. // var_dump($money1180Sum);
  2332. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  2333. //var_dump($person_nums);
  2334. //计算个人的11800单价的业绩 集合
  2335. $money11800Sum = 0;
  2336. foreach ($money11800Records as $record) {
  2337. $money11800Sum += $record['money'] - 3000 - 1800;
  2338. }
  2339. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  2340. //var_dump($person_nums);
  2341. //计算个人的11800单价的业绩 集合
  2342. $money10620Sum = 0;
  2343. foreach ($money10620Records as $record) {
  2344. $money10620Sum += $record['money'] - 2700 - 1620;
  2345. }
  2346. // 计算除去特定值后的总和
  2347. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  2348. $otherMoneySum = 0;
  2349. foreach ($otherMoneyRecords as $record) {
  2350. $otherMoneySum += $record['money'];
  2351. }
  2352. // 分别处理特定值的情况并加上其他值的总和
  2353. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  2354. return $user_person_amount;
  2355. }
  2356. //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  2357. public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
  2358. // 获取直接下级的 UID 列表
  2359. $get_childs = Db::name("user")
  2360. ->where("spread_uid", $user_id)
  2361. ->column("uid");
  2362. // 初始化变量
  2363. $all_departments = []; // 用于存储所有直属下级的业绩
  2364. // 遍历每个直属下级
  2365. foreach ($get_childs as $child) {
  2366. // 获取当前下级及其子级
  2367. $child_group = [$child];
  2368. $recursive_children = $this->getRecursiveChildren_getcon($child);
  2369. $child_group = array_merge($child_group, $recursive_children);
  2370. // 获取当前分组的业绩
  2371. $result = $this->getteampv_getcon($child_group);
  2372. // 将直属下级的业绩加入数组
  2373. $all_departments[] = $result;
  2374. }
  2375. // 将传入的 $bigamount 和 $smallamount 加入数组
  2376. $all_departments[] = $bigamount;
  2377. $all_departments[] = $smallamount;
  2378. // 检查是否所有业绩都是 0
  2379. if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
  2380. return [0, 0];
  2381. }
  2382. // 初始化最大部门和小部门
  2383. $max_department = 0;
  2384. $small_department = 0;
  2385. // 遍历 $all_departments,找出最大值并累加小部门的值
  2386. foreach ($all_departments as $department) {
  2387. if ($department > $max_department) {
  2388. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  2389. if ($max_department != 0) {
  2390. $small_department += $max_department; // 将旧的最大值累加到小部门
  2391. }
  2392. $max_department = $department; // 更新最大部门
  2393. } else {
  2394. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  2395. $small_department += $department;
  2396. }
  2397. }
  2398. // 返回结果
  2399. return [
  2400. $max_department, // 大部门业绩
  2401. $small_department // 小部门业绩
  2402. ];
  2403. //拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
  2404. // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
  2405. }
  2406. //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  2407. public function getparents_child_pv_getcon($user_id){
  2408. // 获取直接下级的 UID 列表
  2409. //$user_id = 593;
  2410. // $get_childs = $this->getRecursiveChildren($user_id);
  2411. $get_childs = Db::name("user")
  2412. ->where("spread_uid", $user_id)
  2413. ->column("uid"); // 获取子级的 uid 列表
  2414. //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
  2415. //获取直接下级
  2416. $children_group = []; // 用于存储每个直接下级及其子级的分组
  2417. // 遍历每个直接下级
  2418. foreach ($get_childs as $child) {
  2419. $child_group = [$child]; // 将直接下级加入分组
  2420. $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
  2421. $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
  2422. $children_group[] = $child_group; // 将分组加入最终结果
  2423. }
  2424. $get_teams_comm_datas = [];
  2425. foreach($children_group as $v){
  2426. $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  2427. }
  2428. if(count($get_teams_comm_datas) > 0){
  2429. // 找到最大值作为大部门
  2430. $max_value = max($get_teams_comm_datas);
  2431. $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
  2432. // 小部门为总和减去最大值
  2433. $small_department = $total_sum - $max_value;
  2434. //返回大部门和小部门
  2435. return [
  2436. $max_value,
  2437. $small_department
  2438. ];
  2439. }else{
  2440. return [
  2441. 0,
  2442. 0
  2443. ];
  2444. }
  2445. }
  2446. }