Auth.php 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042
  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 周总
  413. if($account != 15528079265){
  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. $date['contribute']=set_price_rtrim($data['contribute']);//贡献值
  681. $data['repurchase_price']=set_price_rtrim($data['repurchase_price']);//复购余额
  682. $data['jingdou']=set_price_rtrim($data['jingdou']);//京豆
  683. $data['vr']=set_price_rtrim($data['vr']);//购物金
  684. $data['hongbao']=set_price_rtrim($data['hongbao']);//红包
  685. $data['fugou']=set_price_rtrim($data['fugou']);//复购金
  686. $data['brokerage_price']=set_price_rtrim($data['brokerage_price']);//养老金
  687. $data['annuity'] = set_price_rtrim($data['annuity']);//养老金
  688. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',0) -> sum('number');
  689. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',1) -> sum('number');
  690. // $data['brokerage_price'] = $a +$b;
  691. $data['brokerage_price'] = $aa['brokerage_price'];
  692. $data['isOld']=($data['is_old']);//
  693. $data['exchange']=0;
  694. $data['withdraw']=0;
  695. $data['user_group']=set_price_rtrim($data['user_group']);
  696. if($this->source=='yhc'){
  697. $data['avatar']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  698. $data['exchange']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('exchange');
  699. //withdraw 是否可以提现 0-可以 1-禁止
  700. $data['withdraw']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('withdraw');
  701. }
  702. //普通用户,根据我的贡献值升级(个人消费贡献值+直推的消费产生的贡献值)
  703. $my_con = [];
  704. if($aa['user_group'] < 2){
  705. $my_con = [2,3];
  706. }else if($aa['user_group'] == 2){
  707. $my_con = [3];
  708. }
  709. $data['con_level'] = [
  710. 'my_con' => $aa['contribute'],//我的贡献值
  711. 'my_recon_con' => $aa['per_contribute'],//我推荐的贡献值
  712. 'curr_level' => $aa['user_group'],//当前用户级别身份
  713. 'change_level' => $my_con //可选的等级身份(业务员、业务经理)
  714. ];
  715. return app('json')->success($data );
  716. }
  717. public function updateUserCon(){
  718. $data = $this->request->params(['change_level','uid']);
  719. $uid = $data['uid'];
  720. if(empty($uid)){
  721. return app('json')->fail('找不到该用户!');
  722. }
  723. // $user = $this->request->userInfo();
  724. //var_dump($data);
  725. //var_dump($user);
  726. $aa = Db::name('user') -> where('uid',$uid)->find();//查询用户个人数据
  727. if(empty($aa)){
  728. return app('json')->fail('找不到该用户!');
  729. }
  730. // if(empty($data['my_con']) || empty($data['my_recon_con']) || empty($data['curr_level']) || empty($data['change_level'])){
  731. // return app('json')->fail('参数有误!');
  732. // }
  733. if($data['change_level'] <= $aa['user_group']){
  734. return app('json')->fail('升级失败,请重新选择!');
  735. }
  736. $dev_amount = 0;//需扣除的贡献值
  737. if($data['change_level'] == 2){
  738. $dev_amount = 1180;
  739. }else if($data['change_level'] == 3){
  740. $dev_amount = 11800;
  741. }
  742. //可升级用的贡献值
  743. $con_amount = $aa['contribute'] + $aa['per_contribute'];
  744. $cur_amount = $con_amount - $dev_amount;
  745. if( $cur_amount < 0){
  746. return app('json')->fail('升级失败,贡献值不足!');
  747. }
  748. // 判断总贡献值是否足够
  749. //推荐的贡献值够扣
  750. $yue_amount = $aa['per_contribute'] - $dev_amount;
  751. if( $yue_amount >= 0){
  752. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=> $yue_amount, 'user_group'=>$data['change_level']]);//查询用户个人数据
  753. if($aa){
  754. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  755. return app('json')->success('升级成功');
  756. }
  757. }else{
  758. //推荐的贡献值不够扣
  759. $yue_amount = $aa['contribute'] + $aa['per_contribute'] - $dev_amount;
  760. if( $yue_amount == 0){
  761. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>0 , 'user_group'=>$data['change_level']]);//
  762. if($aa){
  763. $this->con_logs($uid,$yue_amount,2,11,"升级会员身份扣除贡献值",-1,2);
  764. return app('json')->success('升级成功');
  765. }
  766. }else if($yue_amount > 0){
  767. $aa = Db::name('user') -> where('uid',$uid)->update(['per_contribute'=>0 , 'contribute'=>$yue_amount, '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. }
  773. }
  774. }
  775. public function con_logs($uid,$num,$order_id,$order_type,$mark,$status = -1,$state){
  776. $con_data = Db::name('user')->where("uid",$uid)->find();
  777. $con = [
  778. 'uid'=>$uid,
  779. 'number'=>$num,//赠送数量
  780. 'status'=>$status,//红包状态
  781. 'mark'=>$mark,//备注
  782. 'desc'=>'',//描述
  783. 'order_id'=>$order_id,//订单id
  784. 'surplus'=> $con_data['contribute'],//剩余
  785. 'order_type'=>$order_type,//订单类型
  786. 'type'=>$state,//1增加,2消耗
  787. 'settlement_time'=>date('Y-m-d H:i:s'),
  788. 'addtime'=>time()
  789. ];
  790. Db::name('user_sign_gongxian')->insert($con);
  791. }
  792. public function getteamsnum($teamid){
  793. $subordinate_members = Db::name('user')
  794. ->alias('u')
  795. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  796. ->where("u.spread_uid", $teamid)
  797. ->where("so.mer_id", 496)
  798. ->group('u.uid')
  799. ->select();
  800. $total_amount_pv_team = 0;
  801. $team_count_total = 0;
  802. foreach ($subordinate_members as $k => $v) {
  803. $t_teams_pv = $this->calculatePerformance($v['uid']);
  804. $total_amount_pv_team += $t_teams_pv['total_performance'];
  805. $team_count_total += $t_teams_pv['team_count'];
  806. }
  807. return $team_count_total;
  808. }
  809. //计算自己和自己团队下面的业绩。新表
  810. public function calculatePerformance($uid)
  811. {
  812. // 初始化业绩数组
  813. $performance = [
  814. 'personal_performance' => 0, // 个人业绩
  815. 'team_performance' => 0, // 团队业绩
  816. 'total_performance' => 0, // 总业绩
  817. 'team_count' => 0, // 加上自己的团队数量
  818. ];
  819. // 定义业绩换算规则
  820. $performanceMapping = [
  821. 1180 => 700,
  822. 10620 => 6300,
  823. 11800 => 7000
  824. ];
  825. // 计算个人业绩
  826. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  827. if ($personalOrder) {
  828. // 将浮点数转换为整数
  829. $totalPrice = (int)$personalOrder['total_price'];
  830. if (isset($performanceMapping[$totalPrice])) {
  831. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  832. }
  833. }
  834. // 计算旗下团队成员的业绩
  835. $teamOrders = Db::name('user')
  836. ->alias('u')
  837. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  838. ->where("u.spread_uid", $uid) // 查询旗下会员
  839. ->where("so.mer_id", 496)
  840. // ->where("so.douhuomall", 1)
  841. // ->where("so.douhuomall_status", 9)
  842. // ->where("so.status", 0)
  843. ->select();
  844. $teamOrders_count = Db::name('user')
  845. ->alias('u')
  846. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  847. ->where("u.spread_uid", $uid) // 查询旗下会员
  848. ->where("so.mer_id", 496)
  849. // ->where("so.douhuomall", 1)
  850. // ->where("so.douhuomall_status", 9)
  851. // ->where("so.status", 0)
  852. ->count();
  853. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  854. foreach ($teamOrders as $order) {
  855. if ($order['total_price']) {
  856. // 将浮点数转换为整数
  857. $totalPrice = (int)$order['total_price'];
  858. if (isset($performanceMapping[$totalPrice])) {
  859. $performance['team_performance'] += $performanceMapping[$totalPrice];
  860. }
  861. }
  862. }
  863. // 计算总业绩
  864. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  865. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  866. return $performance;
  867. }
  868. //获取大小部门业绩(新表)
  869. public function getbig_samll_datas($subordinate_members){
  870. //单独写一个方法获取大小部门的数据
  871. $arr_team = [];
  872. foreach ($subordinate_members as $k => $v) {
  873. //计算自己和旗下的业绩
  874. $arr_team[] = $this->calculatePerformance($v['uid']);
  875. }
  876. // 初始化变量
  877. $maxPerformance = 0;
  878. $maxIndex = -1;
  879. // 找出 total_performance 最高的记录
  880. foreach ($arr_team as $index => $item) {
  881. if ($item['total_performance'] > $maxPerformance) {
  882. $maxPerformance = $item['total_performance'];
  883. $maxIndex = $index;
  884. }
  885. }
  886. // 如果找到了最高记录
  887. if ($maxIndex !== -1) {
  888. // 提取最高记录
  889. $maxRecord = $arr_team[$maxIndex];
  890. // 从原数组中移除该记录
  891. unset($arr_team[$maxIndex]);
  892. // 重新索引数组
  893. $arr_team = array_values($arr_team);
  894. } else {
  895. // 如果没有找到记录,可以设置一个默认值
  896. $maxRecord = null;
  897. }
  898. // 计算大部门和小部门的汇总信息
  899. $majorDepartmentSummary = [
  900. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  901. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  902. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  903. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  904. "data" => $maxRecord ? [$maxRecord] : []
  905. ];
  906. $minorDepartmentSummary = [
  907. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  908. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  909. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  910. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  911. "data" => $arr_team
  912. ];
  913. // 输出结果
  914. // echo "大部门汇总信息:\n";
  915. // print_r($majorDepartmentSummary);
  916. // echo "小部门汇总信息:\n";
  917. // print_r($minorDepartmentSummary);
  918. return array($majorDepartmentSummary,$minorDepartmentSummary);
  919. }
  920. public function getBreak($uid,$list=[],$count=0){
  921. $sql = "select getUserLevelId($uid) as count";
  922. $count = Db::query($sql);
  923. return count(explode(",",$count[0]['count'])) - 1;
  924. }
  925. /**
  926. * 整合用户登录token
  927. * @return mixed
  928. * @author xaboy
  929. * @day 2020/6/1
  930. */
  931. public function tokenList()
  932. {
  933. $user = $this->request->userInfo()->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  934. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  935. $userInfo = $user->toArray();
  936. $data['mweb_info'] = $this->curl_java_login($userInfo['phone'])['data'];
  937. $data['merchant_info'] = [];
  938. return app('json')->success($data);
  939. }
  940. function curl_java_login($phone){
  941. $curl = curl_init();
  942. curl_setopt_array($curl, array(
  943. CURLOPT_URL => 'http://shop.hxxfb.com/gateway/userCenter_service/userLogOnService/userPhoneLogOn',
  944. CURLOPT_RETURNTRANSFER => true,
  945. CURLOPT_ENCODING => '',
  946. CURLOPT_MAXREDIRS => 10,
  947. CURLOPT_TIMEOUT => 0,
  948. CURLOPT_FOLLOWLOCATION => true,
  949. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  950. CURLOPT_CUSTOMREQUEST => 'POST',
  951. CURLOPT_POSTFIELDS =>'{"phone":'.$phone.',"sms_code":"9527","type":"1"}',
  952. CURLOPT_HTTPHEADER => array(
  953. 'Content-Type: application/json'
  954. ),
  955. ));
  956. $response = curl_exec($curl);
  957. curl_close($curl);
  958. $response = json_decode($response, true);
  959. return $response;
  960. }
  961. /**
  962. * 获取用户信息
  963. * @return mixed
  964. * @author xaboy
  965. * @day 2020/6/1
  966. */
  967. public function userVolunteer()
  968. {
  969. $uid = $this->request->uid();
  970. $volunteer = Db::name("volunteer") -> where(["uid"=>$uid]) -> find();
  971. // $volunteer_class = app()->make(Volunteer::class);
  972. $volunteer_class = new Volunteer();
  973. $volunteerData = $volunteer_class -> volunteer($uid);
  974. $data['grade'] = 0;
  975. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  976. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  977. if($volunteer){
  978. $data = $volunteer;
  979. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  980. if($volunteer['grade'] == 1){
  981. $data['condition_one'] = systemConfig("a_volunteer_achievement");//团队养老金要求
  982. $data['condition_two'] = systemConfig("a_volunteer_number");//团队人数要求
  983. }
  984. if($volunteer['grade'] == 2){
  985. $data['condition_one'] = systemConfig("b_volunteer_achievement");//团队养老金要求
  986. $data['condition_two'] = systemConfig("b_volunteer_number");//团队人数要求
  987. }
  988. if($volunteer['grade'] == 3){
  989. $data['condition_one'] = systemConfig("c_volunteer_achievement");//团队养老金要求
  990. $data['condition_two'] = systemConfig("c_volunteer_number");//团队人数要求
  991. }
  992. if($volunteer['grade'] == 4){
  993. $data['condition_one'] = systemConfig("d_volunteer_achievement");//团队养老金要求
  994. $data['condition_two'] = systemConfig("d_volunteer_number");//团队人数要求
  995. }
  996. }
  997. return app('json')->success($data);
  998. }
  999. /**
  1000. * @param UserRepository $repository
  1001. * @return mixed
  1002. * @author xaboy
  1003. * @day 2020/6/1
  1004. */
  1005. public function logout(UserRepository $repository)
  1006. {
  1007. $repository->clearToken($this->request->token());
  1008. return app('json')->success('退出登录');
  1009. }
  1010. /**
  1011. * @return mixed
  1012. * @throws DataNotFoundException
  1013. * @throws DbException
  1014. * @throws ModelNotFoundException
  1015. * @author xaboy
  1016. * @day 2020-05-11
  1017. */
  1018. public function auth()
  1019. {
  1020. $request = $this->request;
  1021. $oauth = WechatService::create()->getApplication()->oauth;
  1022. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1023. try {
  1024. $wechatInfo = $oauth->user()->getOriginal();
  1025. } catch (\Exception $e) {
  1026. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1027. }
  1028. if (!isset($wechatInfo['nickname'])) {
  1029. return app('json')->fail('授权失败[002]');
  1030. }
  1031. /** @var WechatUserRepository $make */
  1032. $make = app()->make(WechatUserRepository::class);
  1033. $user = $make->syncUser($wechatInfo['openid'], $wechatInfo);
  1034. if (!$user)
  1035. return app('json')->fail('授权失败[003]');
  1036. /** @var UserRepository $make */
  1037. $userRepository = app()->make(UserRepository::class);
  1038. $user[1] = $userRepository->mainUser($user[1]);
  1039. $pid = $this->request->param('spread', 0);
  1040. $userRepository->bindSpread($user[1], intval($pid));
  1041. $tokenInfo = $userRepository->createToken($user[1]);
  1042. $userRepository->loginAfter($user[1]);
  1043. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1044. }
  1045. protected function returnToken($user, $tokenInfo)
  1046. {
  1047. $CommonRepository = app()->make(Common::class);
  1048. $access_token ='75_-8y0OT8i5w72EkPCLpCQoGFGa2Ir42T8RHvqZPLJ4sjn27s6Aj7RUEO5yJX77pzHVoo34zXpeBS0M-gdNegdCRB4FWhkAqxmuhdrANkenSHdrmEvPSWQex4OKFQXLBfAEAJXN';
  1049. var_dump($access_token);
  1050. $unionid = "oGtg_6E5SwAcXhv5Do5z3GL_UMXw";
  1051. $unionid = "o4-On50WzIkkbJsf-apbBE3VB1O0";
  1052. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $unionid . "&lang=zh_CN";
  1053. }
  1054. /**
  1055. * @return mixed
  1056. * @throws DataNotFoundException
  1057. * @throws DbException
  1058. * @throws ModelNotFoundException
  1059. * @author xaboy
  1060. * @day 2020-05-11
  1061. */
  1062. public function mpAuth()
  1063. {
  1064. list($code, $post_cache_key) = $this->request->params([
  1065. 'code',
  1066. 'cache_key',
  1067. ], true);
  1068. $session_key = Cache::get('eb_api_code_' . $post_cache_key);
  1069. if (!$code && !$session_key)
  1070. return app('json')->fail('授权失败,参数有误');
  1071. $miniProgramService = MiniProgramService::create();
  1072. if ($code && !$session_key) {
  1073. try {
  1074. $userInfoCong = $miniProgramService->getUserInfo($code);
  1075. $session_key = $userInfoCong['session_key'];
  1076. $cache_key = md5(time() . $code);
  1077. Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
  1078. } catch (\Exception $e) {
  1079. return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  1080. }
  1081. }
  1082. $data = $this->request->params([
  1083. ['spread_spid', 0],
  1084. ['spread_code', ''],
  1085. ['iv', ''],
  1086. ['encryptedData', ''],
  1087. ]);
  1088. try {
  1089. //解密获取用户信息
  1090. $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
  1091. } catch (\Exception $e) {
  1092. if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
  1093. throw $e;
  1094. }
  1095. if (!$userInfo || !isset($userInfo['openId'])) return app('json')->fail('openid获取失败');
  1096. if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
  1097. /** @var WechatUserRepository $make */
  1098. $make = app()->make(WechatUserRepository::class);
  1099. $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
  1100. if (!$user)
  1101. return app('json')->fail('授权失败');
  1102. /** @var UserRepository $make */
  1103. $userRepository = app()->make(UserRepository::class);
  1104. $user[1] = $userRepository->mainUser($user[1]);
  1105. //获取是否有扫码进小程序
  1106. if (isset($data['spread_code']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']))) {
  1107. $data['spread_spid'] = $info['third_id'];
  1108. }
  1109. $userRepository->bindSpread($user[1], intval($data['spread_spid']));
  1110. $tokenInfo = $userRepository->createToken($user[1]);
  1111. $userRepository->loginAfter($user[1]);
  1112. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  1113. }
  1114. public function getCaptcha()
  1115. {
  1116. $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
  1117. $key = uniqid(microtime(true), true);
  1118. Cache::set('api_captche' . $key, $codeBuilder->getPhrase(), 300);
  1119. $captcha = $codeBuilder->build()->inline();
  1120. $code = $codeBuilder->getPhrase();
  1121. return app('json')->success(compact('key', 'code', 'captcha'));
  1122. }
  1123. protected function checkCaptcha($uni, string $code): bool
  1124. {
  1125. $cacheName = 'api_captche' . $uni;
  1126. if (!Cache::has($cacheName)) return false;
  1127. $key = Cache::get($cacheName);
  1128. $code = mb_strtolower($code, 'UTF-8');
  1129. $res = password_verify($code, $key);
  1130. if ($res) Cache::delete($cacheName);
  1131. return $res;
  1132. }
  1133. public function verify(UserAuthValidate $validate)
  1134. {
  1135. $data = $this->request->params(['phone', 'code', 'key',"type"]);
  1136. $validate->sceneVerify()->check($data);
  1137. log::info("发送短信方法");
  1138. if ($data['type']=="register"){
  1139. $count=Db::name("user")->where("phone", $data["phone"])->count();
  1140. if ($count){
  1141. return app('json')->make(405, '该手机号已注册');
  1142. }
  1143. }
  1144. $sms_num_key = 'api.auth.num.' . $data['phone'];
  1145. $sms_key = 'api.auth.sms.' . $data['phone'];
  1146. $num = Cache::get($sms_num_key) ? Cache::get($sms_num_key) : 0;
  1147. log::info("num{$num}" );
  1148. if ($num > 9) {
  1149. if (!$data['code'])
  1150. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  1151. if (!$this->checkCaptcha($data['key'], $data['code']))
  1152. return app('json')->fail('验证码输入有误');
  1153. }
  1154. $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
  1155. $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ;
  1156. $res = app()->make(AliYunSmsService::class)->send($data['phone'], $sms_code);
  1157. if($res['Code']!='OK'){
  1158. Db::name('log')->insert(['data'=>'幸福保短信发送失败:'.json_encode($res,256)]);
  1159. return app('json')->fail('操作过于频繁,请稍后重试~');
  1160. }
  1161. log::info("sms_key==={$sms_key}" );
  1162. log::info("sms_code==={$sms_code}" );
  1163. log::info("sms_time==={$sms_time}" );
  1164. Cache::set($sms_key, $sms_code,$sms_time * 60);
  1165. Cache::set($sms_num_key, $num + 1, 300);
  1166. //'短信发送成功'
  1167. return app('json')->success('短信发送成功');
  1168. }
  1169. /**
  1170. * 一壶茶查询邀请人信息 1-根据手机号查询uid 2-根据uid查手机号
  1171. * @return mixed
  1172. * @throws DataNotFoundException
  1173. * @throws DbException
  1174. * @throws ModelNotFoundException
  1175. */
  1176. public function query_uid(){
  1177. $phone = $this->request->param('phone');
  1178. $uid = $this->request->param('uid',0);
  1179. $share_id = $this->request->param('share_id',0);
  1180. $type = $this->request->param('type',1);//1-根据手机号查询uid 2-根据uid查手机号 3-通过share_id 查询用户信息
  1181. if($this->source=='yhc' && $this->merId) {
  1182. $user=$this->inviter_verification($type,$uid,$phone,$share_id);
  1183. if($user!=false){
  1184. return app('json')->success('获取成功',$user);
  1185. }
  1186. }
  1187. return app('json')->fail('邀请人不存在');
  1188. }
  1189. private function inviter_verification($type,$uid='',$phone='',$share_id=''){
  1190. if($type==2) {
  1191. $where['uid'] = $uid;
  1192. }else if($type==3){
  1193. $where['uid'] = Db::name('product_share')->where('id', $share_id)->value('uid');
  1194. }else{
  1195. $where['account']=$phone;
  1196. }
  1197. $user =Db::name('user')->field('uid,account as phone')->where($where)->find();
  1198. if(!$user){
  1199. return false;
  1200. }
  1201. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1202. if(!$user2){
  1203. return false;
  1204. }
  1205. return $user;
  1206. }
  1207. /**
  1208. * 一壶茶判断这个手机号是否注册过
  1209. * @return mixed
  1210. * @throws DataNotFoundException
  1211. * @throws DbException
  1212. * @throws ModelNotFoundException
  1213. */
  1214. public function query_phone()
  1215. {
  1216. $phone = $this->request->param('phone','');
  1217. if($phone==''){
  1218. //解密微信手机号
  1219. $sessionKey=$this->request->params(['sessionKey']);
  1220. $encryptedData=$this->request->params(['encryptedData']);
  1221. $iv=$this->request->params(['iv']);
  1222. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1223. return app('json')->fail('参数不正确');
  1224. }
  1225. $appid = 'wx9082e5ac2fdb513f';//储蓄保小程序appid
  1226. if($this->source=='yhc'){
  1227. $appid = 'wx9082e5ac2fdb513f';//一壶茶小程序appid
  1228. }
  1229. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1230. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1231. $iv =str_replace(' ','+', $iv['iv']);
  1232. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1233. $errCode = $pc->decryptData($encryptedData, $iv, $wx_data_str );
  1234. if ($errCode != 0) {
  1235. return app('json')->fail('没有获取到手机号');
  1236. }
  1237. // dump($data);
  1238. $wx_data=json_decode($wx_data_str,true);
  1239. if(isset($wx_data['purePhoneNumber'])){
  1240. $phone=$wx_data['purePhoneNumber'];
  1241. }
  1242. }
  1243. $validate= new UserAuthValidate();
  1244. $validate->sceneVerify()->check(['phone'=>$phone]);
  1245. if($this->source=='yhc' && $this->merId) {
  1246. $where['account']=$phone;
  1247. $user =Db::name('user')->field('uid')->where($where)->find();
  1248. if(!$user){
  1249. return app('json')->fail('未注册');
  1250. }
  1251. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  1252. if($user2){
  1253. return app('json')->success('已注册');
  1254. }
  1255. }
  1256. return app('json')->fail('未注册');
  1257. }
  1258. public function smsLogin(UserAuthValidate $validate, UserRepository $repository)
  1259. {
  1260. $data = $this->request->params(['phone', 'sms_code', 'spread', 'share_id']);
  1261. // $data = $this->request->params(['phone', 'sms_code']);
  1262. $validate->sceneSmslogin()->check($data);
  1263. $domain = $this->request->domain();
  1264. $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'];
  1265. if(($data['sms_code'] == '9527' || $data['sms_code'] == 9527)){
  1266. } else if($data['sms_code'] == '9527' && strpos($domain, 'pre.bjtdba.com') !== false){
  1267. // 域名中包含 "test.hebeiyhc.com'" 字符串
  1268. }else{
  1269. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1270. return app('json')->fail('验证码不正确');
  1271. }
  1272. $user = $repository->accountByUser($data['phone']);
  1273. if (!$user){
  1274. if (!intval($data['spread'])) {
  1275. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1276. $data['spread'] = $spread_uid;
  1277. }
  1278. $user = $repository->registr($data['phone'], null, 'h5', $data['spread']);
  1279. }
  1280. $user = $repository->mainUser($user);
  1281. // if($this->source=='yhc' && $this->merId){
  1282. // $where=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1283. // $count=Db::name('enterprise_user')->where($where)->count();
  1284. // if($count<1){
  1285. // $insert=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1286. // if (!intval($data['spread'])) {
  1287. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1288. // }else{
  1289. // $spread_uid=$data['spread'];
  1290. // }
  1291. // if($this->inviter_verification(2,$spread_uid)==false){
  1292. // return app('json')->fail('请输入正确邀请人手机号');
  1293. // }
  1294. // $insert['puid']= $spread_uid;
  1295. // $insert['node_uid']= $spread_uid;
  1296. // Db::name('enterprise_user')->insert($insert);
  1297. // }
  1298. // }
  1299. // $repository->bindSpread($user, intval($data['spread']));
  1300. $tokenInfo = $repository->createToken($user);
  1301. $repository->loginAfter($user);
  1302. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1303. }
  1304. public function merJavaRegister(UserRepository $repository){
  1305. $data = $this->request->params(['phone', 'spread','token','sign']);
  1306. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  1307. // 校验sign
  1308. $checkSign = Signature::checkSign($data);
  1309. if (!$checkSign) {
  1310. Log::channel("gong")->error('sign校验失败');
  1311. return app('json')->fail('sign校验失败');
  1312. }
  1313. $user = $repository->accountByUser($data['phone']);
  1314. if (!$user) $user = $repository->registr($data['phone'], $data['password'],'MP',intval($data['spread']));
  1315. $user = $repository->mainUser($user);
  1316. $repository->bindSpread($user, intval($data['spread']));
  1317. $repository->loginAfter($user);
  1318. return app('json')->success($user);
  1319. }
  1320. /**
  1321. * @param $phone
  1322. * @param $code
  1323. * @return bool
  1324. * @author Qinii
  1325. * @day 2020-06-12
  1326. */
  1327. public function checkSmsCode($phone, $code)
  1328. {
  1329. $sms_key = 'api.auth.sms.' . $phone;
  1330. //log::info("缓存===code=={$sms_key}");
  1331. //log::info( Cache::get($sms_key));
  1332. //log::info("页面传值==={$code}");
  1333. if (!$cache_code = Cache::get($sms_key)) return false;
  1334. if ($code != $cache_code) return false;
  1335. Cache::delete($sms_key);
  1336. return true;
  1337. }
  1338. //批量生产100个账号
  1339. public function register_all(UserAuthValidate $validate, UserRepository $repository){
  1340. $datas = $this->request->params(['start', 'end','phone']);
  1341. if(mb_strlen($datas['start'].$datas['phone']) != 11 || mb_strlen($datas['end'].$datas['phone']) != 11){
  1342. return app("json")->fail('参数错误');
  1343. }
  1344. for($i=$datas['start'];$i<=$datas['end'];$i++)//这个dao是看你要生成多答少个数字,然后循环生成
  1345. {
  1346. $data=[
  1347. "phone"=>$datas['phone'].$i,
  1348. 'password'=>"123456"
  1349. ];
  1350. $user = $repository->registr($data['phone'], $data['password']);
  1351. $data=[
  1352. 'user_name'=>"测试".$i,
  1353. "mobile"=>"15555555187",
  1354. "user_card"=>"410181198508206517",
  1355. "card_positive"=>"https://app.bjtdba.com/uploads/def/20201030/088ecbdfa81534fadcc7c731d11c0594.jpg",
  1356. "card_reverse"=>"https://app.bjtdba.com/uploads/def/20201030/7546811225c6b5df37a7f41250ba3e66.jpg",
  1357. "status"=>1,
  1358. "create_time"=>time(),
  1359. "update_time"=>time(),
  1360. "uid"=>$i
  1361. ];
  1362. Db::name("user_certification")->insert($data);
  1363. }
  1364. return app("json")->success('成功');
  1365. }
  1366. public function phoneCheck(UserRepository $repository){
  1367. $data = $this->request->params(['phone']);
  1368. $user = $repository->accountByUser($data['phone']);
  1369. if($user){
  1370. return app("json")->success('手机号已注册,可直接绑定',1);
  1371. }else{
  1372. return app("json")->success('手机号未注册,请输入密码',2);
  1373. }
  1374. }
  1375. /*支付宝获取签名*/
  1376. public function aliSign(){
  1377. $repository = app()->make(UserRepository::class);
  1378. $data = $repository ->aliSign();
  1379. return app("json")->success('ok',$data);
  1380. }
  1381. /*支付宝授权登录*/
  1382. public function aliCheck(){
  1383. $data = $this->request->params(['user_id']);
  1384. if(!$data['user_id'] || $data['user_id'] == '' || $data['user_id'] =='undefined'){
  1385. return app('json')->fail("异常操作");
  1386. }
  1387. $repository = app()->make(UserRepository::class);
  1388. $result = $repository ->aliCheck($data['user_id']);
  1389. if(isset($result['code']) && $result['code'] == 200){
  1390. $user = $repository->accountByUser($result['user']['account']);
  1391. $tokenInfo = $repository->createToken($user);
  1392. $repository->loginAfter($user);
  1393. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1394. }
  1395. return app("json")->success('ok',$result);
  1396. }
  1397. /*微信信息获取*/
  1398. public function getWechat(){
  1399. $repository = app()->make(UserRepository::class);
  1400. return app('json')->success($repository->getWechat());
  1401. }
  1402. /*微信授权登录*/
  1403. public function wechatCheck(){
  1404. $data = $this->request->params(['openid']);
  1405. if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
  1406. return app('json')->fail("openid参数缺失");
  1407. }
  1408. $repository = app()->make(UserRepository::class);
  1409. if($this->source=='yhc'){
  1410. $result = $repository ->wechatCheckYhc($data['openid']);
  1411. }else{
  1412. $result = $repository ->wechatCheck($data['openid']);
  1413. }
  1414. if(isset($result['code']) && $result['code'] == 200){
  1415. $user = $repository->accountByUser($result['user']['account']);
  1416. $tokenInfo = $repository->createToken($user);
  1417. $repository->loginAfter($user);
  1418. if($this->source=='yhc'){
  1419. // $user=$user->toArray();
  1420. $user->avatar=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  1421. }
  1422. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1423. }
  1424. return app("json")->fail($result['msg']);
  1425. }
  1426. public function binding_yhc(UserAuthValidate $validate, UserRepository $repository)
  1427. {
  1428. $data = $this->request->params(['phone', 'third_user_id','type']);
  1429. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1430. return app('json')->fail("绑定失败");
  1431. }
  1432. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1433. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP','',0,"https://". $this->request->host(true));//2222
  1434. if($user){
  1435. $enterprise_user= Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->find();
  1436. if(!$enterprise_user){
  1437. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1438. }else if ($enterprise_user['openid']==''){
  1439. $update = ["openid" => $data['third_user_id']];
  1440. Db::name("enterprise_user")->where(['mer_id'=>$this->merId,'uid'=>$user->uid])->update($update);
  1441. }
  1442. // $pid = $this->request->param('spread', 0);
  1443. // $repository->bindSpread($user, intval($pid));
  1444. $tokenInfo = $repository->createToken($user);
  1445. $repository->loginAfter($user);
  1446. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1447. }else{
  1448. return app('json')->fail("绑定失败");
  1449. }
  1450. }
  1451. /**
  1452. * 支付宝微信注册绑定手机号
  1453. * type 1微信2支付宝
  1454. * third_user_id 微信openid 支付宝userId
  1455. * @param UserRepository $repository
  1456. */
  1457. public function binding(UserAuthValidate $validate, UserRepository $repository)
  1458. {
  1459. $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','nickName','avatarUrl','sms']);
  1460. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1461. return app('json')->fail("绑定失败");
  1462. }
  1463. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1464. $validate->sceneSmslogin()->check($data);
  1465. if($data['sms'] != 1){
  1466. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1467. return app('json')->fail('验证码不正确');
  1468. }
  1469. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true));//2222
  1470. if($user){
  1471. $userRepository = app()->make(UserRepository::class);
  1472. $userInfo = $userRepository->getOne(['uid' => $user->uid ?? $user['uid']]);
  1473. //绑定线下充值金额
  1474. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1475. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1476. $notBind = $unionUsersRepository->getAllNotBind($data['third_user_id']);
  1477. if ($notBind) {
  1478. $orderMerchantRepository->doBindUser($userInfo, $data['type']);
  1479. }
  1480. $user = $repository->accountByUser($data['phone']);
  1481. if ($data['type'] == 1) {
  1482. $data1 = ["wechat_user_id" => $data['third_user_id']];
  1483. if($this->source=='yhc' && $this->merId){ //一壶茶创建用户
  1484. $enterprise_user_count = Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->count();
  1485. if($enterprise_user_count<1){
  1486. $spread_data = $this->request->params(['spread', 'share_id']);
  1487. if (!intval($spread_data['spread'])) {
  1488. $spread_uid = Db::name('product_share')->where('id', $spread_data['share_id'])->value('uid');
  1489. }else{
  1490. $spread_uid=$spread_data['spread'];
  1491. }
  1492. if($this->inviter_verification(2,$spread_uid)==false){
  1493. return app('json')->fail('请输入正确邀请人手机号');
  1494. }
  1495. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1496. }
  1497. }
  1498. } else {
  1499. $data1 = ["ali_user_id" => $data['third_user_id']];
  1500. }
  1501. $data2 = [
  1502. "type" => $data['type'],
  1503. "uid" => $user->uid,
  1504. "nickname" => !empty($data['nickName']) ? $data['nickName'] : $user -> nickname,
  1505. "avater" => !empty($data['avatarUrl']) ? $data['avatarUrl'] : $user -> avater,
  1506. ];
  1507. $userRepository -> updateUser($user->uid,$data1,$data2);
  1508. $pid = $this->request->param('spread', 0);
  1509. $repository->bindSpread($user, intval($pid));
  1510. $tokenInfo = $repository->createToken($user);
  1511. $repository->loginAfter($user);
  1512. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1513. }else{
  1514. return app('json')->fail("绑定失败");
  1515. }
  1516. }
  1517. public function queryHaike(){
  1518. $merch_no = $this->request->params(['merch_no']);
  1519. if(!isset($merch_no['merch_no']) || empty($merch_no['merch_no'])){
  1520. return app('json')->fail("请输入商户号");
  1521. }
  1522. $res = Db::name("haike_account")->where("merch_no",$merch_no['merch_no'])->select();
  1523. if(!$res){
  1524. return app('json')->fail("这个商户号没有账单");
  1525. }
  1526. $merch = Db::name('merchant') -> where("merch_no",$merch_no['merch_no']) -> find();
  1527. $data['商户号'] = $merch_no['merch_no'];
  1528. $data['商户名称'] = $merch["mer_name"];
  1529. $data['商户手机号'] = $merch["mer_phone"];
  1530. $data['结算金额'] = 0;
  1531. $data['结算手续费'] = 0;
  1532. foreach ($res as $key => $value){
  1533. $data['结算金额'] += $value['settle_accounts'];
  1534. $data['结算手续费'] += $value['settle_accounts_fee'];
  1535. }
  1536. echo "<pre>";
  1537. dump($data);
  1538. return 1;
  1539. }
  1540. public function createUserNumberAll(){
  1541. $userRepository = app()->make(UserRepository::class);
  1542. $user = Db::name('user') -> select();
  1543. foreach($user as $key => $value){
  1544. $userRepository -> createUserNumber($value['uid']);
  1545. }
  1546. }
  1547. /**
  1548. * @param int $uid 用户ID
  1549. * @param string $score 积分
  1550. * @param int $status 积分状态
  1551. * @param string $mark 备注
  1552. * @param string $has_qian 连续签到天数
  1553. * @param string $today_signintime 签到时间
  1554. * @param int $order_id 订单ID
  1555. * @param int $pm 1-收入。2-支出
  1556. * @param string $order_type
  1557. * @throws DbException
  1558. */
  1559. public function sign_add($uid, $score, $status, $mark, $has_qian = '', $today_signintime = '', $order_id = 0, $pm = 1, $order_type = '',$type='',$settlement_time = '')
  1560. {
  1561. if(!in_array($type,[1,2])){
  1562. // 其他情况都直接返回,因为目前只有365专区购买才可以获得
  1563. return false;
  1564. }
  1565. $ins_data['uid'] = $uid;
  1566. $ins_data['continuity_day'] = $has_qian;
  1567. $ins_data['reward_socre'] = $score;
  1568. $ins_data['signin_time'] = $today_signintime;
  1569. $ins_data['addtime'] = time();
  1570. $ins_data['status'] = $status;
  1571. $ins_data['mark'] = $mark;
  1572. $ins_data['type'] = $type;
  1573. $ins_data['settlement_time'] = $settlement_time;// 结算时间 真正到了结算时间会结算
  1574. $ins_data['order_id'] = $order_id;
  1575. $ins_data['pm'] = $pm;
  1576. $ins_data['order_type'] = $order_type;
  1577. Db::name('user_sign_score')->insertGetId($ins_data);
  1578. if($pm == 1 && $status == 1){
  1579. Db::name('user')->where('uid',$uid)->inc('score', $score)->update();
  1580. }
  1581. if($pm == 2){
  1582. Db::name('user')->where('uid', $uid)->dec('score', $score)->update();
  1583. }
  1584. }
  1585. public function yijianlogin(UserRepository $repository)
  1586. {
  1587. try {
  1588. // Db::name('log')->insert(['data'=>'一键登录进来了']);
  1589. $token = $this->request->params(['token'])['token'];
  1590. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1591. ->regionId('cn-hangzhou')
  1592. ->asDefaultClient();
  1593. $result = AlibabaCloud::rpc()
  1594. ->product('Dypnsapi')
  1595. ->scheme('https')// https | http
  1596. ->version('2017-05-25')
  1597. ->action('GetMobile')
  1598. ->method('POST')
  1599. ->host('dypnsapi.aliyuncs.com')
  1600. ->options([
  1601. 'query' => [
  1602. 'RegionId' => "cn-hangzhou",
  1603. 'AccessToken' => $token
  1604. ],
  1605. ])
  1606. ->request();
  1607. // 将返回的结果转化为数组
  1608. $result = $result->toArray();
  1609. // Db::name('log')->insert(['data'=>json_encode($result)]);
  1610. //判断当前数组不为空
  1611. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  1612. // token不为空返回手机号码
  1613. $phone = $result['GetMobileResultDTO']['Mobile'];
  1614. $user_res=Db::name('user')->where('account',$phone)->find();
  1615. if(!$user_res){
  1616. $repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
  1617. }
  1618. $user = $repository->accountByUser($phone);
  1619. $user = $repository->mainUser($user);
  1620. $tokenInfo = $repository->createToken($user);
  1621. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1622. } else {
  1623. //如果token为空
  1624. $res = [
  1625. 'state' => 0,
  1626. 'msg' => 'token无效'
  1627. ];
  1628. return app('json')->fail($res);
  1629. }
  1630. }catch (\Exception $e) {
  1631. Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1632. }
  1633. }
  1634. //小程序获取 用户手机号
  1635. public function applet_phone(UserRepository $repository)
  1636. {
  1637. try {
  1638. // Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
  1639. $sessionKey=$this->request->params(['sessionKey']);
  1640. $encryptedData=$this->request->params(['encryptedData']);
  1641. $share_id = $this->request->params(['share_id']);
  1642. $iv=$this->request->params(['iv']);
  1643. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1644. return app('json')->fail('参数不正确');
  1645. }
  1646. $appid = 'wx82986c4471ce7efc';
  1647. if($this->source=='yhc'){
  1648. $appid = 'wx82986c4471ce7efc';
  1649. }
  1650. $appid = 'wx7b4d857deb0447f3';
  1651. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1652. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1653. $iv =str_replace(' ','+', $iv['iv']);
  1654. // dump($iv,$encryptedData);
  1655. // return ;
  1656. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1657. // dump($pc);
  1658. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  1659. // dump($errCode);
  1660. if ($errCode != 0) {
  1661. return app('json')->fail('没有获取到手机号1');
  1662. }
  1663. // dump($data);
  1664. $data=json_decode($data,true);
  1665. $phone=$data['purePhoneNumber']??'';
  1666. if($phone==''){
  1667. return app('json')->fail('没有获取到手机号2');
  1668. }
  1669. if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
  1670. return app('json')->fail('手机号格式错误');
  1671. }
  1672. $user_res=Db::name('user')->where('account',$phone)->find();
  1673. if(!$user_res){
  1674. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  1675. $repository->registr($phone, 123456,'APP',$spread_uid);
  1676. }
  1677. $user = $repository->accountByUser($phone);
  1678. if($this->source=='yhc' && $this->merId){
  1679. $where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1680. $count=Db::name('enterprise_user')->where($where)->count();
  1681. if($count<1){
  1682. $insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1683. $data = $this->request->params(['spread', 'share_id']);
  1684. if(isset($data['spread']) && $data['spread']){
  1685. $insert['puid']= $data['spread'];
  1686. $insert['node_uid']= $data['spread'];
  1687. }else if(isset($data['share_id']) && $data['share_id']){
  1688. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1689. $insert['puid']= $spread_uid;
  1690. $insert['node_uid']= $spread_uid;
  1691. }
  1692. if(!isset($insert['node_uid']) || !$insert['node_uid']){
  1693. return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
  1694. }
  1695. if(isset($data['spread']) && isset($zhuce)){
  1696. $insert['puid']= $data['spread'];
  1697. $insert['node_uid']= $data['spread'];
  1698. }
  1699. Db::name('enterprise_user')->insert($insert);
  1700. }
  1701. }
  1702. $user = $repository->mainUser($user);
  1703. $tokenInfo = $repository->createToken($user);
  1704. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1705. }catch (Exception $exception){
  1706. Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  1707. }
  1708. }
  1709. public function phone_name()
  1710. {
  1711. try {
  1712. $phone=$this->request->params(['phone']);
  1713. if(empty($phone['phone'])){
  1714. return app('json')->fail('请填写手机号码');
  1715. }
  1716. $phone=$phone['phone'];
  1717. $uid=Db::name('user')->where('account',$phone)->find();
  1718. $user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
  1719. if(!$user_name){
  1720. $user_name=$uid['nickname'];
  1721. }
  1722. return app('json')->success($user_name);
  1723. }catch (\Exception $e) {
  1724. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1725. }
  1726. }
  1727. public function get_auth_token(){
  1728. $params=$this->request->params(['url','origin']);
  1729. try {
  1730. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1731. ->regionId('cn-hangzhou')
  1732. ->asDefaultClient()->options([
  1733. ]);
  1734. $result = AlibabaCloud::rpc()
  1735. ->product('Dypnsapi')
  1736. ->scheme('https')// https | http
  1737. ->version('2017-05-25')
  1738. ->action('GetAuthToken')
  1739. ->method('POST')
  1740. ->host('dypnsapi.aliyuncs.com')
  1741. ->options([
  1742. 'query' => [
  1743. 'Url' => $params['url'],
  1744. 'Origin' => $params['origin'],
  1745. ],
  1746. ])
  1747. ->request();
  1748. $result = $result->toArray();
  1749. return app('json')->success($result);
  1750. }catch (Exception $e) {
  1751. return app('json')->success();
  1752. }
  1753. }
  1754. public function get_phone_with_token(){
  1755. $params=$this->request->params(['token']);
  1756. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1757. ->regionId('cn-hangzhou')
  1758. ->asDefaultClient()->options([]);
  1759. $result = AlibabaCloud::rpc()
  1760. ->product('Dypnsapi')
  1761. ->scheme('https')// https | http
  1762. ->version('2017-05-25')
  1763. ->action('GetPhoneWithToken')
  1764. ->method('POST')
  1765. ->host('dypnsapi.aliyuncs.com')
  1766. ->options([
  1767. 'query' => [
  1768. 'SpToken' => $params['token'],
  1769. ],
  1770. ])
  1771. ->request();
  1772. $result = $result->toArray();
  1773. return app('json')->success($result);
  1774. }
  1775. }