Auth.php 67 KB

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