Auth.php 108 KB

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