Auth.php 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806
  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,$data['spread']);
  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. return app('json')->success($repository->returnToken($user, $tokenInfo));
  508. }
  509. /**
  510. * 手机号找回密码
  511. * @param UserRepository $repository
  512. * @return mixed
  513. * @throws DbException
  514. * @author xaboy
  515. * @day 2020/6/1
  516. */
  517. public function reset(UserAuthValidate $validate, UserRepository $repository){
  518. $data = $this->request->params(['account', 'captcha', 'code', 'password']);
  519. $data['phone'] = $data['account'];
  520. $data['sms_code'] = $data['captcha'];
  521. $validate->sceneSmslogin()->check($data);
  522. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  523. return app('json')->fail('验证码不正确');
  524. $user = $repository->accountByUser($data['account']);
  525. if ($user){
  526. $res = $repository->resetPassword($data['account'], $data['password'], $user['uid']);
  527. if($res){
  528. return app('json')->success('重置成功');
  529. }
  530. }
  531. return app('json')->error('重置失败');
  532. }
  533. /**
  534. * 旧密码找回密码
  535. * @param UserRepository $repository
  536. * @return mixed
  537. * @throws DbException
  538. * @author xaboy
  539. * @day 2021/1/21
  540. */
  541. public function oldreset(UserRepository $repository){
  542. $user = $this->request->userInfo()
  543. ->hidden(['label_id', 'group_id', 'card_id', 'last_time', 'last_ip', 'status', 'spread_uid', 'spread_time', 'real_name', 'brokerage_price']);
  544. $user->append(['account','pwd','phone',"uid"]);
  545. $user=$user->toArray();
  546. // $user = $this->request->userInfo()->hidden(['account','pwd','phone',"uid"]);
  547. // $user=$this->request->userInfo();
  548. $data = $this->request->params(['passwordold', 'password']);
  549. if (!$user)
  550. return app('json')->fail('密码错误');
  551. if (!password_verify($pwd = (string)$data["passwordold"], $user['pwd']))
  552. return app('json')->fail('密码错误1');
  553. // UserRepository $repository
  554. $user = $repository->accountByUser($user['account']);
  555. if ($user){
  556. $res = $repository->resetPassword($user['account'], $data['password'], $user['uid']);
  557. if($res){
  558. return app('json')->success('重置成功');
  559. }
  560. }
  561. return app('json')->error('重置失败');
  562. }
  563. /*手机号验证
  564. * @author cabbage
  565. * */
  566. public function checkAccount(UserAuthValidate $validate, UserRepository $repository){
  567. $data = $this->request->params(['account', 'captcha']);
  568. $data['phone'] = $data['account'];
  569. $data['sms_code'] = $data['captcha'];
  570. $validate->sceneSmslogin()->check($data);
  571. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  572. return app('json')->fail('验证码不正确');
  573. $user = $repository->accountByUser($data['account']);
  574. if ($user) {
  575. return app('json')->success('验证成功');
  576. }else{
  577. return app('json')->error('旧手机验证失败');
  578. }
  579. }
  580. /**
  581. * 更换手机号
  582. * @param UserRepository $repository
  583. * @return mixed
  584. * @throws DbException
  585. * @author cabbage
  586. */
  587. public function changeAccount(UserAuthValidate $validate,UserRepository $repository){
  588. $data = $this->request->params(['account', 'new_account','captcha']);
  589. $data['phone'] = $data['new_account'];
  590. $data['sms_code'] = $data['captcha'];
  591. $validate->sceneSmslogin()->check($data);
  592. if (!$this->checkSmsCode($data['new_account'], $data['captcha']))
  593. return app('json')->fail('验证码不正确');
  594. $user = $repository->accountByUser($data['account']);
  595. if ($user){
  596. $res = $repository->resetAccount($data['new_account'],$user['uid'],$user['identity']);
  597. if($res){
  598. return app('json')->success('重置成功');
  599. }
  600. }
  601. return app('json')->error('重置失败');
  602. }
  603. /**
  604. * 获取用户信息
  605. * @return mixed
  606. * @author xaboy
  607. * @day 2020/6/1
  608. */
  609. public function userInfo()
  610. {
  611. $user = $this->request->userInfo()
  612. ->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  613. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  614. $data=$user->toArray();
  615. $is_merchant=Db::name("merchant_intention")->where(["uid"=>$user["uid"],"is_branch"=>0])->order("mer_intention_id desc")->value("status");
  616. $data["is_merchant"]=$is_merchant===0||$is_merchant>0?$is_merchant:-1;
  617. $data['phone1'] =substr($data['phone'], 0, 3) . '****' . substr($data['phone'], 7, 4);
  618. $data['longtime'] = intval((time()- strtotime($data['create_time'])) / 86400);
  619. $is_ertification=Db::name("user_certification")->where("uid",$user["uid"])->value("status");
  620. $data["is_ertification"]=$is_ertification>0||$is_ertification===0?$is_ertification:-1;
  621. $mer_staff=Db::name("store_staff")->where(["uid"=>$user["uid"]])->value("department");
  622. $data["is_mer_staff"]=$mer_staff?explode(",",$mer_staff):0;
  623. $volunteer = Db::name("volunteer") -> where(["uid"=>$user["uid"]]) -> value("grade");
  624. $data['volunteer'] = $volunteer ?? 0;
  625. if($data['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  626. $data['avatar']=Db::name('user_account')->where('type',1)->where('uid',$data['uid'])->value('avater');
  627. if(empty($data['avatar'])){
  628. $data['avatar']=Db::name('user_account')->where('type',2)->where('uid',$data['uid'])->value('avater');
  629. if(empty($data['avatar'])){
  630. $data['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  631. }
  632. }
  633. }
  634. //养老金展示
  635. // $data['annuity'] = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',1) -> sum('number');
  636. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',0) -> sum('number');
  637. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',1) -> sum('number');
  638. $data['annuity'] = $a +$b;
  639. //上级身份是否大仓会员
  640. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$user["uid"])->find();
  641. //渠道商
  642. $is_channel = Db::name('channel_user') -> where('uid',$user["uid"])->where('status',1)->find();
  643. //红积分
  644. $red = Db::name('user_rich') -> where('uid',$user['uid'])->value('red');
  645. $data['is_da_cang_vip'] = 0;
  646. $data['is_channel'] = 0;
  647. $data['red'] = 0;
  648. if($is_da_cang_vip){
  649. $data['is_da_cang_vip'] = $is_da_cang_vip['type'];
  650. }
  651. if($is_channel){
  652. $data['is_channel'] = 1;
  653. }
  654. if ($red){
  655. $data['red'] = $red;
  656. }
  657. $aa = Db::name('user') -> where('uid',$user['uid'])->find();//查询用户个人数据
  658. $teamsnums = $this->getteamsnum($user['uid']);
  659. //$team_userinfo_old_jbp1 = $this->getPerformance($teamid);//获取旧表总大小部门人数
  660. //$data['team_number'] = $this->getBreak($user['uid']);//获取新表大小部门总人数
  661. $data['team_number'] = $teamsnums;
  662. $data['is_bangfu'] = Db::name('user_bangfu') -> where('uid',$user["uid"])->value('status')==1;
  663. // $data['area_manage'] = Db::name('area_manage')->field('type,code_list')->where('uid',$user["uid"])->find();
  664. // if($data['area_manage']){
  665. // $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');
  666. // if($area_manage){
  667. // $area_manage = array_column($area_manage,'name','id');
  668. // $code_list = explode(',',$data['area_manage']['code_list']);
  669. // $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]]];
  670. // }
  671. // }
  672. $user_rich=Db::name('user_rich')->where('uid', $user['uid'])->field('type,stockholder,is_huitian')->find();
  673. $data['user_rich_type']= (isset($user_rich) )?$user_rich['type']:0;
  674. $data['stockholder']= (isset($user_rich) )?$user_rich['stockholder']:0;
  675. // $area_manage_type=Db::name('area_manage')->where('uid', $user["uid"])->value('type');
  676. //类型 district-区/县代 city-市代',
  677. // $data['area_manage_type']=$area_manage_type??'';
  678. // $data['member_brokerage_price']=set_price_rtrim($data['member_brokerage_price']);
  679. //积分
  680. $data['score']=set_price_rtrim($data['score']);
  681. //2025新增 贡献值,红包,京东,vr,复购金
  682. // 老逻辑 需要废弃
  683. // if( $user['user_group'] <= 2 ){
  684. // $data['contribute'] = $user['contribute'] + $user['per_contribute'];
  685. // }else{
  686. // $data['contribute'] = $user['contribute'];
  687. // }
  688. $date['contribute']=set_price_rtrim($data['contribute']);//贡献值
  689. $data['repurchase_price']=set_price_rtrim($data['repurchase_price']);//复购余额
  690. $data['jingdou']=set_price_rtrim($data['jingdou']);//京豆
  691. $data['vr']=set_price_rtrim($data['vr']);//购物金
  692. $data['hongbao']=set_price_rtrim($data['hongbao']);//红包
  693. $data['fugou']=set_price_rtrim($data['fugou']);//复购金
  694. $data['brokerage_price']=set_price_rtrim($data['brokerage_price']);//养老金
  695. $data['annuity'] = set_price_rtrim($data['annuity']);//养老金
  696. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',0) -> sum('number');
  697. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',1) -> sum('number');
  698. // $data['brokerage_price'] = $a +$b;
  699. $data['brokerage_price'] = $aa['brokerage_price'];
  700. $data['isOld']=($data['is_old']);//
  701. $data['exchange']=0;
  702. $data['withdraw']=0;
  703. $data['user_group']=set_price_rtrim($data['user_group']);
  704. if($this->source=='yhc'){
  705. $data['avatar']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  706. $data['exchange']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('exchange');
  707. //withdraw 是否可以提现 0-可以 1-禁止
  708. $data['withdraw']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('withdraw');
  709. }
  710. //普通用户,根据我的贡献值升级(个人消费贡献值+直推的消费产生的贡献值)
  711. $my_con = [];
  712. if($aa['user_group'] < 2){
  713. $my_con = [2,3];
  714. }else if($aa['user_group'] == 2){
  715. $my_con = [3];
  716. }
  717. $data['con_level'] = [
  718. 'my_con' => $aa['contribute'],//我的贡献值
  719. 'my_recon_con' => $aa['per_contribute'],//我推荐的贡献值
  720. 'curr_level' => $aa['user_group'],//当前用户级别身份
  721. 'change_level' => $my_con //可选的等级身份(业务员、业务经理)
  722. ];
  723. return app('json')->success($data );
  724. }
  725. public function updateUserCon(){
  726. $data = $this->request->params(['change_level','uid']);
  727. $uid = $data['uid'];
  728. if(empty($uid)){
  729. return app('json')->fail('找不到该用户!');
  730. }
  731. // $user = $this->request->userInfo();
  732. //var_dump($data);
  733. //var_dump($user);
  734. $aa = Db::name('user') -> where('uid',$uid)->find();//查询用户个人数据
  735. if(empty($aa)){
  736. return app('json')->fail('找不到该用户!');
  737. }
  738. // if(empty($data['my_con']) || empty($data['my_recon_con']) || empty($data['curr_level']) || empty($data['change_level'])){
  739. // return app('json')->fail('参数有误!');
  740. // }
  741. if($data['change_level'] <= $aa['user_group']){
  742. return app('json')->fail('升级失败,请重新选择!');
  743. }
  744. $dev_amount = 0;//需扣除的贡献值
  745. if($data['change_level'] == 2){
  746. $dev_amount = 1180;
  747. }else if($data['change_level'] == 3){
  748. $dev_amount = 11800;
  749. }
  750. //可升级用的贡献值
  751. $con_amount = $aa['contribute'] + $aa['per_contribute'];
  752. $cur_amount = $con_amount - $dev_amount;
  753. if( $cur_amount < 0){
  754. return app('json')->fail('升级失败,贡献值不足!');
  755. }
  756. // 判断总贡献值是否足够
  757. //推荐的贡献值够扣
  758. $yue_amount = $aa['per_contribute'] - $dev_amount;
  759. if( $yue_amount >= 0){
  760. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=> $yue_amount, 'user_group'=>$data['change_level']]);//查询用户个人数据
  761. if($aa){
  762. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  763. return app('json')->success('升级成功');
  764. }
  765. }else{
  766. //推荐的贡献值不够扣
  767. $yue_amount = $aa['contribute'] + $aa['per_contribute'] - $dev_amount;
  768. if( $yue_amount == 0){
  769. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>0 , 'user_group'=>$data['change_level']]);//
  770. if($aa){
  771. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  772. return app('json')->success('升级成功');
  773. }
  774. }else if($yue_amount > 0){
  775. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>$yue_amount, 'user_group'=>$data['change_level']]);//查询用户个人数据
  776. if($aa){
  777. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  778. return app('json')->success('升级成功');
  779. }
  780. }
  781. }
  782. }
  783. public function con_logs($uid,$num,$order_id,$order_type,$mark,$status = -1,$state){
  784. $con_data = Db::name('user')->where("uid",$uid)->find();
  785. $con = [
  786. 'uid'=>$uid,
  787. 'number'=>$num,//赠送数量
  788. 'status'=>$status,//红包状态
  789. 'mark'=>$mark,//备注
  790. 'desc'=>'',//描述
  791. 'order_id'=>$order_id,//订单id
  792. 'surplus'=> $con_data['contribute'],//剩余
  793. 'order_type'=>$order_type,//订单类型
  794. 'type'=>$state,//1增加,2消耗
  795. 'settlement_time'=>date('Y-m-d H:i:s'),
  796. 'addtime'=>time()
  797. ];
  798. Db::name('user_sign_gongxian')->insert($con);
  799. }
  800. public function getteamsnum($teamid){
  801. // $subordinate_members = Db::name('user')
  802. // ->alias('u')
  803. // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  804. // ->where("u.spread_uid", $teamid)
  805. // ->where("so.mer_id", 496)
  806. // ->group('u.uid')
  807. //
  808. // ->select();
  809. //
  810. //
  811. // $total_amount_pv_team = 0;
  812. // $team_count_total = 0;
  813. //
  814. // foreach ($subordinate_members as $k => $v) {
  815. // $t_teams_pv = $this->calculatePerformance($v['uid']);
  816. // $total_amount_pv_team += $t_teams_pv['total_performance'];
  817. // $team_count_total += $t_teams_pv['team_count'];
  818. //
  819. //
  820. // }
  821. return Db::name('user')->where(['level_id'=>$teamid])->count();
  822. }
  823. //计算自己和自己团队下面的业绩。新表
  824. public function calculatePerformance($uid)
  825. {
  826. // 初始化业绩数组
  827. $performance = [
  828. 'personal_performance' => 0, // 个人业绩
  829. 'team_performance' => 0, // 团队业绩
  830. 'total_performance' => 0, // 总业绩
  831. 'team_count' => 0, // 加上自己的团队数量
  832. ];
  833. // 定义业绩换算规则
  834. $performanceMapping = [
  835. 1180 => 700,
  836. 10620 => 6300,
  837. 11800 => 7000
  838. ];
  839. // 计算个人业绩
  840. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  841. if ($personalOrder) {
  842. // 将浮点数转换为整数
  843. $totalPrice = (int)$personalOrder['total_price'];
  844. if (isset($performanceMapping[$totalPrice])) {
  845. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  846. }
  847. }
  848. // 计算旗下团队成员的业绩
  849. $teamOrders = Db::name('user')
  850. ->alias('u')
  851. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  852. ->where("u.spread_uid", $uid) // 查询旗下会员
  853. ->where("so.mer_id", 496)
  854. // ->where("so.douhuomall", 1)
  855. // ->where("so.douhuomall_status", 9)
  856. // ->where("so.status", 0)
  857. ->select();
  858. $teamOrders_count = Db::name('user')
  859. ->alias('u')
  860. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  861. ->where("u.spread_uid", $uid) // 查询旗下会员
  862. ->where("so.mer_id", 496)
  863. // ->where("so.douhuomall", 1)
  864. // ->where("so.douhuomall_status", 9)
  865. // ->where("so.status", 0)
  866. ->count();
  867. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  868. foreach ($teamOrders as $order) {
  869. if ($order['total_price']) {
  870. // 将浮点数转换为整数
  871. $totalPrice = (int)$order['total_price'];
  872. if (isset($performanceMapping[$totalPrice])) {
  873. $performance['team_performance'] += $performanceMapping[$totalPrice];
  874. }
  875. }
  876. }
  877. // 计算总业绩
  878. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  879. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  880. return $performance;
  881. }
  882. //获取大小部门业绩(新表)
  883. public function getbig_samll_datas($subordinate_members){
  884. //单独写一个方法获取大小部门的数据
  885. $arr_team = [];
  886. foreach ($subordinate_members as $k => $v) {
  887. //计算自己和旗下的业绩
  888. $arr_team[] = $this->calculatePerformance($v['uid']);
  889. }
  890. // 初始化变量
  891. $maxPerformance = 0;
  892. $maxIndex = -1;
  893. // 找出 total_performance 最高的记录
  894. foreach ($arr_team as $index => $item) {
  895. if ($item['total_performance'] > $maxPerformance) {
  896. $maxPerformance = $item['total_performance'];
  897. $maxIndex = $index;
  898. }
  899. }
  900. // 如果找到了最高记录
  901. if ($maxIndex !== -1) {
  902. // 提取最高记录
  903. $maxRecord = $arr_team[$maxIndex];
  904. // 从原数组中移除该记录
  905. unset($arr_team[$maxIndex]);
  906. // 重新索引数组
  907. $arr_team = array_values($arr_team);
  908. } else {
  909. // 如果没有找到记录,可以设置一个默认值
  910. $maxRecord = null;
  911. }
  912. // 计算大部门和小部门的汇总信息
  913. $majorDepartmentSummary = [
  914. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  915. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  916. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  917. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  918. "data" => $maxRecord ? [$maxRecord] : []
  919. ];
  920. $minorDepartmentSummary = [
  921. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  922. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  923. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  924. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  925. "data" => $arr_team
  926. ];
  927. // 输出结果
  928. // echo "大部门汇总信息:\n";
  929. // print_r($majorDepartmentSummary);
  930. // echo "小部门汇总信息:\n";
  931. // print_r($minorDepartmentSummary);
  932. return array($majorDepartmentSummary,$minorDepartmentSummary);
  933. }
  934. public function getBreak($uid,$list=[],$count=0){
  935. $sql = "select getUserLevelId($uid) as count";
  936. $count = Db::query($sql);
  937. return count(explode(",",$count[0]['count'])) - 1;
  938. }
  939. /**
  940. * 整合用户登录token
  941. * @return mixed
  942. * @author xaboy
  943. * @day 2020/6/1
  944. */
  945. public function tokenList()
  946. {
  947. $user = $this->request->userInfo()->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  948. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  949. $userInfo = $user->toArray();
  950. $temp = $this->curl_java_login($userInfo['phone']);
  951. $data['mweb_info'] = [];
  952. if(isset($temp['data'])){
  953. $data['mweb_info'] = $temp['data'];
  954. }
  955. $data['merchant_info'] = [];
  956. return app('json')->success($data);
  957. }
  958. function curl_java_login($phone){
  959. $curl = curl_init();
  960. curl_setopt_array($curl, array(
  961. CURLOPT_URL => env('APP_URL') . '/gateway/userCenter_service/userLogOnService/userPhoneLogOn',
  962. CURLOPT_RETURNTRANSFER => true,
  963. CURLOPT_ENCODING => '',
  964. CURLOPT_MAXREDIRS => 10,
  965. CURLOPT_TIMEOUT => 0,
  966. CURLOPT_FOLLOWLOCATION => true,
  967. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  968. CURLOPT_CUSTOMREQUEST => 'POST',
  969. CURLOPT_POSTFIELDS =>'{"phone":'.$phone.',"sms_code":"9527","type":"1"}',
  970. CURLOPT_HTTPHEADER => array(
  971. 'Content-Type: application/json'
  972. ),
  973. ));
  974. $response = curl_exec($curl);
  975. curl_close($curl);
  976. $response = json_decode($response, true);
  977. return $response;
  978. }
  979. /**
  980. * 获取用户信息
  981. * @return mixed
  982. * @author xaboy
  983. * @day 2020/6/1
  984. */
  985. public function userVolunteer()
  986. {
  987. $uid = $this->request->uid();
  988. $volunteer = Db::name("volunteer") -> where(["uid"=>$uid]) -> find();
  989. // $volunteer_class = app()->make(Volunteer::class);
  990. $volunteer_class = new Volunteer();
  991. $volunteerData = $volunteer_class -> volunteer($uid);
  992. $data['grade'] = 0;
  993. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  994. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  995. if($volunteer){
  996. $data = $volunteer;
  997. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  998. if($volunteer['grade'] == 1){
  999. $data['condition_one'] = systemConfig("a_volunteer_achievement");//团队养老金要求
  1000. $data['condition_two'] = systemConfig("a_volunteer_number");//团队人数要求
  1001. }
  1002. if($volunteer['grade'] == 2){
  1003. $data['condition_one'] = systemConfig("b_volunteer_achievement");//团队养老金要求
  1004. $data['condition_two'] = systemConfig("b_volunteer_number");//团队人数要求
  1005. }
  1006. if($volunteer['grade'] == 3){
  1007. $data['condition_one'] = systemConfig("c_volunteer_achievement");//团队养老金要求
  1008. $data['condition_two'] = systemConfig("c_volunteer_number");//团队人数要求
  1009. }
  1010. if($volunteer['grade'] == 4){
  1011. $data['condition_one'] = systemConfig("d_volunteer_achievement");//团队养老金要求
  1012. $data['condition_two'] = systemConfig("d_volunteer_number");//团队人数要求
  1013. }
  1014. }
  1015. return app('json')->success($data);
  1016. }
  1017. /**
  1018. * @param UserRepository $repository
  1019. * @return mixed
  1020. * @author xaboy
  1021. * @day 2020/6/1
  1022. */
  1023. public function logout(UserRepository $repository)
  1024. {
  1025. $repository->clearToken($this->request->token());
  1026. return app('json')->success('退出登录');
  1027. }
  1028. /**
  1029. * @return mixed
  1030. * @throws DataNotFoundException
  1031. * @throws DbException
  1032. * @throws ModelNotFoundException
  1033. * @author xaboy
  1034. * @day 2020-05-11
  1035. */
  1036. public function auth()
  1037. {
  1038. $request = $this->request;
  1039. $oauth = WechatService::create()->getApplication()->oauth;
  1040. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1041. try {
  1042. $wechatInfo = $oauth->user()->getOriginal();
  1043. } catch (\Exception $e) {
  1044. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1045. }
  1046. if (!isset($wechatInfo['nickname'])) {
  1047. return app('json')->fail('授权失败[002]');
  1048. }
  1049. /** @var WechatUserRepository $make */
  1050. $make = app()->make(WechatUserRepository::class);
  1051. $user = $make->syncUser($wechatInfo['openid'], $wechatInfo);
  1052. if (!$user)
  1053. return app('json')->fail('授权失败[003]');
  1054. /** @var UserRepository $make */
  1055. $userRepository = app()->make(UserRepository::class);
  1056. $user[1] = $userRepository->mainUser($user[1]);
  1057. $pid = $this->request->param('spread', 0);
  1058. $userRepository->bindSpread($user[1], intval($pid));
  1059. $tokenInfo = $userRepository->createToken($user[1]);
  1060. $userRepository->loginAfter($user[1]);
  1061. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1062. }
  1063. protected function returnToken($user, $tokenInfo)
  1064. {
  1065. $CommonRepository = app()->make(Common::class);
  1066. $access_token ='75_-8y0OT8i5w72EkPCLpCQoGFGa2Ir42T8RHvqZPLJ4sjn27s6Aj7RUEO5yJX77pzHVoo34zXpeBS0M-gdNegdCRB4FWhkAqxmuhdrANkenSHdrmEvPSWQex4OKFQXLBfAEAJXN';
  1067. var_dump($access_token);
  1068. $unionid = "oGtg_6E5SwAcXhv5Do5z3GL_UMXw";
  1069. $unionid = "o4-On50WzIkkbJsf-apbBE3VB1O0";
  1070. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $unionid . "&lang=zh_CN";
  1071. }
  1072. /**
  1073. * @return mixed
  1074. * @throws DataNotFoundException
  1075. * @throws DbException
  1076. * @throws ModelNotFoundException
  1077. * @author xaboy
  1078. * @day 2020-05-11
  1079. */
  1080. public function mpAuth()
  1081. {
  1082. list($code, $post_cache_key) = $this->request->params([
  1083. 'code',
  1084. 'cache_key',
  1085. ], true);
  1086. $session_key = Cache::get('eb_api_code_' . $post_cache_key);
  1087. if (!$code && !$session_key)
  1088. return app('json')->fail('授权失败,参数有误');
  1089. $miniProgramService = MiniProgramService::create();
  1090. if ($code && !$session_key) {
  1091. try {
  1092. $userInfoCong = $miniProgramService->getUserInfo($code);
  1093. $session_key = $userInfoCong['session_key'];
  1094. $cache_key = md5(time() . $code);
  1095. Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
  1096. } catch (\Exception $e) {
  1097. return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  1098. }
  1099. }
  1100. $data = $this->request->params([
  1101. ['spread_spid', 0],
  1102. ['spread_code', ''],
  1103. ['iv', ''],
  1104. ['encryptedData', ''],
  1105. ]);
  1106. try {
  1107. //解密获取用户信息
  1108. $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
  1109. } catch (\Exception $e) {
  1110. if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
  1111. throw $e;
  1112. }
  1113. if (!$userInfo || !isset($userInfo['openId'])) return app('json')->fail('openid获取失败');
  1114. if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
  1115. /** @var WechatUserRepository $make */
  1116. $make = app()->make(WechatUserRepository::class);
  1117. $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
  1118. if (!$user)
  1119. return app('json')->fail('授权失败');
  1120. /** @var UserRepository $make */
  1121. $userRepository = app()->make(UserRepository::class);
  1122. $user[1] = $userRepository->mainUser($user[1]);
  1123. //获取是否有扫码进小程序
  1124. if (isset($data['spread_code']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']))) {
  1125. $data['spread_spid'] = $info['third_id'];
  1126. }
  1127. $userRepository->bindSpread($user[1], intval($data['spread_spid']));
  1128. $tokenInfo = $userRepository->createToken($user[1]);
  1129. $userRepository->loginAfter($user[1]);
  1130. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1131. }
  1132. public function getCaptcha()
  1133. {
  1134. $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
  1135. $key = uniqid(microtime(true), true);
  1136. Cache::set('api_captche' . $key, $codeBuilder->getPhrase(), 300);
  1137. $captcha = $codeBuilder->build()->inline();
  1138. $code = $codeBuilder->getPhrase();
  1139. return app('json')->success(compact('key', 'code', 'captcha'));
  1140. }
  1141. protected function checkCaptcha($uni, string $code): bool
  1142. {
  1143. $cacheName = 'api_captche' . $uni;
  1144. if (!Cache::has($cacheName)) return false;
  1145. $key = Cache::get($cacheName);
  1146. $code = mb_strtolower($code, 'UTF-8');
  1147. $res = password_verify($code, $key);
  1148. if ($res) Cache::delete($cacheName);
  1149. return $res;
  1150. }
  1151. /**
  1152. * 获取验签公钥
  1153. * @return Response
  1154. */
  1155. public function getPublicKey(): Response
  1156. {
  1157. $path = env('RSA_PUBLIC_KEY_PATH');
  1158. if (empty($path)) {
  1159. return json([
  1160. 'code' => 500,
  1161. 'msg' => '公钥路径未配置',
  1162. 'data' => null
  1163. ]);
  1164. }
  1165. if (!file_exists($path)) {
  1166. return json([
  1167. 'code' => 500,
  1168. 'msg' => '公钥文件不存在: ' . $path,
  1169. 'data' => null
  1170. ]);
  1171. }
  1172. $publicKey = file_get_contents($path);
  1173. return json([
  1174. 'code' => 200,
  1175. 'msg' => 'success',
  1176. 'data' => [
  1177. 'public_key' => $publicKey
  1178. ]
  1179. ]);
  1180. }
  1181. public function verify(UserAuthValidate $validate)
  1182. {
  1183. $data = $this->request->params(['phone', 'code', 'key',"type"]);
  1184. $validate->sceneVerify()->check($data);
  1185. log::info("发送短信方法");
  1186. if ($data['type']=="register"){
  1187. $count=Db::name("user")->where("phone", $data["phone"])->count();
  1188. if ($count){
  1189. return app('json')->make(405, '该手机号已注册');
  1190. }
  1191. }
  1192. $sms_num_key = 'api.auth.num.' . $data['phone'];
  1193. $sms_key = 'api.auth.sms.' . $data['phone'];
  1194. $num = Cache::get($sms_num_key) ? Cache::get($sms_num_key) : 0;
  1195. log::info("num{$num}" );
  1196. if ($num > 9) {
  1197. if (!$data['code'])
  1198. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  1199. if (!$this->checkCaptcha($data['key'], $data['code']))
  1200. return app('json')->fail('验证码输入有误');
  1201. }
  1202. $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
  1203. $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ;
  1204. $res = app()->make(AliYunSmsService::class)->send($data['phone'], $sms_code);
  1205. if($res['Code']!='OK'){
  1206. Db::name('log')->insert(['data'=>'幸福保短信发送失败:'.json_encode($res,256)]);
  1207. return app('json')->fail('操作过于频繁,请稍后重试~');
  1208. }
  1209. log::info("sms_key==={$sms_key}" );
  1210. log::info("sms_code==={$sms_code}" );
  1211. log::info("sms_time==={$sms_time}" );
  1212. Cache::set($sms_key, $sms_code,$sms_time * 60);
  1213. Cache::set($sms_num_key, $num + 1, 300);
  1214. //'短信发送成功'
  1215. return app('json')->success('短信发送成功');
  1216. }
  1217. /**
  1218. * 一壶茶查询邀请人信息 1-根据手机号查询uid 2-根据uid查手机号
  1219. * @return mixed
  1220. * @throws DataNotFoundException
  1221. * @throws DbException
  1222. * @throws ModelNotFoundException
  1223. */
  1224. public function query_uid(){
  1225. $phone = $this->request->param('phone');
  1226. $uid = $this->request->param('uid',0);
  1227. $share_id = $this->request->param('share_id',0);
  1228. $type = $this->request->param('type',1);//1-根据手机号查询uid 2-根据uid查手机号 3-通过share_id 查询用户信息
  1229. if($this->source=='yhc' && $this->merId) {
  1230. $user=$this->inviter_verification($type,$uid,$phone,$share_id);
  1231. if($user!=false){
  1232. return app('json')->success('获取成功',$user);
  1233. }
  1234. }
  1235. return app('json')->fail('邀请人不存在');
  1236. }
  1237. private function inviter_verification($type,$uid='',$phone='',$share_id=''){
  1238. if($type==2) {
  1239. $where['uid'] = $uid;
  1240. }else if($type==3){
  1241. $where['uid'] = Db::name('product_share')->where('id', $share_id)->value('uid');
  1242. }else{
  1243. $where['account']=$phone;
  1244. }
  1245. $user =Db::name('user')->field('uid,account as phone')->where($where)->find();
  1246. if(!$user){
  1247. return false;
  1248. }
  1249. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1250. if(!$user2){
  1251. return false;
  1252. }
  1253. return $user;
  1254. }
  1255. /**
  1256. * 一壶茶判断这个手机号是否注册过
  1257. * @return mixed
  1258. * @throws DataNotFoundException
  1259. * @throws DbException
  1260. * @throws ModelNotFoundException
  1261. */
  1262. public function query_phone()
  1263. {
  1264. $phone = $this->request->param('phone','');
  1265. if($phone==''){
  1266. //解密微信手机号
  1267. $sessionKey=$this->request->params(['sessionKey']);
  1268. $encryptedData=$this->request->params(['encryptedData']);
  1269. $iv=$this->request->params(['iv']);
  1270. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1271. return app('json')->fail('参数不正确');
  1272. }
  1273. $appid = 'wx9082e5ac2fdb513f';//幸福宝小程序appid
  1274. if($this->source=='yhc'){
  1275. $appid = 'wx9082e5ac2fdb513f';//一壶茶小程序appid
  1276. }
  1277. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1278. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1279. $iv =str_replace(' ','+', $iv['iv']);
  1280. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1281. $errCode = $pc->decryptData($encryptedData, $iv, $wx_data_str );
  1282. if ($errCode != 0) {
  1283. return app('json')->fail('没有获取到手机号');
  1284. }
  1285. // dump($data);
  1286. $wx_data=json_decode($wx_data_str,true);
  1287. if(isset($wx_data['purePhoneNumber'])){
  1288. $phone=$wx_data['purePhoneNumber'];
  1289. }
  1290. }
  1291. $validate= new UserAuthValidate();
  1292. $validate->sceneVerify()->check(['phone'=>$phone]);
  1293. if($this->source=='yhc' && $this->merId) {
  1294. $where['account']=$phone;
  1295. $user =Db::name('user')->field('uid')->where($where)->find();
  1296. if(!$user){
  1297. return app('json')->fail('未注册');
  1298. }
  1299. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1300. if($user2){
  1301. return app('json')->success('已注册');
  1302. }
  1303. }
  1304. return app('json')->fail('未注册');
  1305. }
  1306. public function smsLogin(UserAuthValidate $validate, UserRepository $repository)
  1307. {
  1308. $data = $this->request->params(['phone', 'sms_code', 'spread', 'share_id']);
  1309. // $data = $this->request->params(['phone', 'sms_code']);
  1310. $validate->sceneSmslogin()->check($data);
  1311. $domain = $this->request->domain();
  1312. //如果手机验证码错误并且验证码不是6865,进入查验团队验证码环节
  1313. if (!$this->checkSmsCode($data['phone'], $data['sms_code']) && $data['sms_code'] !== '6865') {
  1314. $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');//通过输入的手机号查询用户的uid
  1315. if($uid){
  1316. $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();//去user_zero_line表查询团队team_uid和团队自定义的验证码
  1317. $hasTeam = false; //先将用户设成不为团队成员
  1318. foreach ($allTeams as $team) {
  1319. $cacheKey = 'team_members_' . $team['team_uid'];
  1320. $member_uids = Cache::get($cacheKey);
  1321. $sql = "select getUserLevelId({$team['team_uid']}) as uids"; //查询所有团队下成员的uid
  1322. $spread_user_list = Db::query($sql);
  1323. $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
  1324. Cache::set($cacheKey, $member_uids, 300); //结果缓存5分钟
  1325. if (in_array($uid, $member_uids)){
  1326. $hasTeam = true; //若用户属于团队,将其设为团队成员
  1327. if ($data['sms_code'] != $team['custom_code']) {
  1328. return app('json')->fail('验证码不正确'); //如果与用户所属团队的验证码不一致,返回验证码不正确
  1329. }
  1330. break;
  1331. }
  1332. }
  1333. if (!$hasTeam) {
  1334. return app('json')->fail('验证码不正确');
  1335. }
  1336. } else {
  1337. return app('json')->fail('验证码不正确');
  1338. }
  1339. }
  1340. $user = $repository->accountByUser($data['phone']);
  1341. if (!$user){
  1342. $data['spread_uid'] = 0;
  1343. if (intval($data['share_id'])) {
  1344. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1345. $data['spread_uid'] = $spread_uid;
  1346. }
  1347. $user = $repository->registr($data['phone'], null, 'h5', '','',1, $data['spread_uid']);
  1348. }
  1349. $user = $repository->mainUser($user);
  1350. // if($this->source=='yhc' && $this->merId){
  1351. // $where=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1352. // $count=Db::name('enterprise_user')->where($where)->count();
  1353. // if($count<1){
  1354. // $insert=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1355. // if (!intval($data['spread'])) {
  1356. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1357. // }else{
  1358. // $spread_uid=$data['spread'];
  1359. // }
  1360. // if($this->inviter_verification(2,$spread_uid)==false){
  1361. // return app('json')->fail('请输入正确邀请人手机号');
  1362. // }
  1363. // $insert['puid']= $spread_uid;
  1364. // $insert['node_uid']= $spread_uid;
  1365. // Db::name('enterprise_user')->insert($insert);
  1366. // }
  1367. // }
  1368. // $repository->bindSpread($user, intval($data['spread']));
  1369. $tokenInfo = $repository->createToken($user);
  1370. $repository->loginAfter($user);
  1371. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1372. }
  1373. public function merJavaRegister(UserRepository $repository){
  1374. $data = $this->request->params(['phone', 'spread','token','sign']);
  1375. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  1376. // 校验sign
  1377. $checkSign = Signature::checkSign($data);
  1378. if (!$checkSign) {
  1379. Log::channel("gong")->error('sign校验失败');
  1380. return app('json')->fail('sign校验失败');
  1381. }
  1382. $user = $repository->accountByUser($data['phone']);
  1383. if (!$user) $user = $repository->registr($data['phone'], $data['password'],'MP',intval($data['spread']));
  1384. $user = $repository->mainUser($user);
  1385. $repository->bindSpread($user, intval($data['spread']));
  1386. $repository->loginAfter($user);
  1387. return app('json')->success($user);
  1388. }
  1389. /**
  1390. * @param $phone
  1391. * @param $code
  1392. * @return bool
  1393. * @author Qinii
  1394. * @day 2020-06-12
  1395. */
  1396. public function checkSmsCode($phone, $code)
  1397. {
  1398. $sms_key = 'api.auth.sms.' . $phone;
  1399. //log::info("缓存===code=={$sms_key}");
  1400. //log::info( Cache::get($sms_key));
  1401. //log::info("页面传值==={$code}");
  1402. if (!$cache_code = Cache::get($sms_key)) return false;
  1403. if ($code != $cache_code) return false;
  1404. Cache::delete($sms_key);
  1405. return true;
  1406. }
  1407. //批量生产100个账号
  1408. public function register_all(UserAuthValidate $validate, UserRepository $repository){
  1409. $datas = $this->request->params(['start', 'end','phone']);
  1410. if(mb_strlen($datas['start'].$datas['phone']) != 11 || mb_strlen($datas['end'].$datas['phone']) != 11){
  1411. return app("json")->fail('参数错误');
  1412. }
  1413. for($i=$datas['start'];$i<=$datas['end'];$i++)//这个dao是看你要生成多答少个数字,然后循环生成
  1414. {
  1415. $data=[
  1416. "phone"=>$datas['phone'].$i,
  1417. 'password'=>"123456"
  1418. ];
  1419. $user = $repository->registr($data['phone'], $data['password']);
  1420. $data=[
  1421. 'user_name'=>"测试".$i,
  1422. "mobile"=>"15555555187",
  1423. "user_card"=>"410181198508206517",
  1424. "card_positive"=>"https://app.bjtdba.com/uploads/def/20201030/088ecbdfa81534fadcc7c731d11c0594.jpg",
  1425. "card_reverse"=>"https://app.bjtdba.com/uploads/def/20201030/7546811225c6b5df37a7f41250ba3e66.jpg",
  1426. "status"=>1,
  1427. "create_time"=>time(),
  1428. "update_time"=>time(),
  1429. "uid"=>$i
  1430. ];
  1431. Db::name("user_certification")->insert($data);
  1432. }
  1433. return app("json")->success('成功');
  1434. }
  1435. public function phoneCheck(UserRepository $repository){
  1436. $data = $this->request->params(['phone']);
  1437. $user = $repository->accountByUser($data['phone']);
  1438. if($user){
  1439. return app("json")->success('手机号已注册,可直接绑定',1);
  1440. }else{
  1441. return app("json")->success('手机号未注册,请输入密码',2);
  1442. }
  1443. }
  1444. /*支付宝获取签名*/
  1445. public function aliSign(){
  1446. $repository = app()->make(UserRepository::class);
  1447. $data = $repository ->aliSign();
  1448. return app("json")->success('ok',$data);
  1449. }
  1450. /*支付宝授权登录*/
  1451. public function aliCheck(){
  1452. $data = $this->request->params(['user_id']);
  1453. if(!$data['user_id'] || $data['user_id'] == '' || $data['user_id'] =='undefined'){
  1454. return app('json')->fail("异常操作");
  1455. }
  1456. $repository = app()->make(UserRepository::class);
  1457. $result = $repository ->aliCheck($data['user_id']);
  1458. if(isset($result['code']) && $result['code'] == 200){
  1459. $user = $repository->accountByUser($result['user']['account']);
  1460. $tokenInfo = $repository->createToken($user);
  1461. $repository->loginAfter($user);
  1462. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1463. }
  1464. return app("json")->success('ok',$result);
  1465. }
  1466. /*微信信息获取*/
  1467. public function getWechat(){
  1468. $repository = app()->make(UserRepository::class);
  1469. return app('json')->success($repository->getWechat());
  1470. }
  1471. /*微信授权登录*/
  1472. public function wechatCheck(){
  1473. $data = $this->request->params(['openid']);
  1474. // , 'nickname', 'avatar'
  1475. $data['nickname'] = $this->request->param('nickname', null);
  1476. $data['avatar'] = $this->request->param('avatar', null);
  1477. if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
  1478. return app('json')->fail("openid参数缺失");
  1479. }
  1480. $repository = app()->make(UserRepository::class);
  1481. if($this->source=='yhc'){
  1482. $result = $repository ->wechatCheckYhc($data['openid']);
  1483. }else{
  1484. $result = $repository ->wechatCheck($data['openid'], $data['nickname'], $data['avatar']);
  1485. }
  1486. if(isset($result['code']) && $result['code'] == 200){
  1487. $user = $repository->accountByUser($result['user']['account']);
  1488. $tokenInfo = $repository->createToken($user);
  1489. $repository->loginAfter($user);
  1490. if($this->source=='yhc'){
  1491. // $user=$user->toArray();
  1492. $user->avatar=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  1493. }
  1494. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1495. }
  1496. return app("json")->fail($result['msg']);
  1497. }
  1498. public function binding_yhc(UserAuthValidate $validate, UserRepository $repository)
  1499. {
  1500. $data = $this->request->params(['phone', 'third_user_id','type']);
  1501. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1502. return app('json')->fail("绑定失败");
  1503. }
  1504. $data['password'] = '123456';//密码已经去掉了。统一默认密码
  1505. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP','',0,"https://". $this->request->host(true));//2222
  1506. if($user){
  1507. $enterprise_user= Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->find();
  1508. if(!$enterprise_user){
  1509. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1510. }else if ($enterprise_user['openid']==''){
  1511. $update = ["openid" => $data['third_user_id']];
  1512. Db::name("enterprise_user")->where(['mer_id'=>$this->merId,'uid'=>$user->uid])->update($update);
  1513. }
  1514. // $pid = $this->request->param('spread', 0);
  1515. // $repository->bindSpread($user, intval($pid));
  1516. $tokenInfo = $repository->createToken($user);
  1517. $repository->loginAfter($user);
  1518. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1519. }else{
  1520. return app('json')->fail("绑定失败");
  1521. }
  1522. }
  1523. /**
  1524. * 支付宝微信注册绑定手机号
  1525. * type 1微信2支付宝
  1526. * third_user_id 微信openid 支付宝userId
  1527. * @param UserRepository $repository
  1528. */
  1529. public function binding(UserAuthValidate $validate, UserRepository $repository)
  1530. {
  1531. $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','sms']);
  1532. $data['nickName'] = $this->request->param('nickName', null);
  1533. $data['avatarUrl'] = $this->request->param('avatarUrl', null);
  1534. $share_id = $this->request->param('share_id', null);
  1535. $spread_uid = 0;
  1536. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1537. return app('json')->fail("绑定失败");
  1538. }
  1539. $data['password'] = '123456';//密码已经去掉了。统一默认密码
  1540. $validate->sceneSmslogin()->check($data);
  1541. if($data['sms'] != 1){
  1542. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1543. return app('json')->fail('验证码不正确');
  1544. }
  1545. if (!empty($share_id)) {
  1546. $spread_uid = Db::name('product_share')->where('id', $share_id)->value('uid');
  1547. }
  1548. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true), $spread_uid);//2222
  1549. if($user){
  1550. $userRepository = app()->make(UserRepository::class);
  1551. $userInfo = $userRepository->getOne(['uid' => $user->uid ?? $user['uid']]);
  1552. //绑定线下充值金额
  1553. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1554. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1555. $notBind = $unionUsersRepository->getAllNotBind($data['third_user_id']);
  1556. if ($notBind) {
  1557. $orderMerchantRepository->doBindUser($userInfo, $data['type']);
  1558. }
  1559. $user = $repository->accountByUser($data['phone']);
  1560. if ($data['type'] == 1) {
  1561. $data1 = ["wechat_user_id" => $data['third_user_id']];
  1562. // 屎山上边堆屎
  1563. $check = Db::name('user_extract_openid')->where('uid', $user->uid)->count();
  1564. if ($check < 1) {
  1565. Db::name("user_extract_openid")->insert([
  1566. 'uid' => $user->uid,
  1567. 'openid' => $data['third_user_id'],
  1568. 'type' => 1
  1569. ]);
  1570. }
  1571. if($this->source=='yhc' && $this->merId){ //一壶茶创建用户
  1572. $enterprise_user_count = Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->count();
  1573. if($enterprise_user_count<1){
  1574. $spread_data = $this->request->params(['spread', 'share_id']);
  1575. if (!intval($spread_data['spread'])) {
  1576. $spread_uid = Db::name('product_share')->where('id', $spread_data['share_id'])->value('uid');
  1577. }else{
  1578. $spread_uid=$spread_data['spread'];
  1579. }
  1580. if($this->inviter_verification(2,$spread_uid)==false){
  1581. return app('json')->fail('请输入正确邀请人手机号');
  1582. }
  1583. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1584. }
  1585. }
  1586. } else {
  1587. $data1 = ["ali_user_id" => $data['third_user_id']];
  1588. }
  1589. $data2 = [];
  1590. if (!is_null($data['nickName']) || !is_null($data['avatarUrl'])) {
  1591. $data2 = [
  1592. "type" => $data['type'],
  1593. "uid" => $user->uid,
  1594. "nickname" => $data['nickName'],
  1595. "avater" => $data['avatarUrl'],
  1596. ];
  1597. }
  1598. $userRepository -> updateUser($user->uid,$data1,$data2);
  1599. $pid = $this->request->param('spread', 0);
  1600. $repository->bindSpread($user, intval($pid));
  1601. $tokenInfo = $repository->createToken($user);
  1602. $repository->loginAfter($user);
  1603. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1604. }else{
  1605. return app('json')->fail("绑定失败");
  1606. }
  1607. }
  1608. public function queryHaike(){
  1609. $merch_no = $this->request->params(['merch_no']);
  1610. if(!isset($merch_no['merch_no']) || empty($merch_no['merch_no'])){
  1611. return app('json')->fail("请输入商户号");
  1612. }
  1613. $res = Db::name("haike_account")->where("merch_no",$merch_no['merch_no'])->select();
  1614. if(!$res){
  1615. return app('json')->fail("这个商户号没有账单");
  1616. }
  1617. $merch = Db::name('merchant') -> where("merch_no",$merch_no['merch_no']) -> find();
  1618. $data['商户号'] = $merch_no['merch_no'];
  1619. $data['商户名称'] = $merch["mer_name"];
  1620. $data['商户手机号'] = $merch["mer_phone"];
  1621. $data['结算金额'] = 0;
  1622. $data['结算手续费'] = 0;
  1623. foreach ($res as $key => $value){
  1624. $data['结算金额'] += $value['settle_accounts'];
  1625. $data['结算手续费'] += $value['settle_accounts_fee'];
  1626. }
  1627. echo "<pre>";
  1628. dump($data);
  1629. return 1;
  1630. }
  1631. public function createUserNumberAll(){
  1632. $userRepository = app()->make(UserRepository::class);
  1633. $user = Db::name('user') -> select();
  1634. foreach($user as $key => $value){
  1635. $userRepository -> createUserNumber($value['uid']);
  1636. }
  1637. }
  1638. /**
  1639. * @param int $uid 用户ID
  1640. * @param string $score 积分
  1641. * @param int $status 积分状态
  1642. * @param string $mark 备注
  1643. * @param string $has_qian 连续签到天数
  1644. * @param string $today_signintime 签到时间
  1645. * @param int $order_id 订单ID
  1646. * @param int $pm 1-收入。2-支出
  1647. * @param string $order_type
  1648. * @throws DbException
  1649. */
  1650. public function sign_add($uid, $score, $status, $mark, $has_qian = '', $today_signintime = '', $order_id = 0, $pm = 1, $order_type = '',$type='',$settlement_time = '')
  1651. {
  1652. if(!in_array($type,[1,2])){
  1653. // 其他情况都直接返回,因为目前只有365专区购买才可以获得
  1654. return false;
  1655. }
  1656. $ins_data['uid'] = $uid;
  1657. $ins_data['continuity_day'] = $has_qian;
  1658. $ins_data['reward_socre'] = $score;
  1659. $ins_data['signin_time'] = $today_signintime;
  1660. $ins_data['addtime'] = time();
  1661. $ins_data['status'] = $status;
  1662. $ins_data['mark'] = $mark;
  1663. $ins_data['type'] = $type;
  1664. $ins_data['settlement_time'] = $settlement_time;// 结算时间 真正到了结算时间会结算
  1665. $ins_data['order_id'] = $order_id;
  1666. $ins_data['pm'] = $pm;
  1667. $ins_data['order_type'] = $order_type;
  1668. Db::name('user_sign_score')->insertGetId($ins_data);
  1669. if($pm == 1 && $status == 1){
  1670. Db::name('user')->where('uid',$uid)->inc('score', $score)->update();
  1671. }
  1672. if($pm == 2){
  1673. Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
  1674. }
  1675. }
  1676. public function yijianlogin(UserRepository $repository)
  1677. {
  1678. try {
  1679. // Db::name('log')->insert(['data'=>'一键登录进来了']);
  1680. $token = $this->request->params(['token'])['token'];
  1681. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1682. ->regionId('cn-hangzhou')
  1683. ->asDefaultClient();
  1684. $result = AlibabaCloud::rpc()
  1685. ->product('Dypnsapi')
  1686. ->scheme('https')// https | http
  1687. ->version('2017-05-25')
  1688. ->action('GetMobile')
  1689. ->method('POST')
  1690. ->host('dypnsapi.aliyuncs.com')
  1691. ->options([
  1692. 'query' => [
  1693. 'RegionId' => "cn-hangzhou",
  1694. 'AccessToken' => $token
  1695. ],
  1696. ])
  1697. ->request();
  1698. // 将返回的结果转化为数组
  1699. $result = $result->toArray();
  1700. // Db::name('log')->insert(['data'=>json_encode($result)]);
  1701. //判断当前数组不为空
  1702. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  1703. // token不为空返回手机号码
  1704. $phone = $result['GetMobileResultDTO']['Mobile'];
  1705. $user_res=Db::name('user')->where('account',$phone)->find();
  1706. if(!$user_res){
  1707. $repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
  1708. }
  1709. $user = $repository->accountByUser($phone);
  1710. $user = $repository->mainUser($user);
  1711. $tokenInfo = $repository->createToken($user);
  1712. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1713. } else {
  1714. //如果token为空
  1715. $res = [
  1716. 'state' => 0,
  1717. 'msg' => 'token无效'
  1718. ];
  1719. return app('json')->fail($res);
  1720. }
  1721. }catch (\Exception $e) {
  1722. Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1723. }
  1724. }
  1725. //小程序获取 用户手机号
  1726. public function applet_phone(UserRepository $repository)
  1727. {
  1728. try {
  1729. // Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
  1730. $sessionKey=$this->request->params(['sessionKey']);
  1731. $encryptedData=$this->request->params(['encryptedData']);
  1732. $share_id = $this->request->params(['share_id']);
  1733. $iv=$this->request->params(['iv']);
  1734. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1735. return app('json')->fail('参数不正确');
  1736. }
  1737. // $appid = 'wx82986c4471ce7efc';
  1738. // if($this->source=='yhc'){
  1739. // $appid = 'wx82986c4471ce7efc';
  1740. // }
  1741. // $appid = 'wx7b4d857deb0447f3';
  1742. $appid = 'wx9082e5ac2fdb513f';
  1743. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1744. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1745. $iv =str_replace(' ','+', $iv['iv']);
  1746. // dump($iv,$encryptedData);
  1747. // return ;
  1748. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1749. // dump($pc);
  1750. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  1751. // $data "{\"phoneNumber\":\"15350612089\",\"purePhoneNumber\":\"15350612089\",\"countryCode\":\"86\",\"watermark\":{\"timestamp\":1745288870,\"appid\":\"wx9082e5ac2fdb513f\"}}"
  1752. // dump($errCode);
  1753. if ($errCode != 0) {
  1754. return app('json')->fail('没有获取到手机号1');
  1755. }
  1756. // dump($data);
  1757. $data=json_decode($data,true);
  1758. $phone=$data['purePhoneNumber']??'';
  1759. if($phone==''){
  1760. return app('json')->fail('没有获取到手机号2');
  1761. }
  1762. if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
  1763. return app('json')->fail('手机号格式错误');
  1764. }
  1765. $user_res=Db::name('user')->where('account',$phone)->find();
  1766. if(!$user_res){
  1767. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  1768. if (!intval($spread_uid)) {
  1769. $spread_uid = 0;
  1770. }
  1771. $repository->registr($phone, 123456,'APP','','','',$spread_uid);
  1772. }
  1773. $user = $repository->accountByUser($phone);
  1774. if($this->source=='yhc' && $this->merId){
  1775. $where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1776. $count=Db::name('enterprise_user')->where($where)->count();
  1777. if($count<1){
  1778. $insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1779. $data = $this->request->params(['spread', 'share_id']);
  1780. if(isset($data['spread']) && $data['spread']){
  1781. $insert['puid']= $data['spread'];
  1782. $insert['node_uid']= $data['spread'];
  1783. }else if(isset($data['share_id']) && $data['share_id']){
  1784. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1785. $insert['puid']= $spread_uid;
  1786. $insert['node_uid']= $spread_uid;
  1787. }
  1788. if(!isset($insert['node_uid']) || !$insert['node_uid']){
  1789. return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
  1790. }
  1791. if(isset($data['spread']) && isset($zhuce)){
  1792. $insert['puid']= $data['spread'];
  1793. $insert['node_uid']= $data['spread'];
  1794. }
  1795. Db::name('enterprise_user')->insert($insert);
  1796. }
  1797. }
  1798. $user = $repository->mainUser($user);
  1799. $tokenInfo = $repository->createToken($user);
  1800. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1801. }catch (Exception $exception){
  1802. Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  1803. }
  1804. }
  1805. public function phone_name()
  1806. {
  1807. try {
  1808. $phone=$this->request->params(['phone']);
  1809. if(empty($phone['phone'])){
  1810. return app('json')->fail('请填写手机号码');
  1811. }
  1812. $phone=$phone['phone'];
  1813. $uid=Db::name('user')->where('account',$phone)->find();
  1814. $user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
  1815. if(!$user_name){
  1816. $user_name=$uid['nickname'];
  1817. }
  1818. return app('json')->success($user_name);
  1819. }catch (\Exception $e) {
  1820. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1821. }
  1822. }
  1823. public function get_auth_token(){
  1824. $params=$this->request->params(['url','origin']);
  1825. try {
  1826. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1827. ->regionId('cn-hangzhou')
  1828. ->asDefaultClient()->options([
  1829. ]);
  1830. $result = AlibabaCloud::rpc()
  1831. ->product('Dypnsapi')
  1832. ->scheme('https')// https | http
  1833. ->version('2017-05-25')
  1834. ->action('GetAuthToken')
  1835. ->method('POST')
  1836. ->host('dypnsapi.aliyuncs.com')
  1837. ->options([
  1838. 'query' => [
  1839. 'Url' => $params['url'],
  1840. 'Origin' => $params['origin'],
  1841. ],
  1842. ])
  1843. ->request();
  1844. $result = $result->toArray();
  1845. return app('json')->success($result);
  1846. }catch (Exception $e) {
  1847. return app('json')->success();
  1848. }
  1849. }
  1850. public function get_phone_with_token(){
  1851. $params=$this->request->params(['token']);
  1852. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1853. ->regionId('cn-hangzhou')
  1854. ->asDefaultClient()->options([]);
  1855. $result = AlibabaCloud::rpc()
  1856. ->product('Dypnsapi')
  1857. ->scheme('https')// https | http
  1858. ->version('2017-05-25')
  1859. ->action('GetPhoneWithToken')
  1860. ->method('POST')
  1861. ->host('dypnsapi.aliyuncs.com')
  1862. ->options([
  1863. 'query' => [
  1864. 'SpToken' => $params['token'],
  1865. ],
  1866. ])
  1867. ->request();
  1868. $result = $result->toArray();
  1869. return app('json')->success($result);
  1870. }
  1871. public function getconlev(){
  1872. // $userid = 17;
  1873. // $datas = $this->getPerformance_getcon($userid);
  1874. // var_dump($datas);
  1875. $dats = db::name("store_order")->whereIn("status",[0,1,2,3])->select();
  1876. var_dump($dats);
  1877. }
  1878. /**
  1879. * 获取当前用户大小部门贡献值
  1880. */
  1881. public function getPerformance_getcon($user_id) {
  1882. $team_amount = 0;
  1883. $person_amount = 0;
  1884. $user_id = 593; //598 523 536
  1885. $result_big_team_arr = [];
  1886. $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
  1887. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  1888. $common_nums = $this->getCommonNums_getcon($user_id);
  1889. //var_dump($common_nums);
  1890. $get_teams_comm_num = 0;
  1891. $get_teams_comm_pv = 0;
  1892. $get_teams_per_num = 0;//小部门人数
  1893. //1.0系统中有下级,需要在2.0中再加下级数据
  1894. if($user_id < 611){
  1895. //梅红在2.0中的ID是780
  1896. //var_dump( $common_nums);
  1897. //用户三峡所有在2.0系统下面的业绩和人数 start
  1898. $child_nums = [];
  1899. //获取当前用户
  1900. foreach($common_nums as $v){
  1901. $child_nums[] = $this->getRecursiveChildren_getcon($v);
  1902. }
  1903. //去除空数组,并重新组合有数据的数组
  1904. $filteredData = array_filter($child_nums, function($array) {
  1905. return !empty($array); // 如果数组不为空,则保留
  1906. });
  1907. // 合并所有非空数组
  1908. foreach ($filteredData as $array) {
  1909. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  1910. }
  1911. //var_dump($result_big_team_arr);
  1912. //获取当前用户下面在2.0中的下级所有PV
  1913. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  1914. $t_pv = $this->getteampv_getcon($result_big_team_arr);
  1915. $get_teams_comm_pv = $t_pv;
  1916. //var_dump($get_teams_comm_pv);echo "ttt";
  1917. //用户伞下小部门所有在2.0系统下面的业绩和人数 end
  1918. }else{
  1919. //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  1920. $child_nums = $this->getChildren_getcon($user_id);
  1921. //获取父级子级下面的个人
  1922. $num_teams = $this->getTeamSize_getcon($child_nums);
  1923. //var_dump($num_teams);
  1924. foreach($child_nums as $v){
  1925. $get_teams_comm_datas[] = $this->getTeamPv11_getcon($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  1926. }
  1927. //$s = $this->getparents_child_pv($user_id);
  1928. //var_dump($get_teams_comm_datas);
  1929. //如果只有一个部门,就是默认大部门
  1930. if( count($get_teams_comm_datas) ==1 ){
  1931. $get_teams_comm_pv =$get_teams_comm_datas[0];
  1932. $get_teams_comm_num = $num_teams[0]['total_count'];
  1933. }else if(count($get_teams_comm_datas) >1){
  1934. // var_dump( $get_teams_comm_datas);
  1935. //获取一个最大值,设为大部门,其他的加载一块是小部门
  1936. $getss = $this->processArray_getcon($get_teams_comm_datas);
  1937. //var_dump($getss);
  1938. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  1939. unset($num_teams[$getss['max_index']]);
  1940. //获取小部门的人数
  1941. $per_num = 0;
  1942. foreach($num_teams as $k=>$v){
  1943. $per_num +=$v['total_count'];
  1944. }
  1945. //找到最大值的(大部门)
  1946. //$get_teams_comm_num = $max_value_count;
  1947. //小部门的数量
  1948. // $get_teams_per_num = $per_num;
  1949. //var_dump($getss['max_value']);
  1950. $person_amount = $getss['remaining_sum'];
  1951. $get_teams_comm_pv = $getss['max_value'];
  1952. }
  1953. }
  1954. //var_dump($get_teams_comm_pv);
  1955. //合并业绩和人数
  1956. $team_amount += $get_teams_comm_pv;
  1957. //var_dump($team_amount);
  1958. //1.0获取小区业绩
  1959. $person_nums = $this->getPersonageNums_getcon($user_id);
  1960. //var_dump($person_nums);
  1961. $result_small_team_arr = [];
  1962. //1.0系统中有下级,需要在2.0中再加下级数据
  1963. //用户三峡所有在2.0系统下面的业绩和人数 start
  1964. $child_nums_mix = [];
  1965. //获取当前用户
  1966. foreach($person_nums as $v){
  1967. $child_nums_mix[] = $this->getRecursiveChildren_getcon($v);
  1968. }
  1969. //去除空数组,并重新组合有数据的数组
  1970. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  1971. return !empty($array); // 如果数组不为空,则保留
  1972. });
  1973. // 合并所有非空数组
  1974. $result_small_team_arr = [];
  1975. foreach ($filteredData_1 as $array) {
  1976. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  1977. }
  1978. //var_dump($result_small_team_arr);
  1979. //获取当前用户下面在2.0中的下级所有PV
  1980. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  1981. $t_pv = $this->getteampv_getcon($result_small_team_arr);
  1982. $get_teams_per_pv =$t_pv;
  1983. //var_dump( $get_teams_per_pv);
  1984. //获取当前用户下面在2.0中的下级所有人数
  1985. // $get_teams_per_num += count($result_small_team_arr);
  1986. //合并业绩和人数
  1987. $person_amount += $get_teams_per_pv;
  1988. //当前会员直属的业绩(1.0大部门)
  1989. $t_pv = $this->getteampv_getcon($common_nums);
  1990. $team_amount += $t_pv;
  1991. //当前会员直属的业绩(1.0大部门)
  1992. $p_pv = $this->getteampv_getcon($person_nums);
  1993. $person_amount += $p_pv;
  1994. //var_dump($team_amount,$person_amount);
  1995. //如果当前用户是1.0用户,找到其直推所有的业绩,根据业绩找到大小部门的同时,还要比对1.0中大小部门的业绩,摘出一个最大业绩的部门是大部门,其余都是小部门()
  1996. if($user_id < 611){
  1997. //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  1998. //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  1999. $b_s = $this->getparents_child_pv11_getcon($user_id,$team_amount,$person_amount);
  2000. $team_amount = $b_s[0];
  2001. $person_amount = $b_s[1];
  2002. }
  2003. $return_data = [
  2004. 'common_nums_pv'=> $team_amount,
  2005. 'person_nums_pv'=> $person_amount,
  2006. ];
  2007. return $return_data;
  2008. }
  2009. /**
  2010. * 获取该用户共建联盟
  2011. */
  2012. public function getCommonNums_getcon($user_id){
  2013. //先获取共建联盟下用户的id
  2014. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  2015. $new_array_ids =[];
  2016. foreach ($son_ids as $key => $value) {
  2017. # code...
  2018. $son_id = $value['id'];
  2019. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2020. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2021. if(count($son_value_ids) > 0) {
  2022. $son_value_ids = array_column($son_value_ids,"id");
  2023. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2024. }
  2025. }
  2026. return $new_array_ids;
  2027. }
  2028. /**
  2029. * 获取该用户个人联盟
  2030. */
  2031. public function getPersonageNums_getcon($user_id){
  2032. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  2033. $new_array_ids =[];
  2034. // return 3343;
  2035. foreach ($son_ids as $key => $value) {
  2036. # code...
  2037. $son_id = $value['id'];
  2038. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2039. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2040. if(count($son_value_ids) > 0) {
  2041. $son_value_ids = array_column($son_value_ids,"id");
  2042. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2043. }
  2044. }
  2045. return $new_array_ids;
  2046. }
  2047. // 根据父级uid,递归获取所有子级UID数组
  2048. public function getRecursiveChildren_getcon($parentUid) {
  2049. $result = []; // 用于存储所有子级的 uid
  2050. // 定义递归函数
  2051. $recursion = function ($parentUid) use (&$result, &$recursion) {
  2052. // 查询当前父级的所有直接子级
  2053. $children = Db::name("user")
  2054. ->where("spread_uid", $parentUid)
  2055. ->column("uid"); // 获取子级的 uid 列表
  2056. // 如果没有子级,直接返回
  2057. if (empty($children)) {
  2058. return;
  2059. }
  2060. // 遍历每个子级
  2061. foreach ($children as $childUid) {
  2062. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  2063. $recursion($childUid); // 递归查询子级的子级
  2064. }
  2065. };
  2066. // 从初始父级开始递归查询
  2067. $recursion($parentUid);
  2068. return array_unique($result); // 返回结果数组,并去重
  2069. }
  2070. //只获取数组中的业绩
  2071. public function getteampv_getcon($common_nums) {
  2072. // // 查询当前用户及其子级的所有订单
  2073. $orders_gongxian = Db::name("user_sign_gongxian")
  2074. ->whereIn('status', [1])
  2075. ->whereIn("uid", $common_nums)
  2076. ->select();
  2077. //var_dump( $common_nums);
  2078. $total_gongxian = 0;
  2079. // // 遍历订单计算业绩
  2080. foreach ($orders_gongxian as $order) {
  2081. if (strpos($order['mark'], "购买") !== false) {
  2082. $total_gongxian += $order['number'];
  2083. }
  2084. }
  2085. return $total_gongxian;
  2086. // // // 查询当前用户及其子级的所有订单
  2087. // $orders = Db::name("store_order")
  2088. // ->whereIn('status', [0, 1, 2, 3])
  2089. // ->whereIn("uid", $common_nums)
  2090. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  2091. // ->select();
  2092. // // 初始化业绩和人数
  2093. // $totalPv = 0;
  2094. // $totalUsers = count($common_nums); // 初始化人数为子级总数
  2095. // // 遍历订单计算业绩
  2096. // foreach ($orders as $order) {
  2097. // if ($order['total_price'] == 1180) {
  2098. // $totalPv += 700;
  2099. // } else if ($order['total_price'] == 11800) {
  2100. // $totalPv += 7000;
  2101. // } else if ($order['total_price'] == 10620) {
  2102. // $totalPv += 6300;
  2103. // } else if ($order['total_price'] == 2360) {
  2104. // $totalPv += 1400;
  2105. // } else if ($order['total_price'] == 9440) {
  2106. // $totalPv += 5600;
  2107. // }
  2108. // }
  2109. // // 返回业绩和人数
  2110. // return [
  2111. // 'totalPv' => $totalPv,
  2112. // 'totalUsers' => $totalUsers
  2113. // ];
  2114. }
  2115. // 2.0 根据父级uid,找到当前用户下面的UID
  2116. public function getChildren_getcon($parentUid) {
  2117. $result = []; // 用于存储所有子级的 uid
  2118. $children = Db::name("user")
  2119. ->where("spread_uid", $parentUid)
  2120. ->column("uid"); // 获取子级的 uid 列表
  2121. return $children; // 返回结果数组,并去重
  2122. }
  2123. // 递归获取所有子级 UID 的业绩
  2124. public function getTeamPv11_getcon($parentUid) {
  2125. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  2126. $children = Db::name("user")
  2127. ->where("spread_uid", $parentUid)
  2128. ->column("uid");
  2129. $allChildren = [];
  2130. foreach ($children as $childUid) {
  2131. $allChildren[] = $childUid;
  2132. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  2133. }
  2134. return $allChildren;
  2135. };
  2136. // 获取当前用户及其所有子级的 UID
  2137. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  2138. $orders_gongxian = Db::name("user_sign_gongxian")
  2139. ->whereIn('status', [1])
  2140. ->whereIn("uid", $allUids)
  2141. ->select();
  2142. $total_gongxian = 0;
  2143. // // 遍历订单计算业绩
  2144. foreach ($orders_gongxian as $order) {
  2145. if (strpos($order['mark'], "购买") !== false) {
  2146. $total_gongxian += $order['number'];
  2147. }
  2148. }
  2149. return $total_gongxian;
  2150. // // 查询当前用户及其子级的所有订单
  2151. // $orders = Db::name("store_order")
  2152. // ->whereIn('status', [0, 1, 2, 3])
  2153. // ->whereIn("uid", $allUids)
  2154. // ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  2155. // ->select();
  2156. // // 计算总业绩
  2157. // $totalPv = 0;
  2158. // foreach ($orders as $order) {
  2159. // switch ($order['total_price']) {
  2160. // case 1180:
  2161. // $totalPv += 700;
  2162. // break;
  2163. // case 11800:
  2164. // $totalPv += 7000;
  2165. // break;
  2166. // case 10620:
  2167. // $totalPv += 6300;
  2168. // break;
  2169. // case 2360:
  2170. // $totalPv += 1400;
  2171. // break;
  2172. // case 9440:
  2173. // $totalPv += 5600;
  2174. // break;
  2175. // }
  2176. // }
  2177. // return $totalPv;
  2178. }
  2179. //根据传递的父级数组,返回他的对应子级的个数
  2180. public function getTeamSize_getcon($parentUids) {
  2181. // 初始化结果数组
  2182. $result = [];
  2183. // 遍历每个父级ID
  2184. foreach ($parentUids as $parentUid) {
  2185. // 递归获取所有子级 UID
  2186. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  2187. $children = Db::name("user")
  2188. ->where("spread_uid", $parentUid)
  2189. ->column("uid");
  2190. // 确保返回的是数组
  2191. if (!is_array($children)) {
  2192. return [];
  2193. }
  2194. $allChildren = [];
  2195. foreach ($children as $childUid) {
  2196. $allChildren[] = $childUid;
  2197. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  2198. }
  2199. return $allChildren;
  2200. };
  2201. // 获取当前父级及其所有子级的 UID
  2202. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  2203. // 计算总个数(包括父级自身)
  2204. $totalUids = count($allUids);
  2205. // 将结果存入数组
  2206. $result[] = [
  2207. 'parent_uid' => $parentUid,
  2208. 'total_count' => $totalUids
  2209. ];
  2210. }
  2211. return $result;
  2212. }
  2213. public function processArray_getcon($array) {
  2214. // 初始化结果数组
  2215. $result = [
  2216. 'max_value' => null, // 最大值
  2217. 'max_index' => null, // 最大值的下标
  2218. 'remaining_sum' => 0 // 剩余值的总和
  2219. ];
  2220. // 检查数组是否为空
  2221. if (empty($array)) {
  2222. return $result;
  2223. }
  2224. // 找出最大值及其下标
  2225. $maxValue = $array[0];
  2226. $maxIndex = 0;
  2227. for ($i = 1; $i < count($array); $i++) {
  2228. if ($array[$i] > $maxValue) {
  2229. $maxValue = $array[$i];
  2230. $maxIndex = $i;
  2231. }
  2232. }
  2233. // 计算剩余值的总和
  2234. $remainingSum = 0;
  2235. for ($i = 0; $i < count($array); $i++) {
  2236. if ($i != $maxIndex) {
  2237. $remainingSum += $array[$i];
  2238. }
  2239. }
  2240. // 将结果存入数组
  2241. $result['max_value'] = $maxValue;
  2242. $result['max_index'] = $maxIndex;
  2243. $result['remaining_sum'] = $remainingSum;
  2244. return $result;
  2245. }
  2246. /**
  2247. * 获取流水信息
  2248. */
  2249. public function getPerformance1_getcon($user_id) {
  2250. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  2251. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  2252. // return $amount;
  2253. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  2254. $money1180Sum = 0;
  2255. foreach ($money1180Records as $record) {
  2256. $money1180Sum += $record['money'] - 300 - 180;
  2257. }
  2258. // var_dump($money1180Sum);
  2259. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  2260. //var_dump($person_nums);
  2261. //计算个人的11800单价的业绩 集合
  2262. $money11800Sum = 0;
  2263. foreach ($money11800Records as $record) {
  2264. $money11800Sum += $record['money'] - 3000 - 1800;
  2265. }
  2266. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  2267. //var_dump($person_nums);
  2268. //计算个人的11800单价的业绩 集合
  2269. $money10620Sum = 0;
  2270. foreach ($money10620Records as $record) {
  2271. $money10620Sum += $record['money'] - 2700 - 1620;
  2272. }
  2273. // 计算除去特定值后的总和
  2274. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  2275. $otherMoneySum = 0;
  2276. foreach ($otherMoneyRecords as $record) {
  2277. $otherMoneySum += $record['money'];
  2278. }
  2279. // 分别处理特定值的情况并加上其他值的总和
  2280. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  2281. return $user_person_amount;
  2282. }
  2283. //1.0用户直属的部门和2.0直属的部门,进行比较,获取大部门和小部门数据
  2284. public function getparents_child_pv11_getcon($user_id, $bigamount, $smallamount) {
  2285. // 获取直接下级的 UID 列表
  2286. $get_childs = Db::name("user")
  2287. ->where("spread_uid", $user_id)
  2288. ->column("uid");
  2289. // 初始化变量
  2290. $all_departments = []; // 用于存储所有直属下级的业绩
  2291. // 遍历每个直属下级
  2292. foreach ($get_childs as $child) {
  2293. // 获取当前下级及其子级
  2294. $child_group = [$child];
  2295. $recursive_children = $this->getRecursiveChildren_getcon($child);
  2296. $child_group = array_merge($child_group, $recursive_children);
  2297. // 获取当前分组的业绩
  2298. $result = $this->getteampv_getcon($child_group);
  2299. // 将直属下级的业绩加入数组
  2300. $all_departments[] = $result;
  2301. }
  2302. // 将传入的 $bigamount 和 $smallamount 加入数组
  2303. $all_departments[] = $bigamount;
  2304. $all_departments[] = $smallamount;
  2305. // 检查是否所有业绩都是 0
  2306. if (count(array_filter($all_departments, function($value) { return $value != 0; })) == 0) {
  2307. return [0, 0];
  2308. }
  2309. // 初始化最大部门和小部门
  2310. $max_department = 0;
  2311. $small_department = 0;
  2312. // 遍历 $all_departments,找出最大值并累加小部门的值
  2313. foreach ($all_departments as $department) {
  2314. if ($department > $max_department) {
  2315. // 如果当前部门的业绩大于最大部门的业绩,更新最大部门
  2316. if ($max_department != 0) {
  2317. $small_department += $max_department; // 将旧的最大值累加到小部门
  2318. }
  2319. $max_department = $department; // 更新最大部门
  2320. } else {
  2321. // 如果当前部门的业绩小于或等于最大部门的业绩,累加到小部门
  2322. $small_department += $department;
  2323. }
  2324. }
  2325. // 返回结果
  2326. return [
  2327. $max_department, // 大部门业绩
  2328. $small_department // 小部门业绩
  2329. ];
  2330. //拿$bigamount, $smallamount业绩和get_childs产生的result业绩去对比。如果都是0.说明没有大小部门了,直接返回0,0如果只有一个数组有数据,
  2331. // 说明只有大部门,默认返回大部门数据,小部门返回0,如果有多条数组数据是一样的,那么就是选一个,设为大部门。剩下的数据叠加设为小部门
  2332. }
  2333. //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  2334. public function getparents_child_pv_getcon($user_id){
  2335. // 获取直接下级的 UID 列表
  2336. //$user_id = 593;
  2337. // $get_childs = $this->getRecursiveChildren($user_id);
  2338. $get_childs = Db::name("user")
  2339. ->where("spread_uid", $user_id)
  2340. ->column("uid"); // 获取子级的 uid 列表
  2341. //根据获得的直接推荐下级2.0,来获取他们和她伞下的子级PV。对比拿一个最大的值,设为大部门,其余的是小部门
  2342. //获取直接下级
  2343. $children_group = []; // 用于存储每个直接下级及其子级的分组
  2344. // 遍历每个直接下级
  2345. foreach ($get_childs as $child) {
  2346. $child_group = [$child]; // 将直接下级加入分组
  2347. $recursive_children = $this->getRecursiveChildren($child); // 获取直接下级的所有子级
  2348. $child_group = array_merge($child_group, $recursive_children); // 将子级加入分组
  2349. $children_group[] = $child_group; // 将分组加入最终结果
  2350. }
  2351. $get_teams_comm_datas = [];
  2352. foreach($children_group as $v){
  2353. $get_teams_comm_datas[] = $this->getteampv($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  2354. }
  2355. if(count($get_teams_comm_datas) > 0){
  2356. // 找到最大值作为大部门
  2357. $max_value = max($get_teams_comm_datas);
  2358. $total_sum = array_sum($get_teams_comm_datas); // 计算数组的总和
  2359. // 小部门为总和减去最大值
  2360. $small_department = $total_sum - $max_value;
  2361. //返回大部门和小部门
  2362. return [
  2363. $max_value,
  2364. $small_department
  2365. ];
  2366. }else{
  2367. return [
  2368. 0,
  2369. 0
  2370. ];
  2371. }
  2372. }
  2373. }