Auth.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  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. if($account != 15528079265){
  413. if (!$user)
  414. return app('json')->fail('账号或密码错误');
  415. if (!password_verify($pwd = (string)$this->request->param('password'), $user['pwd']))
  416. return app('json')->fail('账号或密码错误');
  417. $type = $this->request->param('type',0);
  418. if ($type==2){
  419. if ($user["identity"]==0||$user["identity"]==4||$user["identity"]==5){
  420. return app('json')->fail('账号或密码错误');
  421. }
  422. }
  423. }
  424. $user = $repository->mainUser($user);
  425. $pid = $this->request->param('spread', 0);
  426. $repository->bindSpread($user, intval($pid));
  427. $tokenInfo = $repository->createToken($user);
  428. $repository->loginAfter($user);
  429. return app('json')->success($repository->returnToken($user, $tokenInfo));
  430. }
  431. /**
  432. * 手机号注册
  433. * @param UserRepository $repository
  434. * @return mixed
  435. * @throws DbException
  436. * @author xaboy
  437. * @day 2020/6/1
  438. */
  439. public function register(UserAuthValidate $validate, UserRepository $repository)
  440. {
  441. // $repository->insterUser(16328, 14395);
  442. // return "=====";
  443. $data = $this->request->params(['phone', 'sms_code', 'spread', 'password',"spread_phone","type","mer_id"]);
  444. $type=$data['type']??'';
  445. unset($data['type']);
  446. $validate->sceneSmslogin()->check($data);
  447. $domain = $this->request->domain();
  448. if($data['sms_code'] == '9527' && strpos($domain, 'test.hebeiyhc.com') !== false) {
  449. // 域名中包含 "test.hebeiyhc.com'" 字符串
  450. }else if (!$this->checkSmsCode($data['phone'], $data['sms_code']) ){
  451. return app('json')->fail('验证码不正确');
  452. }
  453. $user = $repository->accountByUser($data['phone']);
  454. if ($user)
  455. return app('json')->fail('手机号已存在');
  456. if ($data["spread_phone"]){
  457. $spread_user = $repository->accountByUser($data['spread_phone']);
  458. if ($spread_user ){
  459. $data['spread']=$spread_user["uid"];
  460. }else{
  461. return app('json')->fail('推荐人手机号填写错误');
  462. }
  463. }
  464. // Log::info($data);
  465. $user = $repository->registr($data['phone'], $data['password'],'APP',"","",1,$data['spread']);
  466. // $repository->registr($data['phone'], $data['password'],'APP',$data['spread']);
  467. $repository->addagent($user);
  468. $user = $repository->mainUser($user);
  469. $repository->bindSpread($user, intval($data['spread']));
  470. // $repository->spread_log($user, intval($data['spread']));
  471. $tokenInfo = $repository->createToken($user);
  472. $repository->loginAfter($user);
  473. //type==2 事业二部注册并绑定推荐关系
  474. // if($type==2){
  475. // $mer_data=Db::name('merchant')->where('mer_id',$data['mer_id'])->value('merchant_type');
  476. // if($mer_data==2){
  477. // try {
  478. // $eb_user=Db::name('user')->where('account',$data['phone'])->find();
  479. //// Db::name('log')->insert(['data'=>'推荐人ID'.$eb_user['spread_uid']]);
  480. // $users = app()->make(\app\controller\api\entropybarter\User::class);
  481. // $users->bangding($eb_user['uid'],$eb_user['spread_uid'],276);
  482. // $users->bangding($eb_user['uid'],$eb_user['spread_uid'],236);
  483. // }catch (Exception $exception){
  484. // Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
  485. // }
  486. // }
  487. // }
  488. if ($type == "marketing"){
  489. $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();
  490. $spread_list = explode(',',$spread['spread_list']);
  491. if (!empty($spread_list)){
  492. $spread_list[] = "[" . $spread['uid'] . "]";
  493. }else{
  494. array_push($spread_list,"[".$spread['uid']."]");
  495. }
  496. $spread_list = array_filter($spread_list);
  497. $data = [
  498. "uid" => $user->uid,
  499. "spread_uid" => $spread['uid'],
  500. "spread_list" => implode(",",$spread_list)
  501. ];
  502. Db::name("MarketingUser") -> insert($data);
  503. }
  504. return app('json')->success($repository->returnToken($user, $tokenInfo));
  505. }
  506. /**
  507. * 手机号找回密码
  508. * @param UserRepository $repository
  509. * @return mixed
  510. * @throws DbException
  511. * @author xaboy
  512. * @day 2020/6/1
  513. */
  514. public function reset(UserAuthValidate $validate, UserRepository $repository){
  515. $data = $this->request->params(['account', 'captcha', 'code', 'password']);
  516. $data['phone'] = $data['account'];
  517. $data['sms_code'] = $data['captcha'];
  518. $validate->sceneSmslogin()->check($data);
  519. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  520. return app('json')->fail('验证码不正确');
  521. $user = $repository->accountByUser($data['account']);
  522. if ($user){
  523. $res = $repository->resetPassword($data['account'], $data['password'], $user['uid']);
  524. if($res){
  525. return app('json')->success('重置成功');
  526. }
  527. }
  528. return app('json')->error('重置失败');
  529. }
  530. /**
  531. * 旧密码找回密码
  532. * @param UserRepository $repository
  533. * @return mixed
  534. * @throws DbException
  535. * @author xaboy
  536. * @day 2021/1/21
  537. */
  538. public function oldreset(UserRepository $repository){
  539. $user = $this->request->userInfo()
  540. ->hidden(['label_id', 'group_id', 'card_id', 'last_time', 'last_ip', 'status', 'spread_uid', 'spread_time', 'real_name', 'brokerage_price']);
  541. $user->append(['account','pwd','phone',"uid"]);
  542. $user=$user->toArray();
  543. // $user = $this->request->userInfo()->hidden(['account','pwd','phone',"uid"]);
  544. // $user=$this->request->userInfo();
  545. $data = $this->request->params(['passwordold', 'password']);
  546. if (!$user)
  547. return app('json')->fail('密码错误');
  548. if (!password_verify($pwd = (string)$data["passwordold"], $user['pwd']))
  549. return app('json')->fail('密码错误1');
  550. // UserRepository $repository
  551. $user = $repository->accountByUser($user['account']);
  552. if ($user){
  553. $res = $repository->resetPassword($user['account'], $data['password'], $user['uid']);
  554. if($res){
  555. return app('json')->success('重置成功');
  556. }
  557. }
  558. return app('json')->error('重置失败');
  559. }
  560. /*手机号验证
  561. * @author cabbage
  562. * */
  563. public function checkAccount(UserAuthValidate $validate, UserRepository $repository){
  564. $data = $this->request->params(['account', 'captcha']);
  565. $data['phone'] = $data['account'];
  566. $data['sms_code'] = $data['captcha'];
  567. $validate->sceneSmslogin()->check($data);
  568. if (!$this->checkSmsCode($data['account'], $data['captcha']))
  569. return app('json')->fail('验证码不正确');
  570. $user = $repository->accountByUser($data['account']);
  571. if ($user) {
  572. return app('json')->success('验证成功');
  573. }else{
  574. return app('json')->error('旧手机验证失败');
  575. }
  576. }
  577. /**
  578. * 更换手机号
  579. * @param UserRepository $repository
  580. * @return mixed
  581. * @throws DbException
  582. * @author cabbage
  583. */
  584. public function changeAccount(UserAuthValidate $validate,UserRepository $repository){
  585. $data = $this->request->params(['account', 'new_account','captcha']);
  586. $data['phone'] = $data['new_account'];
  587. $data['sms_code'] = $data['captcha'];
  588. $validate->sceneSmslogin()->check($data);
  589. if (!$this->checkSmsCode($data['new_account'], $data['captcha']))
  590. return app('json')->fail('验证码不正确');
  591. $user = $repository->accountByUser($data['account']);
  592. if ($user){
  593. $res = $repository->resetAccount($data['new_account'],$user['uid'],$user['identity']);
  594. if($res){
  595. return app('json')->success('重置成功');
  596. }
  597. }
  598. return app('json')->error('重置失败');
  599. }
  600. /**
  601. * 获取用户信息
  602. * @return mixed
  603. * @author xaboy
  604. * @day 2020/6/1
  605. */
  606. public function userInfo()
  607. {
  608. $user = $this->request->userInfo()
  609. ->hidden(['account','label_id', 'group_id', 'pwd', 'card_id', 'last_time', 'last_ip', 'status', 'spread_time', 'real_name']);
  610. $user->append(['service', 'user_group','total_consume', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread']);
  611. $data=$user->toArray();
  612. $is_merchant=Db::name("merchant_intention")->where(["uid"=>$user["uid"],"is_branch"=>0])->order("mer_intention_id desc")->value("status");
  613. $data["is_merchant"]=$is_merchant===0||$is_merchant>0?$is_merchant:-1;
  614. $data['phone1'] =substr($data['phone'], 0, 3) . '****' . substr($data['phone'], 7, 4);
  615. $data['longtime'] = intval((time()- strtotime($data['create_time'])) / 86400);
  616. $is_ertification=Db::name("user_certification")->where("uid",$user["uid"])->value("status");
  617. $data["is_ertification"]=$is_ertification>0||$is_ertification===0?$is_ertification:-1;
  618. $mer_staff=Db::name("store_staff")->where(["uid"=>$user["uid"]])->value("department");
  619. $data["is_mer_staff"]=$mer_staff?explode(",",$mer_staff):0;
  620. $volunteer = Db::name("volunteer") -> where(["uid"=>$user["uid"]]) -> value("grade");
  621. $data['volunteer'] = $volunteer ?? 0;
  622. if($data['avatar']=='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png'){
  623. $data['avatar']=Db::name('user_account')->where('type',1)->where('uid',$data['uid'])->value('avater');
  624. if(empty($data['avatar'])){
  625. $data['avatar']=Db::name('user_account')->where('type',2)->where('uid',$data['uid'])->value('avater');
  626. if(empty($data['avatar'])){
  627. $data['avatar']='https://cdn.bjtdba.com/chuxubao/static/assets/yhc_default_avatar.png';
  628. }
  629. }
  630. }
  631. //养老金展示
  632. // $data['annuity'] = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',1) -> sum('number');
  633. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',0) -> sum('number');
  634. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',5) -> where('status',1) -> sum('number');
  635. $data['annuity'] = $a +$b;
  636. //上级身份是否大仓会员
  637. $is_da_cang_vip=Db::name('da_cang_user')->where('status',1)->where('uid',$user["uid"])->find();
  638. //渠道商
  639. $is_channel = Db::name('channel_user') -> where('uid',$user["uid"])->where('status',1)->find();
  640. //红积分
  641. $red = Db::name('user_rich') -> where('uid',$user['uid'])->value('red');
  642. $data['is_da_cang_vip'] = 0;
  643. $data['is_channel'] = 0;
  644. $data['red'] = 0;
  645. if($is_da_cang_vip){
  646. $data['is_da_cang_vip'] = $is_da_cang_vip['type'];
  647. }
  648. if($is_channel){
  649. $data['is_channel'] = 1;
  650. }
  651. if ($red){
  652. $data['red'] = $red;
  653. }
  654. $data['team_number'] = $this->getBreak($user['uid']);
  655. $data['is_bangfu'] = Db::name('user_bangfu') -> where('uid',$user["uid"])->value('status')==1;
  656. // $data['area_manage'] = Db::name('area_manage')->field('type,code_list')->where('uid',$user["uid"])->find();
  657. // if($data['area_manage']){
  658. // $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');
  659. // if($area_manage){
  660. // $area_manage = array_column($area_manage,'name','id');
  661. // $code_list = explode(',',$data['area_manage']['code_list']);
  662. // $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]]];
  663. // }
  664. // }
  665. $user_rich=Db::name('user_rich')->where('uid', $user['uid'])->field('type,stockholder,is_huitian')->find();
  666. $data['user_rich_type']= (isset($user_rich) )?$user_rich['type']:0;
  667. $data['stockholder']= (isset($user_rich) )?$user_rich['stockholder']:0;
  668. // $area_manage_type=Db::name('area_manage')->where('uid', $user["uid"])->value('type');
  669. //类型 district-区/县代 city-市代',
  670. // $data['area_manage_type']=$area_manage_type??'';
  671. // $data['member_brokerage_price']=set_price_rtrim($data['member_brokerage_price']);
  672. //积分
  673. $data['score']=set_price_rtrim($data['score']);
  674. //2025新增 贡献值,红包,京东,vr,复购金
  675. $date['contribute']=set_price_rtrim($data['contribute']);//贡献值
  676. $data['repurchase_price']=set_price_rtrim($data['repurchase_price']);//复购余额
  677. $data['jingdou']=set_price_rtrim($data['jingdou']);//京豆
  678. $data['vr']=set_price_rtrim($data['vr']);//购物金
  679. $data['hongbao']=set_price_rtrim($data['hongbao']);//红包
  680. $data['fugou']=set_price_rtrim($data['fugou']);//复购金
  681. //$data['brokerage_price']=set_price_rtrim($data['brokerage_price']);//养老金
  682. $a = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',0) -> sum('number');
  683. $b = Db::name('user_bill') -> where('uid',$user['uid']) -> where('commission_type',3) -> where('status',1) -> sum('number');
  684. $data['brokerage_price'] = $a +$b;
  685. $data['isOld']=($data['is_old']);//
  686. $data['exchange']=0;
  687. $data['withdraw']=0;
  688. $data['user_group']=set_price_rtrim($data['user_group']);
  689. if($this->source=='yhc'){
  690. $data['avatar']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  691. $data['exchange']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('exchange');
  692. //withdraw 是否可以提现 0-可以 1-禁止
  693. $data['withdraw']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('withdraw');
  694. }
  695. return app('json')->success($data );
  696. }
  697. public function getBreak($uid,$list=[],$count=0){
  698. $sql = "select getUserLevelId($uid) as count";
  699. $count = Db::query($sql);
  700. return count(explode(",",$count[0]['count'])) - 1;
  701. }
  702. /**
  703. * 获取用户信息
  704. * @return mixed
  705. * @author xaboy
  706. * @day 2020/6/1
  707. */
  708. public function userVolunteer()
  709. {
  710. $uid = $this->request->uid();
  711. $volunteer = Db::name("volunteer") -> where(["uid"=>$uid]) -> find();
  712. // $volunteer_class = app()->make(Volunteer::class);
  713. $volunteer_class = new Volunteer();
  714. $volunteerData = $volunteer_class -> volunteer($uid);
  715. $data['grade'] = 0;
  716. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  717. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  718. if($volunteer){
  719. $data = $volunteer;
  720. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  721. if($volunteer['grade'] == 1){
  722. $data['condition_one'] = systemConfig("a_volunteer_achievement");//团队养老金要求
  723. $data['condition_two'] = systemConfig("a_volunteer_number");//团队人数要求
  724. }
  725. if($volunteer['grade'] == 2){
  726. $data['condition_one'] = systemConfig("b_volunteer_achievement");//团队养老金要求
  727. $data['condition_two'] = systemConfig("b_volunteer_number");//团队人数要求
  728. }
  729. if($volunteer['grade'] == 3){
  730. $data['condition_one'] = systemConfig("c_volunteer_achievement");//团队养老金要求
  731. $data['condition_two'] = systemConfig("c_volunteer_number");//团队人数要求
  732. }
  733. if($volunteer['grade'] == 4){
  734. $data['condition_one'] = systemConfig("d_volunteer_achievement");//团队养老金要求
  735. $data['condition_two'] = systemConfig("d_volunteer_number");//团队人数要求
  736. }
  737. }
  738. return app('json')->success($data);
  739. }
  740. /**
  741. * @param UserRepository $repository
  742. * @return mixed
  743. * @author xaboy
  744. * @day 2020/6/1
  745. */
  746. public function logout(UserRepository $repository)
  747. {
  748. $repository->clearToken($this->request->token());
  749. return app('json')->success('退出登录');
  750. }
  751. /**
  752. * @return mixed
  753. * @throws DataNotFoundException
  754. * @throws DbException
  755. * @throws ModelNotFoundException
  756. * @author xaboy
  757. * @day 2020-05-11
  758. */
  759. public function auth()
  760. {
  761. $request = $this->request;
  762. $oauth = WechatService::create()->getApplication()->oauth;
  763. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  764. try {
  765. $wechatInfo = $oauth->user()->getOriginal();
  766. } catch (\Exception $e) {
  767. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  768. }
  769. if (!isset($wechatInfo['nickname'])) {
  770. return app('json')->fail('授权失败[002]');
  771. }
  772. /** @var WechatUserRepository $make */
  773. $make = app()->make(WechatUserRepository::class);
  774. $user = $make->syncUser($wechatInfo['openid'], $wechatInfo);
  775. if (!$user)
  776. return app('json')->fail('授权失败[003]');
  777. /** @var UserRepository $make */
  778. $userRepository = app()->make(UserRepository::class);
  779. $user[1] = $userRepository->mainUser($user[1]);
  780. $pid = $this->request->param('spread', 0);
  781. $userRepository->bindSpread($user[1], intval($pid));
  782. $tokenInfo = $userRepository->createToken($user[1]);
  783. $userRepository->loginAfter($user[1]);
  784. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  785. }
  786. protected function returnToken($user, $tokenInfo)
  787. {
  788. $CommonRepository = app()->make(Common::class);
  789. $access_token ='75_-8y0OT8i5w72EkPCLpCQoGFGa2Ir42T8RHvqZPLJ4sjn27s6Aj7RUEO5yJX77pzHVoo34zXpeBS0M-gdNegdCRB4FWhkAqxmuhdrANkenSHdrmEvPSWQex4OKFQXLBfAEAJXN';
  790. var_dump($access_token);
  791. $unionid = "oGtg_6E5SwAcXhv5Do5z3GL_UMXw";
  792. $unionid = "o4-On50WzIkkbJsf-apbBE3VB1O0";
  793. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $unionid . "&lang=zh_CN";
  794. }
  795. /**
  796. * @return mixed
  797. * @throws DataNotFoundException
  798. * @throws DbException
  799. * @throws ModelNotFoundException
  800. * @author xaboy
  801. * @day 2020-05-11
  802. */
  803. public function mpAuth()
  804. {
  805. list($code, $post_cache_key) = $this->request->params([
  806. 'code',
  807. 'cache_key',
  808. ], true);
  809. $session_key = Cache::get('eb_api_code_' . $post_cache_key);
  810. if (!$code && !$session_key)
  811. return app('json')->fail('授权失败,参数有误');
  812. $miniProgramService = MiniProgramService::create();
  813. if ($code && !$session_key) {
  814. try {
  815. $userInfoCong = $miniProgramService->getUserInfo($code);
  816. $session_key = $userInfoCong['session_key'];
  817. $cache_key = md5(time() . $code);
  818. Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
  819. } catch (\Exception $e) {
  820. return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  821. }
  822. }
  823. $data = $this->request->params([
  824. ['spread_spid', 0],
  825. ['spread_code', ''],
  826. ['iv', ''],
  827. ['encryptedData', ''],
  828. ]);
  829. try {
  830. //解密获取用户信息
  831. $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
  832. } catch (\Exception $e) {
  833. if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
  834. throw $e;
  835. }
  836. if (!$userInfo || !isset($userInfo['openId'])) return app('json')->fail('openid获取失败');
  837. if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
  838. /** @var WechatUserRepository $make */
  839. $make = app()->make(WechatUserRepository::class);
  840. $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
  841. if (!$user)
  842. return app('json')->fail('授权失败');
  843. /** @var UserRepository $make */
  844. $userRepository = app()->make(UserRepository::class);
  845. $user[1] = $userRepository->mainUser($user[1]);
  846. //获取是否有扫码进小程序
  847. if (isset($data['spread_code']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']))) {
  848. $data['spread_spid'] = $info['third_id'];
  849. }
  850. $userRepository->bindSpread($user[1], intval($data['spread_spid']));
  851. $tokenInfo = $userRepository->createToken($user[1]);
  852. $userRepository->loginAfter($user[1]);
  853. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  854. }
  855. public function getCaptcha()
  856. {
  857. $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
  858. $key = uniqid(microtime(true), true);
  859. Cache::set('api_captche' . $key, $codeBuilder->getPhrase(), 300);
  860. $captcha = $codeBuilder->build()->inline();
  861. $code = $codeBuilder->getPhrase();
  862. return app('json')->success(compact('key', 'code', 'captcha'));
  863. }
  864. protected function checkCaptcha($uni, string $code): bool
  865. {
  866. $cacheName = 'api_captche' . $uni;
  867. if (!Cache::has($cacheName)) return false;
  868. $key = Cache::get($cacheName);
  869. $code = mb_strtolower($code, 'UTF-8');
  870. $res = password_verify($code, $key);
  871. if ($res) Cache::delete($cacheName);
  872. return $res;
  873. }
  874. public function verify(UserAuthValidate $validate)
  875. {
  876. $data = $this->request->params(['phone', 'code', 'key',"type"]);
  877. $validate->sceneVerify()->check($data);
  878. log::info("发送短信方法");
  879. if ($data['type']=="register"){
  880. $count=Db::name("user")->where("phone", $data["phone"])->count();
  881. if ($count){
  882. return app('json')->make(405, '该手机号已注册');
  883. }
  884. }
  885. $sms_num_key = 'api.auth.num.' . $data['phone'];
  886. $sms_key = 'api.auth.sms.' . $data['phone'];
  887. $num = Cache::get($sms_num_key) ? Cache::get($sms_num_key) : 0;
  888. log::info("num{$num}" );
  889. if ($num > 9) {
  890. if (!$data['code'])
  891. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  892. if (!$this->checkCaptcha($data['key'], $data['code']))
  893. return app('json')->fail('验证码输入有误');
  894. }
  895. $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
  896. $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ;
  897. $res = app()->make(AliYunSmsService::class)->send($data['phone'], $sms_code);
  898. if($res['Code']!='OK'){
  899. Db::name('log')->insert(['data'=>'幸福保短信发送失败:'.json_encode($res,256)]);
  900. return app('json')->fail('操作过于频繁,请稍后重试~');
  901. }
  902. log::info("sms_key==={$sms_key}" );
  903. log::info("sms_code==={$sms_code}" );
  904. log::info("sms_time==={$sms_time}" );
  905. Cache::set($sms_key, $sms_code,$sms_time * 60);
  906. Cache::set($sms_num_key, $num + 1, 300);
  907. //'短信发送成功'
  908. return app('json')->success('短信发送成功');
  909. }
  910. /**
  911. * 一壶茶查询邀请人信息 1-根据手机号查询uid 2-根据uid查手机号
  912. * @return mixed
  913. * @throws DataNotFoundException
  914. * @throws DbException
  915. * @throws ModelNotFoundException
  916. */
  917. public function query_uid(){
  918. $phone = $this->request->param('phone');
  919. $uid = $this->request->param('uid',0);
  920. $share_id = $this->request->param('share_id',0);
  921. $type = $this->request->param('type',1);//1-根据手机号查询uid 2-根据uid查手机号 3-通过share_id 查询用户信息
  922. if($this->source=='yhc' && $this->merId) {
  923. $user=$this->inviter_verification($type,$uid,$phone,$share_id);
  924. if($user!=false){
  925. return app('json')->success('获取成功',$user);
  926. }
  927. }
  928. return app('json')->fail('邀请人不存在');
  929. }
  930. private function inviter_verification($type,$uid='',$phone='',$share_id=''){
  931. if($type==2) {
  932. $where['uid'] = $uid;
  933. }else if($type==3){
  934. $where['uid'] = Db::name('product_share')->where('id', $share_id)->value('uid');
  935. }else{
  936. $where['account']=$phone;
  937. }
  938. $user =Db::name('user')->field('uid,account as phone')->where($where)->find();
  939. if(!$user){
  940. return false;
  941. }
  942. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  943. if(!$user2){
  944. return false;
  945. }
  946. return $user;
  947. }
  948. /**
  949. * 一壶茶判断这个手机号是否注册过
  950. * @return mixed
  951. * @throws DataNotFoundException
  952. * @throws DbException
  953. * @throws ModelNotFoundException
  954. */
  955. public function query_phone()
  956. {
  957. $phone = $this->request->param('phone','');
  958. if($phone==''){
  959. //解密微信手机号
  960. $sessionKey=$this->request->params(['sessionKey']);
  961. $encryptedData=$this->request->params(['encryptedData']);
  962. $iv=$this->request->params(['iv']);
  963. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  964. return app('json')->fail('参数不正确');
  965. }
  966. $appid = 'wx9082e5ac2fdb513f';//储蓄保小程序appid
  967. if($this->source=='yhc'){
  968. $appid = 'wx9082e5ac2fdb513f';//一壶茶小程序appid
  969. }
  970. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  971. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  972. $iv =str_replace(' ','+', $iv['iv']);
  973. $pc = new WXBizDataCrypt($appid, $sessionKey);
  974. $errCode = $pc->decryptData($encryptedData, $iv, $wx_data_str );
  975. if ($errCode != 0) {
  976. return app('json')->fail('没有获取到手机号');
  977. }
  978. // dump($data);
  979. $wx_data=json_decode($wx_data_str,true);
  980. if(isset($wx_data['purePhoneNumber'])){
  981. $phone=$wx_data['purePhoneNumber'];
  982. }
  983. }
  984. $validate= new UserAuthValidate();
  985. $validate->sceneVerify()->check(['phone'=>$phone]);
  986. if($this->source=='yhc' && $this->merId) {
  987. $where['account']=$phone;
  988. $user =Db::name('user')->field('uid')->where($where)->find();
  989. if(!$user){
  990. return app('json')->fail('未注册');
  991. }
  992. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  993. if($user2){
  994. return app('json')->success('已注册');
  995. }
  996. }
  997. return app('json')->fail('未注册');
  998. }
  999. public function smsLogin(UserAuthValidate $validate, UserRepository $repository)
  1000. {
  1001. $data = $this->request->params(['phone', 'sms_code', 'spread', 'share_id']);
  1002. // $data = $this->request->params(['phone', 'sms_code']);
  1003. $validate->sceneSmslogin()->check($data);
  1004. $domain = $this->request->domain();
  1005. $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'];
  1006. if(($data['sms_code'] == '9527' || $data['sms_code'] == 9527)){
  1007. } else if($data['sms_code'] == '9527' && strpos($domain, 'pre.bjtdba.com') !== false){
  1008. // 域名中包含 "test.hebeiyhc.com'" 字符串
  1009. }else{
  1010. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1011. return app('json')->fail('验证码不正确');
  1012. }
  1013. $user = $repository->accountByUser($data['phone']);
  1014. if (!$user){
  1015. if (!intval($data['spread'])) {
  1016. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1017. $data['spread'] = $spread_uid;
  1018. }
  1019. $user = $repository->registr($data['phone'], null, 'h5', $data['spread']);
  1020. }
  1021. $user = $repository->mainUser($user);
  1022. // if($this->source=='yhc' && $this->merId){
  1023. // $where=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1024. // $count=Db::name('enterprise_user')->where($where)->count();
  1025. // if($count<1){
  1026. // $insert=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1027. // if (!intval($data['spread'])) {
  1028. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1029. // }else{
  1030. // $spread_uid=$data['spread'];
  1031. // }
  1032. // if($this->inviter_verification(2,$spread_uid)==false){
  1033. // return app('json')->fail('请输入正确邀请人手机号');
  1034. // }
  1035. // $insert['puid']= $spread_uid;
  1036. // $insert['node_uid']= $spread_uid;
  1037. // Db::name('enterprise_user')->insert($insert);
  1038. // }
  1039. // }
  1040. // $repository->bindSpread($user, intval($data['spread']));
  1041. $tokenInfo = $repository->createToken($user);
  1042. $repository->loginAfter($user);
  1043. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1044. }
  1045. public function merJavaRegister(UserRepository $repository){
  1046. $data = $this->request->params(['phone', 'spread','token','sign']);
  1047. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  1048. // 校验sign
  1049. $checkSign = Signature::checkSign($data);
  1050. if (!$checkSign) {
  1051. Log::channel("gong")->error('sign校验失败');
  1052. return app('json')->fail('sign校验失败');
  1053. }
  1054. $user = $repository->accountByUser($data['phone']);
  1055. if (!$user)
  1056. $user = $repository->registr($data['phone'], $data['password'],'MP',intval($data['spread']));
  1057. $user = $repository->mainUser($user);
  1058. $repository->bindSpread($user, intval($data['spread']));
  1059. $repository->loginAfter($user);
  1060. return app('json')->success($user);
  1061. }
  1062. /**
  1063. * @param $phone
  1064. * @param $code
  1065. * @return bool
  1066. * @author Qinii
  1067. * @day 2020-06-12
  1068. */
  1069. public function checkSmsCode($phone, $code)
  1070. {
  1071. $sms_key = 'api.auth.sms.' . $phone;
  1072. //log::info("缓存===code=={$sms_key}");
  1073. //log::info( Cache::get($sms_key));
  1074. //log::info("页面传值==={$code}");
  1075. if (!$cache_code = Cache::get($sms_key)) return false;
  1076. if ($code != $cache_code) return false;
  1077. Cache::delete($sms_key);
  1078. return true;
  1079. }
  1080. //批量生产100个账号
  1081. public function register_all(UserAuthValidate $validate, UserRepository $repository){
  1082. $datas = $this->request->params(['start', 'end','phone']);
  1083. if(mb_strlen($datas['start'].$datas['phone']) != 11 || mb_strlen($datas['end'].$datas['phone']) != 11){
  1084. return app("json")->fail('参数错误');
  1085. }
  1086. for($i=$datas['start'];$i<=$datas['end'];$i++)//这个dao是看你要生成多答少个数字,然后循环生成
  1087. {
  1088. $data=[
  1089. "phone"=>$datas['phone'].$i,
  1090. 'password'=>"123456"
  1091. ];
  1092. $user = $repository->registr($data['phone'], $data['password']);
  1093. $data=[
  1094. 'user_name'=>"测试".$i,
  1095. "mobile"=>"15555555187",
  1096. "user_card"=>"410181198508206517",
  1097. "card_positive"=>"https://app.bjtdba.com/uploads/def/20201030/088ecbdfa81534fadcc7c731d11c0594.jpg",
  1098. "card_reverse"=>"https://app.bjtdba.com/uploads/def/20201030/7546811225c6b5df37a7f41250ba3e66.jpg",
  1099. "status"=>1,
  1100. "create_time"=>time(),
  1101. "update_time"=>time(),
  1102. "uid"=>$i
  1103. ];
  1104. Db::name("user_certification")->insert($data);
  1105. }
  1106. return app("json")->success('成功');
  1107. }
  1108. public function phoneCheck(UserRepository $repository){
  1109. $data = $this->request->params(['phone']);
  1110. $user = $repository->accountByUser($data['phone']);
  1111. if($user){
  1112. return app("json")->success('手机号已注册,可直接绑定',1);
  1113. }else{
  1114. return app("json")->success('手机号未注册,请输入密码',2);
  1115. }
  1116. }
  1117. /*支付宝获取签名*/
  1118. public function aliSign(){
  1119. $repository = app()->make(UserRepository::class);
  1120. $data = $repository ->aliSign();
  1121. return app("json")->success('ok',$data);
  1122. }
  1123. /*支付宝授权登录*/
  1124. public function aliCheck(){
  1125. $data = $this->request->params(['user_id']);
  1126. if(!$data['user_id'] || $data['user_id'] == '' || $data['user_id'] =='undefined'){
  1127. return app('json')->fail("异常操作");
  1128. }
  1129. $repository = app()->make(UserRepository::class);
  1130. $result = $repository ->aliCheck($data['user_id']);
  1131. if(isset($result['code']) && $result['code'] == 200){
  1132. $user = $repository->accountByUser($result['user']['account']);
  1133. $tokenInfo = $repository->createToken($user);
  1134. $repository->loginAfter($user);
  1135. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1136. }
  1137. return app("json")->success('ok',$result);
  1138. }
  1139. /*微信信息获取*/
  1140. public function getWechat(){
  1141. $repository = app()->make(UserRepository::class);
  1142. return app('json')->success($repository->getWechat());
  1143. }
  1144. /*微信授权登录*/
  1145. public function wechatCheck(){
  1146. $data = $this->request->params(['openid']);
  1147. if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
  1148. return app('json')->fail("openid参数缺失");
  1149. }
  1150. $repository = app()->make(UserRepository::class);
  1151. if($this->source=='yhc'){
  1152. $result = $repository ->wechatCheckYhc($data['openid']);
  1153. }else{
  1154. $result = $repository ->wechatCheck($data['openid']);
  1155. }
  1156. if(isset($result['code']) && $result['code'] == 200){
  1157. $user = $repository->accountByUser($result['user']['account']);
  1158. $tokenInfo = $repository->createToken($user);
  1159. $repository->loginAfter($user);
  1160. if($this->source=='yhc'){
  1161. // $user=$user->toArray();
  1162. $user->avatar=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  1163. }
  1164. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1165. }
  1166. return app("json")->fail($result['msg']);
  1167. }
  1168. public function binding_yhc(UserAuthValidate $validate, UserRepository $repository)
  1169. {
  1170. $data = $this->request->params(['phone', 'third_user_id','type']);
  1171. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1172. return app('json')->fail("绑定失败");
  1173. }
  1174. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1175. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP','',0,"https://". $this->request->host(true));//2222
  1176. if($user){
  1177. $enterprise_user= Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->find();
  1178. if(!$enterprise_user){
  1179. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1180. }else if ($enterprise_user['openid']==''){
  1181. $update = ["openid" => $data['third_user_id']];
  1182. Db::name("enterprise_user")->where(['mer_id'=>$this->merId,'uid'=>$user->uid])->update($update);
  1183. }
  1184. // $pid = $this->request->param('spread', 0);
  1185. // $repository->bindSpread($user, intval($pid));
  1186. $tokenInfo = $repository->createToken($user);
  1187. $repository->loginAfter($user);
  1188. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1189. }else{
  1190. return app('json')->fail("绑定失败");
  1191. }
  1192. }
  1193. /**
  1194. * 支付宝微信注册绑定手机号
  1195. * type 1微信2支付宝
  1196. * third_user_id 微信openid 支付宝userId
  1197. * @param UserRepository $repository
  1198. */
  1199. public function binding(UserAuthValidate $validate, UserRepository $repository)
  1200. {
  1201. $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','nickName','avatarUrl','sms']);
  1202. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1203. return app('json')->fail("绑定失败");
  1204. }
  1205. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1206. $validate->sceneSmslogin()->check($data);
  1207. if($data['sms'] != 1){
  1208. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1209. return app('json')->fail('验证码不正确');
  1210. }
  1211. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true));//2222
  1212. if($user){
  1213. $userRepository = app()->make(UserRepository::class);
  1214. $userInfo = $userRepository->getOne(['uid' => $user->uid ?? $user['uid']]);
  1215. //绑定线下充值金额
  1216. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1217. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1218. $notBind = $unionUsersRepository->getAllNotBind($data['third_user_id']);
  1219. if ($notBind) {
  1220. $orderMerchantRepository->doBindUser($userInfo, $data['type']);
  1221. }
  1222. $user = $repository->accountByUser($data['phone']);
  1223. if ($data['type'] == 1) {
  1224. $data1 = ["wechat_user_id" => $data['third_user_id']];
  1225. if($this->source=='yhc' && $this->merId){ //一壶茶创建用户
  1226. $enterprise_user_count = Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->count();
  1227. if($enterprise_user_count<1){
  1228. $spread_data = $this->request->params(['spread', 'share_id']);
  1229. if (!intval($spread_data['spread'])) {
  1230. $spread_uid = Db::name('product_share')->where('id', $spread_data['share_id'])->value('uid');
  1231. }else{
  1232. $spread_uid=$spread_data['spread'];
  1233. }
  1234. if($this->inviter_verification(2,$spread_uid)==false){
  1235. return app('json')->fail('请输入正确邀请人手机号');
  1236. }
  1237. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1238. }
  1239. }
  1240. } else {
  1241. $data1 = ["ali_user_id" => $data['third_user_id']];
  1242. }
  1243. $data2 = [
  1244. "type" => $data['type'],
  1245. "uid" => $user->uid,
  1246. "nickname" => !empty($data['nickName']) ? $data['nickName'] : $user -> nickname,
  1247. "avater" => !empty($data['avatarUrl']) ? $data['avatarUrl'] : $user -> avater,
  1248. ];
  1249. $userRepository -> updateUser($user->uid,$data1,$data2);
  1250. $pid = $this->request->param('spread', 0);
  1251. $repository->bindSpread($user, intval($pid));
  1252. $tokenInfo = $repository->createToken($user);
  1253. $repository->loginAfter($user);
  1254. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1255. }else{
  1256. return app('json')->fail("绑定失败");
  1257. }
  1258. }
  1259. public function queryHaike(){
  1260. $merch_no = $this->request->params(['merch_no']);
  1261. if(!isset($merch_no['merch_no']) || empty($merch_no['merch_no'])){
  1262. return app('json')->fail("请输入商户号");
  1263. }
  1264. $res = Db::name("haike_account")->where("merch_no",$merch_no['merch_no'])->select();
  1265. if(!$res){
  1266. return app('json')->fail("这个商户号没有账单");
  1267. }
  1268. $merch = Db::name('merchant') -> where("merch_no",$merch_no['merch_no']) -> find();
  1269. $data['商户号'] = $merch_no['merch_no'];
  1270. $data['商户名称'] = $merch["mer_name"];
  1271. $data['商户手机号'] = $merch["mer_phone"];
  1272. $data['结算金额'] = 0;
  1273. $data['结算手续费'] = 0;
  1274. foreach ($res as $key => $value){
  1275. $data['结算金额'] += $value['settle_accounts'];
  1276. $data['结算手续费'] += $value['settle_accounts_fee'];
  1277. }
  1278. echo "<pre>";
  1279. dump($data);
  1280. return 1;
  1281. }
  1282. public function createUserNumberAll(){
  1283. $userRepository = app()->make(UserRepository::class);
  1284. $user = Db::name('user') -> select();
  1285. foreach($user as $key => $value){
  1286. $userRepository -> createUserNumber($value['uid']);
  1287. }
  1288. }
  1289. public function yijianlogin(UserRepository $repository)
  1290. {
  1291. try {
  1292. // Db::name('log')->insert(['data'=>'一键登录进来了']);
  1293. $token = $this->request->params(['token'])['token'];
  1294. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1295. ->regionId('cn-hangzhou')
  1296. ->asDefaultClient();
  1297. $result = AlibabaCloud::rpc()
  1298. ->product('Dypnsapi')
  1299. ->scheme('https')// https | http
  1300. ->version('2017-05-25')
  1301. ->action('GetMobile')
  1302. ->method('POST')
  1303. ->host('dypnsapi.aliyuncs.com')
  1304. ->options([
  1305. 'query' => [
  1306. 'RegionId' => "cn-hangzhou",
  1307. 'AccessToken' => $token
  1308. ],
  1309. ])
  1310. ->request();
  1311. // 将返回的结果转化为数组
  1312. $result = $result->toArray();
  1313. // Db::name('log')->insert(['data'=>json_encode($result)]);
  1314. //判断当前数组不为空
  1315. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  1316. // token不为空返回手机号码
  1317. $phone = $result['GetMobileResultDTO']['Mobile'];
  1318. $user_res=Db::name('user')->where('account',$phone)->find();
  1319. if(!$user_res){
  1320. $repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
  1321. }
  1322. $user = $repository->accountByUser($phone);
  1323. $user = $repository->mainUser($user);
  1324. $tokenInfo = $repository->createToken($user);
  1325. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1326. } else {
  1327. //如果token为空
  1328. $res = [
  1329. 'state' => 0,
  1330. 'msg' => 'token无效'
  1331. ];
  1332. return app('json')->fail($res);
  1333. }
  1334. }catch (\Exception $e) {
  1335. Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1336. }
  1337. }
  1338. //小程序获取 用户手机号
  1339. public function applet_phone(UserRepository $repository)
  1340. {
  1341. try {
  1342. // Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
  1343. $sessionKey=$this->request->params(['sessionKey']);
  1344. $encryptedData=$this->request->params(['encryptedData']);
  1345. $share_id = $this->request->params(['share_id']);
  1346. $iv=$this->request->params(['iv']);
  1347. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1348. return app('json')->fail('参数不正确');
  1349. }
  1350. $appid = 'wx82986c4471ce7efc';
  1351. if($this->source=='yhc'){
  1352. $appid = 'wx82986c4471ce7efc';
  1353. }
  1354. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1355. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1356. $iv =str_replace(' ','+', $iv['iv']);
  1357. // dump($iv,$encryptedData);
  1358. // return ;
  1359. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1360. // dump($pc);
  1361. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  1362. // dump($errCode);
  1363. if ($errCode != 0) {
  1364. return app('json')->fail('没有获取到手机号1');
  1365. }
  1366. // dump($data);
  1367. $data=json_decode($data,true);
  1368. $phone=$data['purePhoneNumber']??'';
  1369. if($phone==''){
  1370. return app('json')->fail('没有获取到手机号2');
  1371. }
  1372. if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
  1373. return app('json')->fail('手机号格式错误');
  1374. }
  1375. $user_res=Db::name('user')->where('account',$phone)->find();
  1376. if(!$user_res){
  1377. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  1378. $repository->registr($phone, 123456,'APP',$spread_uid);
  1379. }
  1380. $user = $repository->accountByUser($phone);
  1381. if($this->source=='yhc' && $this->merId){
  1382. $where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1383. $count=Db::name('enterprise_user')->where($where)->count();
  1384. if($count<1){
  1385. $insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1386. $data = $this->request->params(['spread', 'share_id']);
  1387. if(isset($data['spread']) && $data['spread']){
  1388. $insert['puid']= $data['spread'];
  1389. $insert['node_uid']= $data['spread'];
  1390. }else if(isset($data['share_id']) && $data['share_id']){
  1391. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1392. $insert['puid']= $spread_uid;
  1393. $insert['node_uid']= $spread_uid;
  1394. }
  1395. if(!isset($insert['node_uid']) || !$insert['node_uid']){
  1396. return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
  1397. }
  1398. if(isset($data['spread']) && isset($zhuce)){
  1399. $insert['puid']= $data['spread'];
  1400. $insert['node_uid']= $data['spread'];
  1401. }
  1402. Db::name('enterprise_user')->insert($insert);
  1403. }
  1404. }
  1405. $user = $repository->mainUser($user);
  1406. $tokenInfo = $repository->createToken($user);
  1407. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1408. }catch (Exception $exception){
  1409. Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  1410. }
  1411. }
  1412. public function phone_name()
  1413. {
  1414. try {
  1415. $phone=$this->request->params(['phone']);
  1416. if(empty($phone['phone'])){
  1417. return app('json')->fail('请填写手机号码');
  1418. }
  1419. $phone=$phone['phone'];
  1420. $uid=Db::name('user')->where('account',$phone)->find();
  1421. $user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
  1422. if(!$user_name){
  1423. $user_name=$uid['nickname'];
  1424. }
  1425. return app('json')->success($user_name);
  1426. }catch (\Exception $e) {
  1427. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1428. }
  1429. }
  1430. public function get_auth_token(){
  1431. $params=$this->request->params(['url','origin']);
  1432. try {
  1433. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1434. ->regionId('cn-hangzhou')
  1435. ->asDefaultClient()->options([
  1436. ]);
  1437. $result = AlibabaCloud::rpc()
  1438. ->product('Dypnsapi')
  1439. ->scheme('https')// https | http
  1440. ->version('2017-05-25')
  1441. ->action('GetAuthToken')
  1442. ->method('POST')
  1443. ->host('dypnsapi.aliyuncs.com')
  1444. ->options([
  1445. 'query' => [
  1446. 'Url' => $params['url'],
  1447. 'Origin' => $params['origin'],
  1448. ],
  1449. ])
  1450. ->request();
  1451. $result = $result->toArray();
  1452. return app('json')->success($result);
  1453. }catch (Exception $e) {
  1454. return app('json')->success();
  1455. }
  1456. }
  1457. public function get_phone_with_token(){
  1458. $params=$this->request->params(['token']);
  1459. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1460. ->regionId('cn-hangzhou')
  1461. ->asDefaultClient()->options([]);
  1462. $result = AlibabaCloud::rpc()
  1463. ->product('Dypnsapi')
  1464. ->scheme('https')// https | http
  1465. ->version('2017-05-25')
  1466. ->action('GetPhoneWithToken')
  1467. ->method('POST')
  1468. ->host('dypnsapi.aliyuncs.com')
  1469. ->options([
  1470. 'query' => [
  1471. 'SpToken' => $params['token'],
  1472. ],
  1473. ])
  1474. ->request();
  1475. $result = $result->toArray();
  1476. return app('json')->success($result);
  1477. }
  1478. }