Auth.php 68 KB

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