Auth.php 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  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['brokerage_price']=set_price_rtrim($data['brokerage_price']);
  675. $data['isOld']=($data['is_old']);//
  676. $data['exchange']=0;
  677. $data['withdraw']=0;
  678. if($this->source=='yhc'){
  679. $data['avatar']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  680. $data['exchange']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('exchange');
  681. //withdraw 是否可以提现 0-可以 1-禁止
  682. $data['withdraw']=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('withdraw');
  683. }
  684. return app('json')->success($data );
  685. }
  686. public function getBreak($uid,$list=[],$count=0){
  687. $sql = "select getUserLevelId($uid) as count";
  688. $count = Db::query($sql);
  689. return count(explode(",",$count[0]['count'])) - 1;
  690. }
  691. /**
  692. * 获取用户信息
  693. * @return mixed
  694. * @author xaboy
  695. * @day 2020/6/1
  696. */
  697. public function userVolunteer()
  698. {
  699. $uid = $this->request->uid();
  700. $volunteer = Db::name("volunteer") -> where(["uid"=>$uid]) -> find();
  701. // $volunteer_class = app()->make(Volunteer::class);
  702. $volunteer_class = new Volunteer();
  703. $volunteerData = $volunteer_class -> volunteer($uid);
  704. $data['grade'] = 0;
  705. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  706. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  707. if($volunteer){
  708. $data = $volunteer;
  709. $data['self_yanglao'] = $volunteerData['self_yanglao'];
  710. if($volunteer['grade'] == 1){
  711. $data['condition_one'] = systemConfig("a_volunteer_achievement");//团队养老金要求
  712. $data['condition_two'] = systemConfig("a_volunteer_number");//团队人数要求
  713. }
  714. if($volunteer['grade'] == 2){
  715. $data['condition_one'] = systemConfig("b_volunteer_achievement");//团队养老金要求
  716. $data['condition_two'] = systemConfig("b_volunteer_number");//团队人数要求
  717. }
  718. if($volunteer['grade'] == 3){
  719. $data['condition_one'] = systemConfig("c_volunteer_achievement");//团队养老金要求
  720. $data['condition_two'] = systemConfig("c_volunteer_number");//团队人数要求
  721. }
  722. if($volunteer['grade'] == 4){
  723. $data['condition_one'] = systemConfig("d_volunteer_achievement");//团队养老金要求
  724. $data['condition_two'] = systemConfig("d_volunteer_number");//团队人数要求
  725. }
  726. }
  727. return app('json')->success($data);
  728. }
  729. /**
  730. * @param UserRepository $repository
  731. * @return mixed
  732. * @author xaboy
  733. * @day 2020/6/1
  734. */
  735. public function logout(UserRepository $repository)
  736. {
  737. $repository->clearToken($this->request->token());
  738. return app('json')->success('退出登录');
  739. }
  740. /**
  741. * @return mixed
  742. * @throws DataNotFoundException
  743. * @throws DbException
  744. * @throws ModelNotFoundException
  745. * @author xaboy
  746. * @day 2020-05-11
  747. */
  748. public function auth()
  749. {
  750. $request = $this->request;
  751. $oauth = WechatService::create()->getApplication()->oauth;
  752. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  753. try {
  754. $wechatInfo = $oauth->user()->getOriginal();
  755. } catch (\Exception $e) {
  756. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  757. }
  758. if (!isset($wechatInfo['nickname'])) {
  759. return app('json')->fail('授权失败[002]');
  760. }
  761. /** @var WechatUserRepository $make */
  762. $make = app()->make(WechatUserRepository::class);
  763. $user = $make->syncUser($wechatInfo['openid'], $wechatInfo);
  764. if (!$user)
  765. return app('json')->fail('授权失败[003]');
  766. /** @var UserRepository $make */
  767. $userRepository = app()->make(UserRepository::class);
  768. $user[1] = $userRepository->mainUser($user[1]);
  769. $pid = $this->request->param('spread', 0);
  770. $userRepository->bindSpread($user[1], intval($pid));
  771. $tokenInfo = $userRepository->createToken($user[1]);
  772. $userRepository->loginAfter($user[1]);
  773. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  774. }
  775. protected function returnToken($user, $tokenInfo)
  776. {
  777. $CommonRepository = app()->make(Common::class);
  778. $access_token ='75_-8y0OT8i5w72EkPCLpCQoGFGa2Ir42T8RHvqZPLJ4sjn27s6Aj7RUEO5yJX77pzHVoo34zXpeBS0M-gdNegdCRB4FWhkAqxmuhdrANkenSHdrmEvPSWQex4OKFQXLBfAEAJXN';
  779. var_dump($access_token);
  780. $unionid = "oGtg_6E5SwAcXhv5Do5z3GL_UMXw";
  781. $unionid = "o4-On50WzIkkbJsf-apbBE3VB1O0";
  782. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $access_token . "&openid=" . $unionid . "&lang=zh_CN";
  783. }
  784. /**
  785. * @return mixed
  786. * @throws DataNotFoundException
  787. * @throws DbException
  788. * @throws ModelNotFoundException
  789. * @author xaboy
  790. * @day 2020-05-11
  791. */
  792. public function mpAuth()
  793. {
  794. list($code, $post_cache_key) = $this->request->params([
  795. 'code',
  796. 'cache_key',
  797. ], true);
  798. $session_key = Cache::get('eb_api_code_' . $post_cache_key);
  799. if (!$code && !$session_key)
  800. return app('json')->fail('授权失败,参数有误');
  801. $miniProgramService = MiniProgramService::create();
  802. if ($code && !$session_key) {
  803. try {
  804. $userInfoCong = $miniProgramService->getUserInfo($code);
  805. $session_key = $userInfoCong['session_key'];
  806. $cache_key = md5(time() . $code);
  807. Cache::set('eb_api_code_' . $cache_key, $session_key, 86400);
  808. } catch (\Exception $e) {
  809. return app('json')->fail('获取session_key失败,请检查您的配置!', ['line' => $e->getLine(), 'message' => $e->getMessage()]);
  810. }
  811. }
  812. $data = $this->request->params([
  813. ['spread_spid', 0],
  814. ['spread_code', ''],
  815. ['iv', ''],
  816. ['encryptedData', ''],
  817. ]);
  818. try {
  819. //解密获取用户信息
  820. $userInfo = $miniProgramService->encryptor($session_key, $data['iv'], $data['encryptedData']);
  821. } catch (\Exception $e) {
  822. if ($e->getCode() == '-41003') return app('json')->fail('获取会话密匙失败');
  823. throw $e;
  824. }
  825. if (!$userInfo || !isset($userInfo['openId'])) return app('json')->fail('openid获取失败');
  826. if (!isset($userInfo['unionId'])) $userInfo['unionId'] = '';
  827. /** @var WechatUserRepository $make */
  828. $make = app()->make(WechatUserRepository::class);
  829. $user = $make->syncRoutineUser($userInfo['openId'], $userInfo);
  830. if (!$user)
  831. return app('json')->fail('授权失败');
  832. /** @var UserRepository $make */
  833. $userRepository = app()->make(UserRepository::class);
  834. $user[1] = $userRepository->mainUser($user[1]);
  835. //获取是否有扫码进小程序
  836. if (isset($data['spread_code']) && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($data['spread_code']))) {
  837. $data['spread_spid'] = $info['third_id'];
  838. }
  839. $userRepository->bindSpread($user[1], intval($data['spread_spid']));
  840. $tokenInfo = $userRepository->createToken($user[1]);
  841. $userRepository->loginAfter($user[1]);
  842. return app('json')->success($userRepository->returnToken($user[1], $tokenInfo));
  843. }
  844. public function getCaptcha()
  845. {
  846. $codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
  847. $key = uniqid(microtime(true), true);
  848. Cache::set('api_captche' . $key, $codeBuilder->getPhrase(), 300);
  849. $captcha = $codeBuilder->build()->inline();
  850. $code = $codeBuilder->getPhrase();
  851. return app('json')->success(compact('key', 'code', 'captcha'));
  852. }
  853. protected function checkCaptcha($uni, string $code): bool
  854. {
  855. $cacheName = 'api_captche' . $uni;
  856. if (!Cache::has($cacheName)) return false;
  857. $key = Cache::get($cacheName);
  858. $code = mb_strtolower($code, 'UTF-8');
  859. $res = password_verify($code, $key);
  860. if ($res) Cache::delete($cacheName);
  861. return $res;
  862. }
  863. public function verify(UserAuthValidate $validate)
  864. {
  865. $data = $this->request->params(['phone', 'code', 'key',"type"]);
  866. $validate->sceneVerify()->check($data);
  867. if ($data['type']=="register"){
  868. $count=Db::name("user")->where("phone", $data["phone"])->count();
  869. if ($count){
  870. return app('json')->make(405, '该手机号已注册');
  871. }
  872. }
  873. $sms_num_key = 'api.auth.num.' . $data['phone'];
  874. $sms_key = 'api.auth.sms.' . $data['phone'];
  875. $num = Cache::get($sms_num_key) ? Cache::get($sms_num_key) : 0;
  876. if ($num > 9) {
  877. if (!$data['code'])
  878. return app('json')->make(402, '操作过于频繁,请稍后重试~');
  879. if (!$this->checkCaptcha($data['key'], $data['code']))
  880. return app('json')->fail('验证码输入有误');
  881. }
  882. $sms_code = str_pad(random_int(1, 9999), 4, 0, STR_PAD_LEFT);
  883. $sms_time = systemConfig('sms_time') ? systemConfig('sms_time') : 30 ;
  884. $res = app()->make(AliYunSmsService::class)->send($data['phone'], $sms_code);
  885. if($res['Code']!='OK'){
  886. Db::name('log')->insert(['data'=>'一壶茶短信发送失败:'.json_encode($res,256)]);
  887. return app('json')->fail('操作过于频繁,请稍后重试~');
  888. }
  889. Cache::set($sms_key, $sms_code,$sms_time * 60);
  890. Cache::set($sms_num_key, $num + 1, 300);
  891. //'短信发送成功'
  892. return app('json')->success('短信发送成功');
  893. }
  894. /**
  895. * 一壶茶查询邀请人信息 1-根据手机号查询uid 2-根据uid查手机号
  896. * @return mixed
  897. * @throws DataNotFoundException
  898. * @throws DbException
  899. * @throws ModelNotFoundException
  900. */
  901. public function query_uid(){
  902. $phone = $this->request->param('phone');
  903. $uid = $this->request->param('uid',0);
  904. $share_id = $this->request->param('share_id',0);
  905. $type = $this->request->param('type',1);//1-根据手机号查询uid 2-根据uid查手机号 3-通过share_id 查询用户信息
  906. if($this->source=='yhc' && $this->merId) {
  907. $user=$this->inviter_verification($type,$uid,$phone,$share_id);
  908. if($user!=false){
  909. return app('json')->success('获取成功',$user);
  910. }
  911. }
  912. return app('json')->fail('邀请人不存在');
  913. }
  914. private function inviter_verification($type,$uid='',$phone='',$share_id=''){
  915. if($type==2) {
  916. $where['uid'] = $uid;
  917. }else if($type==3){
  918. $where['uid'] = Db::name('product_share')->where('id', $share_id)->value('uid');
  919. }else{
  920. $where['account']=$phone;
  921. }
  922. $user =Db::name('user')->field('uid,account as phone')->where($where)->find();
  923. if(!$user){
  924. return false;
  925. }
  926. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  927. if(!$user2){
  928. return false;
  929. }
  930. return $user;
  931. }
  932. /**
  933. * 一壶茶判断这个手机号是否注册过
  934. * @return mixed
  935. * @throws DataNotFoundException
  936. * @throws DbException
  937. * @throws ModelNotFoundException
  938. */
  939. public function query_phone()
  940. {
  941. $phone = $this->request->param('phone','');
  942. if($phone==''){
  943. //解密微信手机号
  944. $sessionKey=$this->request->params(['sessionKey']);
  945. $encryptedData=$this->request->params(['encryptedData']);
  946. $iv=$this->request->params(['iv']);
  947. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  948. return app('json')->fail('参数不正确');
  949. }
  950. $appid = 'wx9082e5ac2fdb513f';//储蓄保小程序appid
  951. if($this->source=='yhc'){
  952. $appid = 'wx9082e5ac2fdb513f';//一壶茶小程序appid
  953. }
  954. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  955. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  956. $iv =str_replace(' ','+', $iv['iv']);
  957. $pc = new WXBizDataCrypt($appid, $sessionKey);
  958. $errCode = $pc->decryptData($encryptedData, $iv, $wx_data_str );
  959. if ($errCode != 0) {
  960. return app('json')->fail('没有获取到手机号');
  961. }
  962. // dump($data);
  963. $wx_data=json_decode($wx_data_str,true);
  964. if(isset($wx_data['purePhoneNumber'])){
  965. $phone=$wx_data['purePhoneNumber'];
  966. }
  967. }
  968. $validate= new UserAuthValidate();
  969. $validate->sceneVerify()->check(['phone'=>$phone]);
  970. if($this->source=='yhc' && $this->merId) {
  971. $where['account']=$phone;
  972. $user =Db::name('user')->field('uid')->where($where)->find();
  973. if(!$user){
  974. return app('json')->fail('未注册');
  975. }
  976. $user2 = Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->find();
  977. if($user2){
  978. return app('json')->success('已注册');
  979. }
  980. }
  981. return app('json')->fail('未注册');
  982. }
  983. public function smsLogin(UserAuthValidate $validate, UserRepository $repository)
  984. {
  985. // $data = $this->request->params(['phone', 'sms_code', 'spread', 'share_id']);
  986. $data = $this->request->params(['phone', 'sms_code']);
  987. $validate->sceneSmslogin()->check($data);
  988. $domain = $this->request->domain();
  989. $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'];
  990. if(($data['sms_code'] == '9527' || $data['sms_code'] == 9527) && strpos($domain, 'test.hebeiyhc.com') !== false){
  991. } else if($data['sms_code'] == '9527' && strpos($domain, 'pre.bjtdba.com') !== false){
  992. // 域名中包含 "test.hebeiyhc.com'" 字符串
  993. }else{
  994. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  995. return app('json')->fail('验证码不正确');
  996. }
  997. $user = $repository->accountByUser($data['phone']);
  998. // if (!$user){
  999. // if (!intval($data['spread'])) {
  1000. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1001. // $data['spread'] = $spread_uid;
  1002. // }
  1003. // $user = $repository->registr($data['phone'], null, 'h5', $data['spread']);
  1004. // }
  1005. $user = $repository->mainUser($user);
  1006. // if($this->source=='yhc' && $this->merId){
  1007. // $where=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1008. // $count=Db::name('enterprise_user')->where($where)->count();
  1009. // if($count<1){
  1010. // $insert=['mer_id'=>$this->merId,'uid'=>$user->uid];
  1011. // if (!intval($data['spread'])) {
  1012. // $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1013. // }else{
  1014. // $spread_uid=$data['spread'];
  1015. // }
  1016. // if($this->inviter_verification(2,$spread_uid)==false){
  1017. // return app('json')->fail('请输入正确邀请人手机号');
  1018. // }
  1019. // $insert['puid']= $spread_uid;
  1020. // $insert['node_uid']= $spread_uid;
  1021. // Db::name('enterprise_user')->insert($insert);
  1022. // }
  1023. // }
  1024. // $repository->bindSpread($user, intval($data['spread']));
  1025. $tokenInfo = $repository->createToken($user);
  1026. $repository->loginAfter($user);
  1027. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1028. }
  1029. public function merJavaRegister(UserRepository $repository){
  1030. $data = $this->request->params(['phone', 'spread','token','sign']);
  1031. Log::channel("gong")->info("供应链取消商品数据:" . json_encode($data));
  1032. // 校验sign
  1033. $checkSign = Signature::checkSign($data);
  1034. if (!$checkSign) {
  1035. Log::channel("gong")->error('sign校验失败');
  1036. return app('json')->fail('sign校验失败');
  1037. }
  1038. $user = $repository->accountByUser($data['phone']);
  1039. if (!$user)
  1040. $user = $repository->registr($data['phone'], $data['password'],'MP',intval($data['spread']));
  1041. $user = $repository->mainUser($user);
  1042. $repository->bindSpread($user, intval($data['spread']));
  1043. $repository->loginAfter($user);
  1044. return app('json')->success($user);
  1045. }
  1046. /**
  1047. * @param $phone
  1048. * @param $code
  1049. * @return bool
  1050. * @author Qinii
  1051. * @day 2020-06-12
  1052. */
  1053. public function checkSmsCode($phone, $code)
  1054. {
  1055. $sms_key = 'api.auth.sms.' . $phone;
  1056. if (!$cache_code = Cache::get($sms_key)) return false;
  1057. if ($code != $cache_code) return false;
  1058. Cache::delete($sms_key);
  1059. return true;
  1060. }
  1061. //批量生产100个账号
  1062. public function register_all(UserAuthValidate $validate, UserRepository $repository){
  1063. $datas = $this->request->params(['start', 'end','phone']);
  1064. if(mb_strlen($datas['start'].$datas['phone']) != 11 || mb_strlen($datas['end'].$datas['phone']) != 11){
  1065. return app("json")->fail('参数错误');
  1066. }
  1067. for($i=$datas['start'];$i<=$datas['end'];$i++)//这个dao是看你要生成多答少个数字,然后循环生成
  1068. {
  1069. $data=[
  1070. "phone"=>$datas['phone'].$i,
  1071. 'password'=>"123456"
  1072. ];
  1073. $user = $repository->registr($data['phone'], $data['password']);
  1074. $data=[
  1075. 'user_name'=>"测试".$i,
  1076. "mobile"=>"15555555187",
  1077. "user_card"=>"410181198508206517",
  1078. "card_positive"=>"https://app.bjtdba.com/uploads/def/20201030/088ecbdfa81534fadcc7c731d11c0594.jpg",
  1079. "card_reverse"=>"https://app.bjtdba.com/uploads/def/20201030/7546811225c6b5df37a7f41250ba3e66.jpg",
  1080. "status"=>1,
  1081. "create_time"=>time(),
  1082. "update_time"=>time(),
  1083. "uid"=>$i
  1084. ];
  1085. Db::name("user_certification")->insert($data);
  1086. }
  1087. return app("json")->success('成功');
  1088. }
  1089. public function phoneCheck(UserRepository $repository){
  1090. $data = $this->request->params(['phone']);
  1091. $user = $repository->accountByUser($data['phone']);
  1092. if($user){
  1093. return app("json")->success('手机号已注册,可直接绑定',1);
  1094. }else{
  1095. return app("json")->success('手机号未注册,请输入密码',2);
  1096. }
  1097. }
  1098. /*支付宝获取签名*/
  1099. public function aliSign(){
  1100. $repository = app()->make(UserRepository::class);
  1101. $data = $repository ->aliSign();
  1102. return app("json")->success('ok',$data);
  1103. }
  1104. /*支付宝授权登录*/
  1105. public function aliCheck(){
  1106. $data = $this->request->params(['user_id']);
  1107. if(!$data['user_id'] || $data['user_id'] == '' || $data['user_id'] =='undefined'){
  1108. return app('json')->fail("异常操作");
  1109. }
  1110. $repository = app()->make(UserRepository::class);
  1111. $result = $repository ->aliCheck($data['user_id']);
  1112. if(isset($result['code']) && $result['code'] == 200){
  1113. $user = $repository->accountByUser($result['user']['account']);
  1114. $tokenInfo = $repository->createToken($user);
  1115. $repository->loginAfter($user);
  1116. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1117. }
  1118. return app("json")->success('ok',$result);
  1119. }
  1120. /*微信信息获取*/
  1121. public function getWechat(){
  1122. $repository = app()->make(UserRepository::class);
  1123. return app('json')->success($repository->getWechat());
  1124. }
  1125. /*微信授权登录*/
  1126. public function wechatCheck(){
  1127. $data = $this->request->params(['openid']);
  1128. if(!$data['openid'] || $data['openid'] == '' || $data['openid'] =='undefined'){
  1129. return app('json')->fail("openid参数缺失");
  1130. }
  1131. $repository = app()->make(UserRepository::class);
  1132. if($this->source=='yhc'){
  1133. $result = $repository ->wechatCheckYhc($data['openid']);
  1134. }else{
  1135. $result = $repository ->wechatCheck($data['openid']);
  1136. }
  1137. if(isset($result['code']) && $result['code'] == 200){
  1138. $user = $repository->accountByUser($result['user']['account']);
  1139. $tokenInfo = $repository->createToken($user);
  1140. $repository->loginAfter($user);
  1141. if($this->source=='yhc'){
  1142. // $user=$user->toArray();
  1143. $user->avatar=Db::name('enterprise_user')->where('mer_id',$this->merId)->where('uid',$user['uid'])->value('avatar');
  1144. }
  1145. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1146. }
  1147. return app("json")->fail($result['msg']);
  1148. }
  1149. public function binding_yhc(UserAuthValidate $validate, UserRepository $repository)
  1150. {
  1151. $data = $this->request->params(['phone', 'third_user_id','type']);
  1152. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1153. return app('json')->fail("绑定失败");
  1154. }
  1155. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1156. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP','',0,"https://". $this->request->host(true));//2222
  1157. if($user){
  1158. $enterprise_user= Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->find();
  1159. if(!$enterprise_user){
  1160. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1161. }else if ($enterprise_user['openid']==''){
  1162. $update = ["openid" => $data['third_user_id']];
  1163. Db::name("enterprise_user")->where(['mer_id'=>$this->merId,'uid'=>$user->uid])->update($update);
  1164. }
  1165. // $pid = $this->request->param('spread', 0);
  1166. // $repository->bindSpread($user, intval($pid));
  1167. $tokenInfo = $repository->createToken($user);
  1168. $repository->loginAfter($user);
  1169. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1170. }else{
  1171. return app('json')->fail("绑定失败");
  1172. }
  1173. }
  1174. /**
  1175. * 支付宝微信注册绑定手机号
  1176. * type 1微信2支付宝
  1177. * third_user_id 微信openid 支付宝userId
  1178. * @param UserRepository $repository
  1179. */
  1180. public function binding(UserAuthValidate $validate, UserRepository $repository)
  1181. {
  1182. $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','nickName','avatarUrl','sms']);
  1183. if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
  1184. return app('json')->fail("绑定失败");
  1185. }
  1186. $data['password'] = '12345678';//密码已经去掉了。统一默认密码
  1187. $validate->sceneSmslogin()->check($data);
  1188. if($data['sms'] != 1){
  1189. if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
  1190. return app('json')->fail('验证码不正确');
  1191. }
  1192. $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true));//2222
  1193. if($user){
  1194. $userRepository = app()->make(UserRepository::class);
  1195. $userInfo = $userRepository->getOne(['uid' => $user->uid ?? $user['uid']]);
  1196. //绑定线下充值金额
  1197. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1198. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1199. $notBind = $unionUsersRepository->getAllNotBind($data['third_user_id']);
  1200. if ($notBind) {
  1201. $orderMerchantRepository->doBindUser($userInfo, $data['type']);
  1202. }
  1203. $user = $repository->accountByUser($data['phone']);
  1204. if ($data['type'] == 1) {
  1205. $data1 = ["wechat_user_id" => $data['third_user_id']];
  1206. if($this->source=='yhc' && $this->merId){ //一壶茶创建用户
  1207. $enterprise_user_count = Db::name("enterprise_user")->where("mer_id",$this->merId)->where('uid',$user->uid)->count();
  1208. if($enterprise_user_count<1){
  1209. $spread_data = $this->request->params(['spread', 'share_id']);
  1210. if (!intval($spread_data['spread'])) {
  1211. $spread_uid = Db::name('product_share')->where('id', $spread_data['share_id'])->value('uid');
  1212. }else{
  1213. $spread_uid=$spread_data['spread'];
  1214. }
  1215. if($this->inviter_verification(2,$spread_uid)==false){
  1216. return app('json')->fail('请输入正确邀请人手机号');
  1217. }
  1218. Db::name("enterprise_user")->insert(['mer_id'=>$this->merId,'uid'=>$user->uid,'openid'=>$data['third_user_id']]);
  1219. }
  1220. }
  1221. } else {
  1222. $data1 = ["ali_user_id" => $data['third_user_id']];
  1223. }
  1224. $data2 = [
  1225. "type" => $data['type'],
  1226. "uid" => $user->uid,
  1227. "nickname" => !empty($data['nickName']) ? $data['nickName'] : $user -> nickname,
  1228. "avater" => !empty($data['avatarUrl']) ? $data['avatarUrl'] : $user -> avater,
  1229. ];
  1230. $userRepository -> updateUser($user->uid,$data1,$data2);
  1231. $pid = $this->request->param('spread', 0);
  1232. $repository->bindSpread($user, intval($pid));
  1233. $tokenInfo = $repository->createToken($user);
  1234. $repository->loginAfter($user);
  1235. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1236. }else{
  1237. return app('json')->fail("绑定失败");
  1238. }
  1239. }
  1240. public function queryHaike(){
  1241. $merch_no = $this->request->params(['merch_no']);
  1242. if(!isset($merch_no['merch_no']) || empty($merch_no['merch_no'])){
  1243. return app('json')->fail("请输入商户号");
  1244. }
  1245. $res = Db::name("haike_account")->where("merch_no",$merch_no['merch_no'])->select();
  1246. if(!$res){
  1247. return app('json')->fail("这个商户号没有账单");
  1248. }
  1249. $merch = Db::name('merchant') -> where("merch_no",$merch_no['merch_no']) -> find();
  1250. $data['商户号'] = $merch_no['merch_no'];
  1251. $data['商户名称'] = $merch["mer_name"];
  1252. $data['商户手机号'] = $merch["mer_phone"];
  1253. $data['结算金额'] = 0;
  1254. $data['结算手续费'] = 0;
  1255. foreach ($res as $key => $value){
  1256. $data['结算金额'] += $value['settle_accounts'];
  1257. $data['结算手续费'] += $value['settle_accounts_fee'];
  1258. }
  1259. echo "<pre>";
  1260. dump($data);
  1261. return 1;
  1262. }
  1263. public function createUserNumberAll(){
  1264. $userRepository = app()->make(UserRepository::class);
  1265. $user = Db::name('user') -> select();
  1266. foreach($user as $key => $value){
  1267. $userRepository -> createUserNumber($value['uid']);
  1268. }
  1269. }
  1270. public function yijianlogin(UserRepository $repository)
  1271. {
  1272. try {
  1273. // Db::name('log')->insert(['data'=>'一键登录进来了']);
  1274. $token = $this->request->params(['token'])['token'];
  1275. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1276. ->regionId('cn-hangzhou')
  1277. ->asDefaultClient();
  1278. $result = AlibabaCloud::rpc()
  1279. ->product('Dypnsapi')
  1280. ->scheme('https')// https | http
  1281. ->version('2017-05-25')
  1282. ->action('GetMobile')
  1283. ->method('POST')
  1284. ->host('dypnsapi.aliyuncs.com')
  1285. ->options([
  1286. 'query' => [
  1287. 'RegionId' => "cn-hangzhou",
  1288. 'AccessToken' => $token
  1289. ],
  1290. ])
  1291. ->request();
  1292. // 将返回的结果转化为数组
  1293. $result = $result->toArray();
  1294. // Db::name('log')->insert(['data'=>json_encode($result)]);
  1295. //判断当前数组不为空
  1296. if (isset($result['GetMobileResultDTO']['Mobile'])) {
  1297. // token不为空返回手机号码
  1298. $phone = $result['GetMobileResultDTO']['Mobile'];
  1299. $user_res=Db::name('user')->where('account',$phone)->find();
  1300. if(!$user_res){
  1301. $repository->registr($phone, 123456,'APP',"http://app.bjtdba.com");
  1302. }
  1303. $user = $repository->accountByUser($phone);
  1304. $user = $repository->mainUser($user);
  1305. $tokenInfo = $repository->createToken($user);
  1306. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1307. } else {
  1308. //如果token为空
  1309. $res = [
  1310. 'state' => 0,
  1311. 'msg' => 'token无效'
  1312. ];
  1313. return app('json')->fail($res);
  1314. }
  1315. }catch (\Exception $e) {
  1316. Db::name('log')->insert(['data'=>'一键登录出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1317. }
  1318. }
  1319. //小程序获取 用户手机号
  1320. public function applet_phone(UserRepository $repository)
  1321. {
  1322. try {
  1323. // Db::name('log')->insert(['data'=>json_encode($this->request->param())]);
  1324. $sessionKey=$this->request->params(['sessionKey']);
  1325. $encryptedData=$this->request->params(['encryptedData']);
  1326. $share_id = $this->request->params(['share_id']);
  1327. $iv=$this->request->params(['iv']);
  1328. if(empty($sessionKey['sessionKey'])||empty($encryptedData['encryptedData'])||empty($iv['iv'])){
  1329. return app('json')->fail('参数不正确');
  1330. }
  1331. $appid = 'wx82986c4471ce7efc';
  1332. if($this->source=='yhc'){
  1333. $appid = 'wx82986c4471ce7efc';
  1334. }
  1335. $sessionKey =str_replace(' ','+', $sessionKey['sessionKey']);
  1336. $encryptedData=str_replace(' ','+',$encryptedData['encryptedData']);
  1337. $iv =str_replace(' ','+', $iv['iv']);
  1338. // dump($iv,$encryptedData);
  1339. // return ;
  1340. $pc = new WXBizDataCrypt($appid, $sessionKey);
  1341. // dump($pc);
  1342. $errCode = $pc->decryptData($encryptedData, $iv, $data );
  1343. // dump($errCode);
  1344. if ($errCode != 0) {
  1345. return app('json')->fail('没有获取到手机号1');
  1346. }
  1347. // dump($data);
  1348. $data=json_decode($data,true);
  1349. $phone=$data['purePhoneNumber']??'';
  1350. if($phone==''){
  1351. return app('json')->fail('没有获取到手机号2');
  1352. }
  1353. if (!preg_match("/^1[3456789]{1}\d{9}$/", $phone)){
  1354. return app('json')->fail('手机号格式错误');
  1355. }
  1356. $user_res=Db::name('user')->where('account',$phone)->find();
  1357. if(!$user_res){
  1358. $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
  1359. $repository->registr($phone, 123456,'APP',$spread_uid);
  1360. }
  1361. $user = $repository->accountByUser($phone);
  1362. if($this->source=='yhc' && $this->merId){
  1363. $where=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1364. $count=Db::name('enterprise_user')->where($where)->count();
  1365. if($count<1){
  1366. $insert=['mer_id'=>$this->merId,'uid'=>$user['uid']];
  1367. $data = $this->request->params(['spread', 'share_id']);
  1368. if(isset($data['spread']) && $data['spread']){
  1369. $insert['puid']= $data['spread'];
  1370. $insert['node_uid']= $data['spread'];
  1371. }else if(isset($data['share_id']) && $data['share_id']){
  1372. $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
  1373. $insert['puid']= $spread_uid;
  1374. $insert['node_uid']= $spread_uid;
  1375. }
  1376. if(!isset($insert['node_uid']) || !$insert['node_uid']){
  1377. return app('json')->fail('必须要有邀请人才能注册',['is'=>1]);
  1378. }
  1379. if(isset($data['spread']) && isset($zhuce)){
  1380. $insert['puid']= $data['spread'];
  1381. $insert['node_uid']= $data['spread'];
  1382. }
  1383. Db::name('enterprise_user')->insert($insert);
  1384. }
  1385. }
  1386. $user = $repository->mainUser($user);
  1387. $tokenInfo = $repository->createToken($user);
  1388. return app('json')->success($repository->returnToken($user, $tokenInfo));
  1389. }catch (Exception $exception){
  1390. Db::name('log')->insert(['data'=>'获取手机号失败--'.$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
  1391. }
  1392. }
  1393. public function phone_name()
  1394. {
  1395. try {
  1396. $phone=$this->request->params(['phone']);
  1397. if(empty($phone['phone'])){
  1398. return app('json')->fail('请填写手机号码');
  1399. }
  1400. $phone=$phone['phone'];
  1401. $uid=Db::name('user')->where('account',$phone)->find();
  1402. $user_name=Db::name('merchant')->where('uid',$uid['uid'])->value('mer_name');
  1403. if(!$user_name){
  1404. $user_name=$uid['nickname'];
  1405. }
  1406. return app('json')->success($user_name);
  1407. }catch (\Exception $e) {
  1408. Db::name('log')->insert(['data'=>'订单支付出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
  1409. }
  1410. }
  1411. public function get_auth_token(){
  1412. $params=$this->request->params(['url','origin']);
  1413. try {
  1414. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1415. ->regionId('cn-hangzhou')
  1416. ->asDefaultClient()->options([
  1417. ]);
  1418. $result = AlibabaCloud::rpc()
  1419. ->product('Dypnsapi')
  1420. ->scheme('https')// https | http
  1421. ->version('2017-05-25')
  1422. ->action('GetAuthToken')
  1423. ->method('POST')
  1424. ->host('dypnsapi.aliyuncs.com')
  1425. ->options([
  1426. 'query' => [
  1427. 'Url' => $params['url'],
  1428. 'Origin' => $params['origin'],
  1429. ],
  1430. ])
  1431. ->request();
  1432. $result = $result->toArray();
  1433. return app('json')->success($result);
  1434. }catch (Exception $e) {
  1435. return app('json')->success();
  1436. }
  1437. }
  1438. public function get_phone_with_token(){
  1439. $params=$this->request->params(['token']);
  1440. AlibabaCloud::accessKeyClient('LTAI5tAzGzm3Kjp8pzn7hHmx', '8ILb06tO6X7xxQk2uj2CDwFNbVWQei')
  1441. ->regionId('cn-hangzhou')
  1442. ->asDefaultClient()->options([]);
  1443. $result = AlibabaCloud::rpc()
  1444. ->product('Dypnsapi')
  1445. ->scheme('https')// https | http
  1446. ->version('2017-05-25')
  1447. ->action('GetPhoneWithToken')
  1448. ->method('POST')
  1449. ->host('dypnsapi.aliyuncs.com')
  1450. ->options([
  1451. 'query' => [
  1452. 'SpToken' => $params['token'],
  1453. ],
  1454. ])
  1455. ->request();
  1456. $result = $result->toArray();
  1457. return app('json')->success($result);
  1458. }
  1459. }