MobileController.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\common\controller\UserApi;
  5. use app\common\library\MobileConstant;
  6. use app\common\model\AdIndexOrderedFlow;
  7. use app\common\model\Area;
  8. use app\common\model\LogisticsCompany;
  9. use app\common\model\Mobile;
  10. use app\common\model\MobileInfo;
  11. use app\common\model\MobileOrder;
  12. use app\common\model\MobileOrderNo;
  13. use app\common\model\MobileOrderProduce;
  14. use app\common\model\MobileUserHistory;
  15. use app\common\model\Payment;
  16. use app\common\model\SysConfig;
  17. use app\common\service\Jdpay;
  18. use app\common\service\MobileComputer;
  19. use app\common\service\SmsSend;
  20. use app\common\service\TransferCheck;
  21. use app\service\byte_dance\ByteDanceOrderPush;
  22. use app\service\byte_dance\ByteDancePay;
  23. use app\service\byte_dance\OceanEngineService;
  24. use app\service\EsMobileService;
  25. use app\service\GantanhaoService;
  26. use app\service\fast_hand\AccessToken;
  27. use app\service\id\IdVerify;
  28. use think\App;
  29. use think\Db;
  30. use think\db\Query;
  31. /**
  32. * 靓号管理
  33. */
  34. class MobileController extends UserApi
  35. {
  36. protected $noNeedLogin = "*";
  37. protected $noNeedRight = '*';
  38. /**
  39. * 列表
  40. * @ApiMethod (POST)
  41. * @ApiParams (name="type",description="1靓号,2流量卡,3api号码,默认1")
  42. * @ApiParams (name="search_type",description="fuzzy模糊,precise精准")
  43. * @ApiParams (name="search_last",description="0,1是否搜索尾部")
  44. * @ApiParams (name="city_id",description="地区id")
  45. * @ApiParams (name="keyword",description="搜索内容,模糊就是字符串,精准就是数组")
  46. * @ApiParams (name="sort",description="price_asc价格从低到高,price_desc价格从高到低")
  47. * @ApiParams (name="network",description="网络")
  48. * @ApiParams (name="price_min",description="价格最低数字")
  49. * @ApiParams (name="price_max",description="价格最高数字")
  50. * @ApiParams (name="exclude_num",description="排除数字,数字[1,2,3]")
  51. * @ApiParams (name="num_max",description="数字较多,传数字")
  52. * @ApiParams (name="rule_position",description="规律位置,middle中间,tail尾部")
  53. * @ApiParams (name="rule_name",description="规律名,AAAA什么的")
  54. * @ApiParams (name="limit",description="limit")
  55. * @ApiParams (name="page",description="page")
  56. * @ApiParams (name="is_activity",description="是否是优惠号码")
  57. * @ApiParams (name="chanId",description="分站ID")
  58. * @ApiParams (name="is_offer",description="是[1]否特价号")
  59. * @ApiReturnParams (name=id,description=id)
  60. * @ApiReturnParams (name="type",description="1靓号,2流量卡")
  61. * @ApiReturnParams (name=logo,description=缩略图)
  62. * @ApiReturnParams (name=name,description=号码名称)
  63. * @ApiReturnParams (name=no,description=手机号)
  64. * @ApiReturnParams (name=type,description=1靓号2流量卡)
  65. * @ApiReturnParams (name=network,description=运营商)
  66. * @ApiReturnParams (name=city,description=城市)
  67. * @ApiReturnParams (name=privince,description=省份)
  68. * @ApiReturnParams (name=amount,description=售价)
  69. * @ApiReturnParams (name=amount_original,description=原价)
  70. * @ApiReturnParams (name=amount_exists,description=含话费)
  71. * @ApiReturnParams (name=amount_base,description=售价)
  72. * @ApiReturnParams (name=amount_charge,description=预充)
  73. * @ApiReturnParams (name=summary,description=简介)
  74. * @ApiReturnParams (name=saled,description=是否已出售)
  75. * @ApiReturnParams (name=status,description=0正常1已售2已下架)
  76. * @ApiReturnParams (name=is_activity,description=是否特价号)
  77. * @ApiReturnParams (name=activity_time_end,description=特价过期时间null永不过期)
  78. * @ApiReturnParams (name=view_count,description=正在浏览人数)
  79. * @ApiReturnParams (name=is_private,description=是否民营运营商)
  80. * @ApiReturnParams (name=hits,description="高亮数组,筛选规则才会有,true为高亮",type=array)
  81. * @ApiReturnParams (name=link,description=流量卡跳转链接,有则跳转,没有就跳转详情)
  82. * @ApiReturnParams (name="info.free_app",description=免流APP列表)
  83. * @ApiReturnParams (name="info.describe",description="套餐说明|资费详情")
  84. * @ApiReturnParams (name="info.content",description="详细内容|注意事项")
  85. * @ApiReturnParams (name="info.flow_year",description="每年流量(G)")
  86. * @ApiReturnParams (name="info.fee",description="资费")
  87. * @ApiReturnParams (name="info.first_month_free",description="首月是否免月租")
  88. * @ApiReturnParams (name="info.discount_title",description="简要优惠介绍")
  89. * @ApiReturnParams (name="info.flow_free_limit",description="前多少名免单")
  90. * @ApiReturnParams (name="info.flow_images",description="流量卡详情图片")
  91. */
  92. public function list(){
  93. // exit();
  94. $data=input();
  95. $page=empty($data['page'])?1:$data['page'];
  96. $limit=input('limit',15);
  97. $chanId=getChanId();
  98. $this->validate($data,[
  99. 'keyword'=>['max:11'],
  100. 'num_max'=>['integer','between:0,9'],
  101. 'rule_position'=>['in:middle,tail'],
  102. ]);
  103. if(empty($data['type'])){
  104. $data['type']=1;
  105. }
  106. if(in_array($data['type'],[Mobile::BEAUTI,Mobile::API])){
  107. $this->listBeauti($data['type']);
  108. }
  109. $hiddenColumn = Mobile::hiddenColumn();
  110. $model=Mobile::show($data);
  111. // $model->field($hiddenColumn,true);
  112. $model->field('mobile.`id`,`status`,`logo`,`name`,`brand`,`no`,`type`,`network`,`city_id`,`city`,`province_id`,`province`,`amount_exists`,`amount_original`,`amount_base`,`amount_charge`,`amount_proxy`,`amount_kill`,`amount`,`top_time`,`rec_time`,`summary`,`is_activity`,`activity_time_end`,`sort`,`sort_line`,`activity_time`,`stock_num`,`is_offer`,`card_status`,`select_num_status`,`product_no`,mobile.`proxy_status`,`send_template`,`not_send_template`,`min_age`,`max_age`,`link`,`sort_proxy`');
  113. $model->where('type',$data['type']);
  114. if(isset($data['price_min']) && is_numeric($data['price_min'])){
  115. $model->where('amount','>=',$data['price_min']);
  116. }
  117. if(!empty($data['price_max']) && is_numeric($data['price_max'])){
  118. $model->where('amount','<=',$data['price_max']);
  119. }
  120. if(!empty($data['search_type']) && !empty($data['keyword'])){
  121. if($data['search_type']=='fuzzy'){
  122. if(isset($data['search_last']) && $data['search_last']==1){
  123. $no=str_pad($data['keyword'],11,'-',STR_PAD_LEFT);
  124. for ($i=0;$i<11;$i++){
  125. if($no[$i]=='-'){
  126. continue;
  127. }
  128. if($i==0){
  129. continue;
  130. }
  131. $pos=$i+1;
  132. $model->where("filter_no_pos_{$pos}",$no[$i]);
  133. }
  134. }else {
  135. $model->where('no', 'like', "%{$data['keyword']}%");
  136. }
  137. }elseif ($data['search_type']=='precise'){
  138. foreach ($data['keyword'] as $k=>$v){
  139. $pos=$k+1;
  140. if($pos==1||$v===""||is_null($v))continue;
  141. $model->where("filter_no_pos_{$pos}",$v);
  142. }
  143. }
  144. }
  145. if(!empty($data['city_id'])){
  146. if (str_contains($data['city_id'],'-all')){
  147. $model->where('province_id',str_replace('-all','',$data['city_id']));
  148. }elseif (is_numeric($data['city_id'])) {
  149. $model->where('city_id', $data['city_id']);
  150. }elseif (preg_match('/\d+-\d+/',$data['city_id'])){
  151. $model->where('city_id',explode('-',$data['city_id']))[1];
  152. }
  153. }
  154. if(!empty($data['network'])){
  155. /*$network=array_column(MobileConstant::getNetwork(),'search','name');
  156. $works=[$data['network']];
  157. foreach ($network as $key=>$networkArr){
  158. if($key==$data['network']){
  159. $works=$networkArr;
  160. break;
  161. }
  162. }
  163. $model->whereIn('network',$works);*/
  164. $model->where('network',$data['network']);
  165. }
  166. if(isset($data['is_activity']) && $data['is_activity']){
  167. $model->where('is_activity',1);
  168. }
  169. if(!empty($data['exclude_num']) && is_array($data['exclude_num'])){
  170. //$model->whereNotLike('no',"%{$data['exclude_num']}%");
  171. foreach ($data['exclude_num'] as $num){
  172. if($num==1){
  173. continue;
  174. }
  175. $model->where("filter_num_{$num}",0);
  176. }
  177. }
  178. if(!empty($data['num_max'])){
  179. $model->where("filter_num_{$data['num_max']}",'>',3);
  180. }
  181. $rules=MobileConstant::getFilters();
  182. if(!empty($data['rule_name'])){
  183. if (!isset($rules[$data['rule_name']])) {
  184. $this->error('规律规则不支持');
  185. }
  186. $rule=$rules[$data['rule_name']];
  187. if(!empty($data['rule_position'])) {
  188. $model->where($rule[$data['rule_position']], 1);
  189. }else{
  190. $model->where(function (Query $query)use ($rule){
  191. $query->where($rule['middle'],1)->whereOr($rule['tail'],1);
  192. });
  193. }
  194. }
  195. if(!empty($data['is_offer'])){
  196. $model->where('is_offer','>',0);
  197. }
  198. /*if($chanId){
  199. $model->whereIn('hold_chan',[0,$chanId]);
  200. }else{
  201. $model->where('hold_chan',0);
  202. }*/
  203. $subIds=[];
  204. if($chanId){
  205. if(empty($data['sort'])) {
  206. $activityData = (clone $model)->where('hold_chan', $chanId)->order('sort_line')->select();
  207. /*$topRecData = (clone $model)
  208. ->join('mobile_sub', "mobile_sub.mobile_id=mobile.id and sub_admin_id=$chanId")
  209. ->where('sub_top_time|sub_rec_time', 1)
  210. ->where(function (Query $query) use ($activityData) {
  211. if ($activityData && $activityData->column('id')) {
  212. $query->whereNotIn('id', $activityData->column('id'));
  213. }
  214. })
  215. ->field('mobile.*')
  216. ->order('sub_sort_line')
  217. ->select();
  218. $subData = $activityData->merge($topRecData);
  219. $subIds = $subData->column('id');*/
  220. $subData=$activityData;
  221. $subIds=$activityData->column('id');
  222. $model->where('is_activity',0);
  223. }
  224. // $model->where('proxy_status', 0)
  225. // $model->where('proxy_id', $chanId);
  226. $model->join('mobile_proxy_status ps', 'mobile.id=ps.mobile_id', 'LEFT')->where(function($q) use($chanId){
  227. $q->where('mobile.proxy_id', $chanId)->where('ps.proxy_id', $chanId)->whereOr(function($q) use($chanId){
  228. $q->where('status', 0)->where('mobile.proxy_id is null')->where('ps.proxy_status', 0)->where('ps.proxy_id', $chanId);
  229. });
  230. });
  231. }else{
  232. $model->where('hold_chan',0)->where('proxy_id is null');
  233. }
  234. if($subIds){
  235. $model->whereNotIn('mobile.id',$subIds);
  236. }
  237. if(!empty($data['sort'])){
  238. if($data['sort']=='price_asc'){
  239. $model->order('amount','asc');
  240. }elseif($data['sort']=='price_desc'){
  241. $model->order('amount','desc');
  242. }
  243. }else{
  244. if($data['type']==1) {
  245. $model->order('sort_line');
  246. }
  247. elseif($chanId){
  248. $model->order('sort_proxy asc, sort asc');
  249. }
  250. else{
  251. $model->order('sort');
  252. }
  253. }
  254. // dump($model->fetchSql()->select());exit;
  255. $list=$model->paginate($limit,true)->toArray();
  256. $listData=$list['data'];
  257. if($page==1 && isset($subData)){
  258. foreach (array_reverse($subData->toArray()) as $item){
  259. array_unshift($listData,$item);
  260. }
  261. }
  262. $list['data']=$listData;
  263. $this->success('',$list);
  264. }
  265. protected function listBeauti($type){
  266. $chanId=getChanId();
  267. $data=input();
  268. $page=empty($data['page'])?1:$data['page'];
  269. $limit=input('limit')?:15;
  270. $query=[
  271. 'query'=>[
  272. "bool"=>[
  273. 'should'=>[
  274. [
  275. 'bool'=>[
  276. 'must'=>[
  277. [
  278. 'terms'=>[
  279. 'status'=>Mobile::beautiFrontShowStatus(),
  280. ],
  281. ],
  282. [
  283. 'bool'=>[
  284. 'must'=>[
  285. [
  286. 'term'=>[
  287. 'is_activity'=>0,
  288. ],
  289. ],
  290. [
  291. 'term'=>[
  292. 'hold_chan'=>0,
  293. ]
  294. ]
  295. ]
  296. ]
  297. ],
  298. [
  299. 'term'=>[
  300. 'type'=>$type,
  301. ]
  302. ]
  303. ]
  304. ]
  305. ],
  306. [
  307. 'bool'=>[
  308. 'must'=>[
  309. [
  310. 'terms'=>[
  311. 'status'=>Mobile::beautiFrontShowStatus(),
  312. ],
  313. ],
  314. [
  315. 'bool'=>[
  316. 'must'=>[
  317. [
  318. 'term'=>[
  319. 'is_activity'=>1,
  320. ],
  321. ],
  322. [
  323. 'term'=>[
  324. 'hold_chan'=>$chanId,
  325. ]
  326. ]
  327. ]
  328. ]
  329. ],
  330. [
  331. 'term'=>[
  332. 'type'=>$type,
  333. ]
  334. ]
  335. ]
  336. ]
  337. ]
  338. ]
  339. ]
  340. ],
  341. 'size'=>$limit,
  342. 'from'=>($page-1)*$limit,
  343. ];
  344. // dump($query);
  345. if(isset($data['price_min']) && is_numeric($data['price_min'])){
  346. $query['query']['bool']['should'][0]['bool']['must'][]['range']['total']['gte']=(int)$data['price_min'];
  347. $query['query']['bool']['should'][1]['bool']['must'][]['range']['total']['gte']=(int)$data['price_min'];
  348. }
  349. if(!empty($data['price_max']) && is_numeric($data['price_max'])){
  350. $query['query']['bool']['should'][0]['bool']['must'][]['range']['total']['lte']=(int)$data['price_max'];
  351. $query['query']['bool']['should'][1]['bool']['must'][]['range']['total']['lte']=(int)$data['price_max'];
  352. }
  353. if(!empty($data['sort'])){
  354. if($data['sort']=='price_asc'){
  355. $query['sort']['total']['order']='asc';
  356. }elseif($data['sort']=='price_desc'){
  357. $query['sort']['total']['order']='desc';
  358. }
  359. }elseif(isset($data['num_max']) && is_numeric($data['num_max'])){
  360. $query['sort']["filter_num_{$data['num_max']}"]['order']='desc';
  361. }else{
  362. /*$query['sort']['activity_time']['order'] = 'desc';
  363. $query['sort']['rec_time']['order'] = 'desc';
  364. $query['sort']['top_time']['order'] = 'desc';
  365. $query['sort']['sort']['order'] = 'asc';*/
  366. $query['sort']['sort_line']['order'] = 'asc';
  367. }
  368. if(!empty($data['search_type']) && !empty($data['keyword'])){
  369. if($data['search_type']=='fuzzy'){
  370. if(isset($data['search_last']) && $data['search_last']==1){
  371. $query['query']['bool']['should'][0]['bool']['must'][]['wildcard']['no']=['value'=>"*{$data['keyword']}"];
  372. $query['query']['bool']['should'][1]['bool']['must'][]['wildcard']['no']=['value'=>"*{$data['keyword']}"];
  373. }else {
  374. $query['query']['bool']['should'][0]['bool']['must'][]['wildcard']['no']=['value'=>"*{$data['keyword']}*"];
  375. $query['query']['bool']['should'][1]['bool']['must'][]['wildcard']['no']=['value'=>"*{$data['keyword']}*"];
  376. }
  377. }elseif ($data['search_type']=='precise'){
  378. foreach ($data['keyword'] as $k=>$v){
  379. $pos=$k+1;
  380. if($pos==1||!is_numeric($v))continue;
  381. $query['query']['bool']['should'][0]['bool']['must'][]['term']["filter_no_pos_{$pos}"]=$v;
  382. $query['query']['bool']['should'][1]['bool']['must'][]['term']["filter_no_pos_{$pos}"]=$v;
  383. }
  384. }
  385. }
  386. if(!empty($data['is_offer'])){
  387. $query['query']['bool']['should'][0]['bool']['must'][]['range']["is_offer"]['gt']=0;
  388. $query['query']['bool']['should'][1]['bool']['must'][]['range']["is_offer"]['gt']=0;
  389. }
  390. if(!empty($data['city_id'])){
  391. if (str_contains($data['city_id'],'-all')){
  392. $provinceId=str_replace('-all','',$data['city_id']);
  393. $query['query']['bool']['should'][0]['bool']['must'][]['term']["province_id"]=$provinceId;
  394. $query['query']['bool']['should'][1]['bool']['must'][]['term']["province_id"]=$provinceId;
  395. }elseif (is_numeric($data['city_id'])) {
  396. $query['query']['bool']['should'][0]['bool']['must'][]['term']["city_id"]=$data['city_id'];
  397. $query['query']['bool']['should'][1]['bool']['must'][]['term']["city_id"]=$data['city_id'];
  398. }elseif (preg_match('/\d+-\d+/',$data['city_id'])){
  399. $cityId=explode('-',$data['city_id'])[1];
  400. $query['query']['bool']['should'][0]['bool']['must'][]['term']["city_id"]=$cityId;
  401. $query['query']['bool']['should'][1]['bool']['must'][]['term']["city_id"]=$cityId;
  402. }
  403. }
  404. $rules=MobileConstant::getFilters();
  405. if(!empty($data['rule_name'])){
  406. if (!isset($rules[$data['rule_name']])) {
  407. $this->error('规律规则不支持');
  408. }
  409. $rule=$rules[$data['rule_name']];
  410. if(!empty($data['rule_position'])) {
  411. $query['query']['bool']['should'][0]['bool']['must'][]['term'][$rule[$data['rule_position']]]=1;
  412. $query['query']['bool']['should'][1]['bool']['must'][]['term'][$rule[$data['rule_position']]]=1;
  413. }else{
  414. $ruleQuery=[
  415. 'bool'=>[
  416. 'should'=>[
  417. [
  418. 'term'=>[
  419. $rule['middle']=>1,
  420. ]
  421. ],
  422. [
  423. 'term'=>[
  424. $rule['tail']=>1,
  425. ]
  426. ]
  427. ]
  428. ]
  429. ];
  430. $query['query']['bool']['should'][0]['bool']['must'][]=$ruleQuery;
  431. $query['query']['bool']['should'][1]['bool']['must'][]=$ruleQuery;
  432. }
  433. }
  434. if(!empty($data['network'])){
  435. $yys = EsMobileService::network($data['network']);
  436. $query['query']['bool']['should'][0]['bool']['must'][]['term']['yys']=$yys;
  437. $query['query']['bool']['should'][1]['bool']['must'][]['term']['yys']=$yys;
  438. // $query['query']['bool']['should'][0]['bool']['must'][]['term']['network']=['value'=>"*{$data['network']}*"];
  439. // $query['query']['bool']['should'][1]['bool']['must'][]['term']['network']=['value'=>"*{$data['network']}*"];
  440. // $query['query']['bool']['should'][0]['bool']['must'][]['term']['network']=["*{$data['network']}*"];
  441. // $query['query']['bool']['should'][1]['bool']['must'][]['term']['network']=["*{$data['network']}*"];
  442. // $query['query']['bool']['should'][0]['bool']['must'][]['term']['network']='移';
  443. // $query['query']['bool']['should'][1]['bool']['must'][]['term']['network']='移';
  444. // $query['query']['bool']['should'][0]['bool']['must'][]['term']['network']='动';
  445. // $query['query']['bool']['should'][0]['bool']['must'][]['term']['network']='网';
  446. // $query['query']['bool']['must'][0]['bool']['should'][]['match_phrase']['network']['query']=$data['network'];
  447. // $query['query']['bool']['must'][0]['bool']['should'][]['match_phrase']['network']['operator']='and';
  448. // $query['query']['bool']['must'][1]['bool']['should'][]['match_phrase']['network']['query']=$data['network'];
  449. }
  450. if(!empty($data['exclude_num']) && is_array($data['exclude_num'])){
  451. $data['exclude_num']=array_unique($data['exclude_num']);
  452. foreach ($data['exclude_num'] as $num){
  453. if(!is_numeric($num)){
  454. continue;
  455. }
  456. $query['query']['bool']['should'][0]['bool']['must'][]['term']["filter_num_{$num}"]=0;
  457. $query['query']['bool']['should'][1]['bool']['must'][]['term']["filter_num_{$num}"]=0;
  458. }
  459. }
  460. if(isset($data['is_activity']) && $data['is_activity']){
  461. $query['query']['bool']['should'][0]['bool']['must'][]['term']['is_activity']=1;
  462. $query['query']['bool']['should'][1]['bool']['must'][]['term']['is_activity']=1;
  463. }else{
  464. $activityShow=config('site.activity_no_show')?:1;
  465. if($activityShow==2){
  466. $query['query']['bool']['should'][0]['bool']['must'][]['term']['is_activity']=0;
  467. $query['query']['bool']['should'][1]['bool']['must'][]['term']['is_activity']=0;
  468. }
  469. }
  470. //dump($query);
  471. $esData = EsMobileService::get($query);
  472. // dump($esData);
  473. $esData['current_page']=$page;
  474. $esData['per_page']=$limit;
  475. $esData['has_more']=count($esData['data'])>=$limit;
  476. $rulePosition=$data['rule_position']??'';
  477. if(!empty($data['rule_name'])){
  478. foreach ($esData['data'] as &$mobile){
  479. $computer=MobileComputer::setMobile($mobile['no']);
  480. if($rulePosition=='tail'){
  481. App::invokeMethod([$computer,'check_'.$rule['tail']]);
  482. $hitTail=$computer->getHits();
  483. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  484. }elseif ($rulePosition=='middle'){
  485. App::invokeMethod([$computer,'check_'.$rule['middle']]);
  486. $hitMiddle=$computer->getHits();
  487. if($hitMiddle){
  488. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitMiddle]);
  489. }
  490. }else{
  491. // $mobile['hits']=[];
  492. App::invokeMethod([$computer,'check_'.$rule['tail']]);
  493. $hitTail=$computer->getHits();
  494. $hits=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  495. $hitResult = false;
  496. foreach ($hits as $hit) {
  497. if ($hit) {
  498. $hitResult = true;
  499. break;
  500. }
  501. }
  502. if (!$hitResult) {
  503. App::invokeMethod([$computer,'check_'.$rule['middle']]);
  504. $hitMiddle=$computer->getHits();
  505. if($hitMiddle){
  506. $hits=MobileComputer::makeHits($mobile['no'],[$hitMiddle]);
  507. }
  508. }
  509. $mobile['hits'] = $hits;
  510. }
  511. }
  512. }elseif(!empty($data['search_type']) && empty($data['rule_name'])){
  513. if(is_array($data['keyword'])){
  514. if(strlen(implode($data['keyword']))==1){
  515. $rule_position = config('site.rule_position');
  516. if($rule_position){
  517. $ruless = MobileConstant::getFilterss();
  518. foreach ($esData['data'] as &$mobile){
  519. $computer=MobileComputer::setMobile($mobile['no']);
  520. if($rulePosition=='tail'){
  521. foreach ($ruless as $v){
  522. App::invokeMethod([$computer,'check_'.$v['tail']]);
  523. $hitTail=$computer->getHits();
  524. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  525. if(!in_array('true',$mobile['hits'])){
  526. App::invokeMethod([$computer,'check_'.$v['middle']]);
  527. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  528. }else{
  529. break;
  530. }
  531. // print_r($mobile['hits']);
  532. // exit();
  533. }
  534. }
  535. }
  536. }
  537. }
  538. }elseif (empty($data['keyword'])){
  539. $rule_position = config('site.rule_position');
  540. if($rule_position){
  541. $ruless = MobileConstant::getFilterss();
  542. foreach ($esData['data'] as &$mobile){
  543. $computer=MobileComputer::setMobile($mobile['no']);
  544. if($rulePosition=='tail'){
  545. foreach ($ruless as $v){
  546. App::invokeMethod([$computer,'check_'.$v['tail']]);
  547. $hitTail=$computer->getHits();
  548. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  549. if(!in_array('true',$mobile['hits'])){
  550. App::invokeMethod([$computer,'check_'.$v['middle']]);
  551. $mobile['hits']=MobileComputer::makeHits($mobile['no'],[$hitTail]);
  552. }else{
  553. break;
  554. }
  555. // print_r($mobile['hits']);
  556. // exit();
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. // 判断数据有无
  564. $mobile_ids = [];
  565. foreach ($esData['data'] as $dv){
  566. $mobile_ids[] = $dv['id'];
  567. }
  568. $mobile_db_ids=Mobile::whereIn('id',$mobile_ids)->column('id');
  569. // es 需要删除的id
  570. $mobile_ids_es_del = array_diff($mobile_ids,$mobile_db_ids);
  571. if($mobile_ids_es_del){
  572. EsMobileService::delMobiles($mobile_ids_es_del);
  573. user_log("EsMobileService_indexList_delByMobile", $mobile_ids_es_del);
  574. $new_Data = [];
  575. foreach ($esData['data'] as $idk => $idv){
  576. if(!in_array($idv['id'],$mobile_ids_es_del)){
  577. // unset($esData['data'][$idk]);
  578. $new_Data[] = $idv;
  579. }
  580. }
  581. $esData['data'] = $new_Data;
  582. }
  583. $this->success('',$esData);
  584. }
  585. /**
  586. * 号码详情
  587. * @ApiParams (name=id,description=号码id)
  588. * @ApiReturnParams (name=copy_word,description=复制的内容)
  589. * @ApiReturnParams (name=card_status,description=1需上传三张身份证照片)
  590. */
  591. public function show(){
  592. $data=$this->_validate([
  593. 'id'=>['require']
  594. ]);
  595. $user=$this->auth->getUser();
  596. $mobile=Mobile::where('id','id')->with(['info'])->find($data['id']);
  597. if(!$mobile){
  598. EsMobileService::delMobiles([$data['id']]);
  599. $this->error('您查找的手机号已下架或不存在');
  600. }
  601. if($mobile['type']==1) {
  602. EsMobileService::addMobile($mobile);
  603. }
  604. //MobileUserHistory::add($user,$mobile);
  605. $mobile->addViewCount();
  606. $mobile->append(['view_count','copy_word']);
  607. $mobile->makeHidden();
  608. MobileInfo::makeFreeApp($mobile['info']);
  609. $this->success('',$mobile);
  610. }
  611. /**
  612. * 下单
  613. * @ApiMethod (POST)
  614. * @ApiParams (name=mobile_id,description=手机号ID)
  615. * @ApiParams (name=name,description=姓名)
  616. * @ApiParams (name=phone,description=手机号)
  617. * @ApiParams (name=sms_code,description=验证码)
  618. * @ApiParams (name=id_no,description="身份号码,450804198608275870",sample="450804198608275870")
  619. * @ApiParams (name=open_idcard_face_img,description="身份证正面照片",required=false)
  620. * @ApiParams (name=open_idcard_back_img,description="身份证反面照片",required=false)
  621. * @ApiParams (name=open_face_img,description="脸部照片",required=false)
  622. * @ApiParams (name=county,description="城市ID,区县id")
  623. * @ApiParams (name=address,description=详细地址)
  624. * @ApiParams (name=remark,description=备注)
  625. * @ApiParams (name=no,description=选号)
  626. * @ApiParams (name=pay_type,description="1微信2支付宝3京东4抖音小程序5快手小程序")
  627. * @ApiParams (name=return_url,description="支付完成回调页面链接")
  628. * @ApiParams (name=clickid,description="巨量引擎clickid")
  629. * @ApiParams (name=platform_source,description="来源平台")
  630. * @ApiReturnParams (name=pay_url,description="支付链接")
  631. * @ApiReturnParams (name=without_pay,description="是否不需要支付")
  632. * @ApiReturnParams (name=res,description="抖音支付时返回参数")
  633. */
  634. public function apply(){
  635. $needId=config('site.system_id_form_open')?true:false;
  636. $user=$this->auth->getUser();
  637. $data=$this->_validate([
  638. 'mobile_id'=>'require',
  639. 'name|姓名'=>['require','max:20'],
  640. 'phone|手机号'=>'require|mobile',
  641. //'id_no|身份证'=>['require','regex'=>'/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/'],
  642. 'county|地区'=>'require|integer',
  643. 'address|详细地址'=>['require','min:4', 'max:100'],
  644. ]);
  645. if($needId){
  646. $this->_validate([
  647. 'id_no|身份证'=>['require','regex'=>'/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/'],
  648. ]);
  649. }
  650. Db::startTrans();
  651. $mobile=Mobile::lock(true)->findOrFail($data['mobile_id']);
  652. if($mobile['type']==1){
  653. $this->_validate([
  654. 'pay_type'=>'require|in:'.implode(',',array_keys(MobileOrder::$payTypes)),
  655. ]);
  656. }
  657. if($mobile['type'] == 2){
  658. $this->_validate([
  659. 'id_no|身份证'=>['require','regex'=>'/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/'],
  660. ]);
  661. if($mobile['card_status']){
  662. $this->_validate([
  663. 'open_idcard_face_img|身份证正面照片' => 'require',
  664. 'open_idcard_back_img|身份证反面照片' => 'require',
  665. 'open_face_img|脸部照片' => 'require',
  666. ]);
  667. }
  668. $blackListConfig = config('site.flow_blacklist');
  669. if($blackListConfig){
  670. $blackList = [];
  671. $blackListTmp = explode("\r\n", $blackListConfig);
  672. foreach($blackListTmp as $key=>$val){
  673. $tmpId = explode(' ', $val);
  674. if(isset($tmpId[1]) && $tmpId[1]) $blackList[] = $tmpId[1];
  675. }
  676. if(in_array($data['id_no'], $blackList)) $this->error('该身份证号已被禁用');
  677. }
  678. $flowLimitAgeStart = $mobile['min_age'];
  679. $flowLimitAgeEnd = $mobile['max_age'];
  680. $birthDay = IdVerify::instance()->getBirthDay($data['id_no']);
  681. $age = $this->countAge($birthDay);
  682. if($flowLimitAgeStart && $age < $flowLimitAgeStart) $this->error('该身份证号年龄被限制');
  683. if($flowLimitAgeEnd && $age > $flowLimitAgeEnd) $this->error('该身份证号年龄被限制');
  684. if($mobile['send_template']){
  685. if(!Mobile::sendTemplateLimit($mobile, $data['county'])) $this->error('该地区暂不支持订购');
  686. }
  687. if($mobile['not_send_template']){
  688. if(Mobile::notSendTemplateLimit($mobile, $data['county'])) $this->error('该地区暂不支持订购');
  689. }
  690. }
  691. $mobile->shouldBuy();
  692. Area::shouldSend($data['county']);
  693. $system_sms_open = config('site.system_sms_open') ? true : false;
  694. if($system_sms_open && $mobile->needCheckSmsCode()) {
  695. SmsSend::setMobile($data['phone'])->setCode($data['sms_code'] ?? '')->setEvent('order')->check();
  696. }
  697. #禁止重复下单
  698. $hasOrder=MobileOrder::where('mobile_id',$mobile->id)
  699. ->where('phone',$data['phone'])
  700. ->where('create_time','>',time()-10)
  701. ->value('id');
  702. if($hasOrder){
  703. Db::rollback();
  704. $this->error('操作频繁');
  705. }
  706. // if($needId && Mobile::isType($mobile['type'])){
  707. if(Mobile::isType($mobile['type'])){
  708. // if($needId && !App::$debug) {
  709. if($needId || $mobile['type'] == 2) {
  710. IdVerify::instance()->check($data['name'] ?? '', $data['id_no'] ?? '');
  711. }
  712. if($mobile['type'] == 2){
  713. $orderLimit = config('site.'.$mobile['brand']);
  714. if($orderLimit && MobileOrder::orderLimit($data['id_no'], $orderLimit, $mobile['brand'])) $this->error('订购频繁');
  715. }
  716. //elseif(MobileOrder::hasOrdered($data['phone'],$mobile)){
  717. elseif(MobileOrder::hasOrdered($data['phone'],$mobile['brand'])){
  718. $this->error('订购频繁1');
  719. }
  720. }
  721. $order = $data;
  722. $order['s_id']=getChanId();
  723. $order['admin_id'] = $mobile['proxy_id'];
  724. $order['no'] = array_key_exists('no',$data)?$data['no']:$mobile['no'];
  725. $order['city'] = implode(',', Area::getTreeId($data['county']));
  726. $order['amount_original'] = $mobile['amount_original'];
  727. $order['amount_hd'] = $mobile['amount'];
  728. $order['amount_charge'] = $mobile['amount_charge'];
  729. $order['amount'] = $mobile['amount'];
  730. $order['amount_di'] = $mobile['amount_di'];
  731. $order['amount_base'] = bcsub($mobile['amount'],$mobile['amount_charge']);
  732. $order['type'] = $mobile['type'];
  733. $order['status'] = 0;
  734. $order['platform_source'] = input('platform_source');
  735. $order['api_goods_id'] = $mobile['api_goods_id'];
  736. if($user){
  737. $order['user_id']=$user['id'];
  738. }
  739. unset($order['county'], $order['sms_code']);
  740. $mobileOrder = (new MobileOrder);
  741. if($mobile['type']==2){
  742. $mobileOrder->flowOrderSubmit();
  743. }
  744. $mobileOrder->allowField(true)->save($order);
  745. // $mobileOrderProduce = (new MobileOrderProduce());
  746. // if($mobile['api_goods_id'] == 982203315714){
  747. // $mobileOrderProduce->allowField(true)->save($order);
  748. // // print_r(7777);
  749. // }
  750. // exit();
  751. //$succ=$mobileOrder;
  752. //if($mobile['type']==1) {
  753. $succ = $this->pay($mobileOrder, $data);
  754. //}
  755. #下架号码
  756. /*$mobile['status']=$mobile::S_DOWN;
  757. $mobile->save();*/
  758. Db::commit();
  759. $this->success('', $succ);
  760. }
  761. /**
  762. * 感叹号订单
  763. * @ApiMethod (POST)
  764. * @ApiParams (name=no,description=手机号)
  765. * @ApiParams (name=order_no,description=订单号)
  766. * @ApiParams (name=name,description=姓名)
  767. * @ApiParams (name=phone,description=联系人手机号)
  768. * @ApiParams (name=id_no,description="身份号码,450804198608275870",sample="450804198608275870")
  769. * @ApiParams (name=open_idcard_face_img,description="身份证正面照片",required=false)
  770. * @ApiParams (name=open_idcard_back_img,description="身份证反面照片",required=false)
  771. * @ApiParams (name=open_face_img,description="脸部照片",required=false)
  772. * @ApiParams (name=county,description="城市ID,区县id")
  773. * @ApiParams (name=address,description=详细地址)
  774. * @ApiParams (name=remark,description=备注)
  775. * @ApiParams (name=api_goods_id,description=商品编码)
  776. * @ApiParams (name=contact_code,description=触点编码)
  777. * @ApiParams (name=create_time,description=创建时间)
  778. * @ApiReturnParams (name=pay_url,description="支付链接")
  779. * @ApiReturnParams (name=without_pay,description="是否不需要支付")
  780. * @ApiReturnParams (name=res,description="抖音支付时返回参数")
  781. */
  782. public function gantanSynchronizeOrders(){
  783. // $needId=config('site.system_id_form_open')?true:false;
  784. // $user=$this->auth->getUser();
  785. $data=$this->_validate([
  786. 'no|手机号'=>'require',
  787. 'order_no|订单号'=>'require',
  788. 'name|姓名'=>['require','max:20'],
  789. 'phone|联系人手机号'=>'require|mobile',
  790. 'id_no|身份证'=>['require','regex'=>'/^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/'],
  791. 'county|地区'=>'require|integer',
  792. 'address|详细地址'=>['require','min:4', 'max:100'],
  793. 'api_goods_id|商品编码'=>['require'],
  794. 'contact_code|触点编码'=>['require'],
  795. 'create_time|创建时间'=>['require']
  796. ]);
  797. Db::startTrans();
  798. $order = $data;
  799. // $order['admin_id'] = $mobile['proxy_id'];
  800. $order['no'] = $data['no'];
  801. $order['city'] = implode(',', Area::getTreeId($data['county']));
  802. // $order['amount_original'] = $mobile['amount_original'];
  803. // $order['amount_hd'] = $mobile['amount'];
  804. // $order['amount_charge'] = $mobile['amount_charge'];
  805. // $order['amount'] = $mobile['amount'];
  806. // $order['amount_di'] = $mobile['amount_di'];
  807. // $order['amount_base'] = bcsub($mobile['amount'],$mobile['amount_charge']);
  808. // $order['type'] = $mobile['type'];
  809. $order['status'] = 10;
  810. // if($user){
  811. // $order['user_id']=$user['id'];
  812. // }
  813. unset($order['county']);
  814. MobileOrder::insert($order);
  815. $mobileOrder = (new MobileOrder);
  816. // $mobileOrder->allowField(true)->save($order);
  817. // $mobileOrder->info()->save([
  818. // 'mobile'=>$mobileOrder['mobile'],
  819. // // 'info'=>$mobileOrder['mobile']['info'],
  820. // ]);
  821. // }
  822. Db::commit();
  823. $this->success('', $order);
  824. }
  825. /**
  826. * 查询订单状态
  827. * @ApiMethod (GET)
  828. *
  829. * @ApiParams (name=order_no, description=订单编号)
  830. * @ApiReturnParams (name=order_no, description="订单编号")
  831. * @ApiReturnParams (name=produce_status, description="订单状态: 1. 已开卡, 0.未开卡")
  832. * @ApiReturnParams (name=produce_activation, description="激活状态: 1.已激活, 0.未激活")
  833. * @ApiReturnParams (name=produce_is_recharge, description="是否首充: 1.已首充, 0.未首充")
  834. * @ApiReturnParams (name=first_amount, description="首充金额")
  835. * @ApiReturnParams (name=no, description="生产号码")
  836. * @ApiReturnParams (name=logistics_numbers, description="物流编号")
  837. * @ApiReturnParams (name=failure_reason, description="失败原因")
  838. * @ApiReturnParams (name=create_time, description="下单时间")
  839. * @ApiReturnParams (name=update_time, description="更新时间")
  840. */
  841. public function getOrderStatus()
  842. {
  843. $orderNo = input('order_no');
  844. if (empty($orderNo)) {
  845. $this->error('订单编号不能为空');
  846. }
  847. $order = MobileOrder::where([
  848. 'order_no' => $orderNo,
  849. 'platform_source' => '敢探号'
  850. ])->field([
  851. 'order_no',
  852. 'produce_status',
  853. 'produce_activation',
  854. 'produce_is_recharge',
  855. 'first_amount',
  856. 'no',
  857. 'logistics_numbers',
  858. 'failure_reason',
  859. 'create_time',
  860. 'update_time',
  861. ])
  862. ->find();
  863. if (!$order) {
  864. $this->error('订单不存在');
  865. }
  866. $this->success('', $order);
  867. }
  868. protected function pay(MobileOrder $mobileOrder,$data,$is_continue=false){
  869. $params = input('param.');
  870. $clickid = $params['clickid'] ?? '';
  871. $data['return_url']=h5_link('pages/PaySuccess/PaySuccess?id='.$mobileOrder['id']);
  872. // if($mobileOrder['type']==2){
  873. // OceanEngineService::setQuery(['clickid'=>input('clickid')])->setAddon(['order_no'=>input('clickid')])->form();
  874. // }
  875. $succ=[
  876. 'pay_url'=>'',
  877. 'id'=>$mobileOrder['id'],
  878. 'without_pay'=>0,
  879. 'res'=>null,
  880. ];
  881. if($mobileOrder['amount']==0){
  882. $succ['without_pay']=1;
  883. $mobileOrder->paySuccessCallback();
  884. try {
  885. OceanEngineService::setQuery(['clickid'=>$clickid])->setAddon(['order_no'=>$clickid])->shopping();
  886. GantanhaoService::orderPurchase($mobileOrder);
  887. }catch (\Exception $e){}
  888. return $succ;
  889. }
  890. $payment=Payment::create([
  891. 'order_no'=>session_create_id(),
  892. 'amount'=>$mobileOrder['amount'],
  893. 'mobile_order_id'=>$mobileOrder['id'],
  894. 'params'=>[
  895. 'clickid'=>$clickid,
  896. ]
  897. ]);
  898. $filename=session_create_id(date('Ymd'));
  899. if(!is_dir($dir=RUNTIME_PATH.'/payment/')) {
  900. @mkdir($dir, 0777, true);
  901. }
  902. if($data['pay_type']==1){
  903. $info=Service::submitOrder($payment['amount'],
  904. $payment['order_no'],'wechat',"购买手机号{$mobileOrder['no']}",
  905. Service::notifyUrl('wechat',$payment['order_no']),$data['return_url']??'','wap');
  906. file_put_contents(RUNTIME_PATH.'/payment/'.$filename,$info->getContent());
  907. $succ['pay_url']=url('/index/index/payment/a/'.$filename,[],true,true);
  908. }elseif ($data['pay_type']==2){
  909. $info=Service::submitOrder($payment['amount'],
  910. $payment['order_no'],'alipay',"购买手机号{$mobileOrder['no']}",
  911. Service::notifyUrl('alipay',$payment['order_no']),$data['return_url']??'','wap');
  912. file_put_contents(RUNTIME_PATH.'/payment/'.$filename,view('alipay',['form'=>$info->getContent()])->getContent());
  913. $succ['pay_url']=url('/index/index/payment/a/'.$filename,[],true,true);
  914. }elseif ($data['pay_type']==3){
  915. $jdpay=App::invokeClass(Jdpay::class);
  916. $payData=$jdpay->order($payment['order_no'],$payment['amount'],"购买手机号{$mobileOrder['no']}");
  917. $succ=array_merge($succ,$payData);
  918. }elseif ($data['pay_type']==4){
  919. if($mobileOrder['platform_source'] == '美美靓号'){
  920. $payData=ByteDancePay::setInfo($payment['order_no'],$payment['amount'],"购买手机号{$mobileOrder['no']}")->get();
  921. $succ['res']=$payData;
  922. if(!$is_continue) {
  923. $push = new ByteDanceOrderPush();
  924. $push->setOrder($mobileOrder);
  925. $push->setPayment($payment);
  926. $push->get();
  927. }
  928. }else{
  929. $payData=ByteDancePay::setInfo2($payment['order_no'],$payment['amount'],"购买手机号{$mobileOrder['no']}")->getWangKa();
  930. // print_r($payData);
  931. $succ['res']=$payData;
  932. if(!$is_continue) {
  933. $push = new ByteDanceOrderPush();
  934. $push->setOrder($mobileOrder);
  935. $push->setPayment($payment);
  936. $push->getWangka();
  937. }
  938. }
  939. }elseif ($data['pay_type']==5){
  940. $getData['access_token'] = $this->_getKsAccessToken();
  941. $getData['app_id'] = config('kuaishou.appid');
  942. $user=$this->auth->getUser();
  943. $postData['open_id'] = Db('user')->where(['id'=>$user['id']])->value('k_openid'); //用户的openid
  944. $postData['out_order_no'] = $payment['order_no'];
  945. // $postData['total_amount'] = $payment['amount'];
  946. $postData['total_amount'] = $payment['amount']*100;
  947. $postData['subject'] = "购买手机号{$mobileOrder['no']}";
  948. $postData['detail'] = "购买手机号{$mobileOrder['no']}";
  949. // $postData['attach'] = 'asdfasdf';
  950. $postData['type'] = 1856;
  951. $postData['expire_time'] = 172800;
  952. $postData['notify_url'] =request()->domain()."/index/payment/notify_ks/order_no/{$payment['order_no']}";
  953. $sign = _makeKsSgin($getData, $postData);
  954. $postData['sign'] = $sign;
  955. $url = 'https://open.kuaishou.com/openapi/mp/developer/epay/create_order?' . http_build_query($getData);
  956. $json = json_encode($postData, 320);
  957. $res = jsonPost($url, $json);
  958. $resArr=json_decode($res,true);
  959. if(!is_array($resArr)){
  960. $this->error('请求支付失败');
  961. }
  962. if($resArr['result']!=1){
  963. $this->error($resArr['error_msg'],$postData);
  964. }
  965. $succ['res']=$resArr['order_info'];
  966. }
  967. return $succ;
  968. }
  969. private function _getKsAccessToken() {
  970. return AccessToken::get();
  971. }
  972. /**
  973. * 继续支付
  974. * @ApiParams (name=id,description=订单id)
  975. * @ApiParams (name=pay_type,description=支付方式与下单一样)
  976. * @ApiParams (name=return_url,description="支付完成回调页面链接")
  977. */
  978. public function continue_pay(){
  979. $data=$this->_validate([
  980. 'id'=>['require'],
  981. 'pay_type'=>'require|in:'.implode(',',array_keys(MobileOrder::$payTypes)),
  982. ]);
  983. $mobileOrder=MobileOrder::whereNull('pay_time')->findOrFail($data['id']);
  984. $mobileOrder->continuePay();
  985. $succ=$this->pay($mobileOrder,$data,true);
  986. $this->success('',$succ);
  987. }
  988. /**
  989. * 订单详情
  990. * @ApiParams (name=id,description=订单id)
  991. * @ApiReturnParams (name=no,description=手机号)
  992. * @ApiReturnParams (name=order_no,description=订单号)
  993. * @ApiReturnParams (name=amount_hd,description=活动价)
  994. * @ApiReturnParams (name=amount_original,description=原价)
  995. * @ApiReturnParams (name=amount_charge,description=预充)
  996. * @ApiReturnParams (name=describe,description=套餐说明)
  997. * @ApiReturnParams (name=proxy.wx_qr,description=客服二维码)
  998. * @ApiReturnParams (name=name,description=收货人)
  999. * @ApiReturnParams (name=phone,description=收货人手机号)
  1000. * @ApiReturnParams (name=id_no,description=收货人身份证)
  1001. * @ApiReturnParams (name=address,description=收货地址)
  1002. * @ApiReturnParams (name=remark,description=备注)
  1003. * @ApiReturnParams (name=create_time,description=下单时间)
  1004. * @ApiReturnParams (name=amount,description=订单金额)
  1005. * @ApiReturnParams (name=trans_name,description=快递名称)
  1006. * @ApiReturnParams (name=trans_no,description=快递单号)
  1007. * @ApiReturnParams (name=status,description="0=>'待付款',10=>'已付款',15=>'待发货',17=>'有号码未发货',20=>'待开卡',25=>'已完成',30=>'申请退款',50=>'已关闭',60=>'无号码',70=>'换卡',80=>'争议单',90=>'已退款',100=>'退款驳回',110=>'审核失败'")
  1008. * @ApiReturnParams (name=reason,description="状态为110审核失败时,敢探号审核失败原因")
  1009. * @ApiReturnParams (name=open_uploaded,description=是否已上传开卡资料)
  1010. * @ApiReturnParams (name=open_idcard_face_img,description=身份证正面照)
  1011. * @ApiReturnParams (name=open_idcard_back_img,description=身份证反面照)
  1012. * @ApiReturnParams (name=open_face_img,description=头像照)
  1013. * @ApiReturnParams (name=open_name,description=姓名)
  1014. * @ApiReturnParams (name=open_id_no,description=身份证号码)
  1015. * @ApiReturnParams (name=open_phone,description=手机号)
  1016. * @ApiReturnParams (name=pay_time,description=支付时间)
  1017. * @ApiReturnParams (name=expire_time,description=过期时间)
  1018. */
  1019. public function order_detail(){
  1020. $order = MobileOrder::with(['proxy','info'])->findOrFail(input('id'));
  1021. $order['proxy'] && $order['proxy']->hidden(['password']);
  1022. $order['describe'] = $order['info']['info']['describe']??'';
  1023. $reason = $order['gantanhao_data_notify'] ? json_decode($order['gantanhao_data_notify'], true) : '';
  1024. $order['reason'] = $reason ? $reason['reason'] : '';
  1025. $this->success('',$order);
  1026. }
  1027. /**
  1028. * 订单列表
  1029. * @ApiParams (name=page,description=page)
  1030. * @ApiParams (name=limit,description=limit)
  1031. * @ApiParams (name=phone,description="手机号,小程序可不传")
  1032. * @ApiParams (name=type,description=1靓号2流量卡)
  1033. * @ApiParams (name=status,description="状态:0待付款10:已付款15:待发货17:有号码未发货20:待开卡25:已完成30:申请退款50:已关闭60:无号码70:换卡80:争议单90:已退款100:退款驳回110:审核失败")
  1034. * @ApiSummary (流量卡状态15:已提运营25:已完成)
  1035. */
  1036. public function order_list(){
  1037. $user=$this->auth->getUser();
  1038. $data=input();
  1039. $this->_validate([
  1040. 'type|类型'=>['in:1,2'],
  1041. ]);
  1042. if(!$user){
  1043. $this->_validate([
  1044. 'phone|手机号'=>['require'],
  1045. ]);
  1046. }
  1047. $type=$data['type']??1;
  1048. $type=$type?:1;
  1049. $order=MobileOrder::with(['proxy','info'])
  1050. ->where(function ($q)use ($user,$data){
  1051. if(!empty($data['phone'])){
  1052. $q->where('phone',$data['phone']);
  1053. }elseif ($user){
  1054. $q->where('user_id',$user['id']);
  1055. }else{
  1056. $q->where('id',1);
  1057. }
  1058. })
  1059. ->filterShow($type)
  1060. ->where('type',$type)
  1061. ->order('id','desc');
  1062. if(isset($data['status']) && $data['status']!==''){
  1063. if($data['status']==0){
  1064. $status=[
  1065. $data['status'],17,60,70,80,
  1066. ];
  1067. $order->whereIn('status',$status);
  1068. }else {
  1069. $order->where('status', $data['status']);
  1070. }
  1071. }
  1072. $ret=$order->paginate(input('limit',15));
  1073. $this->success('',$ret);
  1074. }
  1075. /**
  1076. * 筛选配置
  1077. *
  1078. */
  1079. public function config(){
  1080. $config=[];
  1081. $networks=MobileConstant::getNetworkString();
  1082. $config['network']=$networks;
  1083. $config['rule']=MobileConstant::getRuleKeys();
  1084. $this->success('',$config);
  1085. }
  1086. /**
  1087. * 上传开卡资料
  1088. * @ApiParams (name=id,description=订单id)
  1089. * @ApiParams (name=idcard_face_img,description=身份证正面照片)
  1090. * @ApiParams (name=idcard_back_img,description=身份证反面照片)
  1091. * @ApiParams (name=face_img,description=本人照片)
  1092. * @ApiParams (name=name,description=本人姓名)
  1093. * @ApiParams (name=id_no,description=本人身份证号码)
  1094. * @ApiParams (name=phone,description=本人联系电话)
  1095. */
  1096. public function upload_identity(){
  1097. $data=$this->_validate([
  1098. 'id'=>['require'],
  1099. 'idcard_face_img|身份证正面照片'=>['require','url'],
  1100. 'idcard_back_img|身份证反面照片'=>['require','url'],
  1101. 'face_img|本人照片'=>['require','url'],
  1102. 'name|本人姓名'=>['require','max:10'],
  1103. 'id_no|本人身份证号码'=>['require'],
  1104. 'phone|本人联系电话'=>['require','integer'],
  1105. ]);
  1106. $order=MobileOrder::findOrFail($data['id']);
  1107. if($order['open_uploaded']){
  1108. $this->error('请勿再次上传');
  1109. }
  1110. IdVerify::instance()->check($data['name'],$data['id_no']);
  1111. $order['open_uploaded']=1;
  1112. $order['open_idcard_face_img']=$data['idcard_face_img'];
  1113. $order['open_idcard_back_img']=$data['idcard_back_img'];
  1114. $order['open_face_img']=$data['face_img'];
  1115. $order['open_name']=$data['name'];
  1116. $order['open_id_no']=$data['id_no'];
  1117. $order['open_phone']=$data['phone'];
  1118. if(!$order->save()){
  1119. $this->error('保存失败');
  1120. }
  1121. $this->success('');
  1122. }
  1123. /**
  1124. * 预定号码
  1125. * @ApiParams (name=no,description=号码)
  1126. * @ApiParams (name=price_min,description=最低承受价格)
  1127. * @ApiParams (name=price_max,description=最高承受价格)
  1128. * @ApiParams (name=remark,description=备注)
  1129. * @ApiParams (name=name,description=姓名)
  1130. * @ApiParams (name=phone,description=联系电话)
  1131. * @ApiParams (name=county,description=区县ID)
  1132. * @ApiParams (name=address,description=详细地址)
  1133. */
  1134. public function order_no(){
  1135. $data=$this->_validate([
  1136. 'no|预定号码'=>['require','integer','min:3','max:8'],
  1137. //'price_min'=>['require','integer','min:0'],
  1138. 'price_max|可承受价格'=>['require','integer','min:0'],
  1139. 'name|姓名'=>['require'],
  1140. 'phone|联系电话'=>['require','integer','length:11'],
  1141. 'county|城市'=>['require','integer'],
  1142. 'address|详细地址'=>['require','length:0,250'],
  1143. ]);
  1144. $no=new MobileOrderNo;
  1145. $data['city']=implode(',',Area::getTreeId($data['county']));
  1146. $no->allowField(true)->save($data);
  1147. $this->success('');
  1148. }
  1149. /**
  1150. * 横幅播报
  1151. * @ApiReturnParams (name=ordered_num,description=已订购人数)
  1152. * @ApiReturnParams (name=no,description=号码)
  1153. * @ApiReturnParams (name=name,description=人名)
  1154. * @ApiReturnParams (name=num,description=人数)
  1155. */
  1156. public function ordered_show(){
  1157. $data=[];
  1158. $data['ordered_num']=SysConfig::look('mo_ordered_num',0);
  1159. $data['ordered_list']=AdIndexOrderedFlow::field('name,no,num')
  1160. ->order('num','asc')
  1161. ->select();
  1162. foreach ($data['ordered_list'] as $item){
  1163. $item['no']=substr($item['no'],0,3).'****'.substr($item['no'],7,4);
  1164. $item['name']=mb_substr($item['name'],0,mb_strlen($item['name'])-1).'*';
  1165. }
  1166. $this->success('',$data);
  1167. }
  1168. /**
  1169. * 退款
  1170. * @ApiMethod (POST)
  1171. * @ApiParams (name=id,description=订单id)
  1172. * @ApiParams (name=reason,description=退款原因)
  1173. */
  1174. public function refund(){
  1175. $data=$this->_validate([
  1176. 'id'=>'require',
  1177. 'reason'=>'require|max:250',
  1178. ]);
  1179. Db::startTrans();
  1180. $order=MobileOrder::lock(true)->findOrFail($data['id']);
  1181. $order->checkAllowRefund();
  1182. $order->makeUserRefund($data['reason']);
  1183. Db::commit();
  1184. $this->success();
  1185. }
  1186. /**
  1187. * 查询物流
  1188. * @ApiMethod (POST)
  1189. * @ApiParams (name=id,description=订单id)
  1190. * @ApiReturnParams (name=AcceptTime,description=时间)
  1191. * @ApiReturnParams (name=AcceptStation,description=描述)
  1192. */
  1193. public function logistics(){
  1194. $data=$this->_validate([
  1195. 'id'=>['require'],
  1196. ]);
  1197. $order=MobileOrder::findOrFail($data['id']);
  1198. $logistics=[];
  1199. if(!$order['trans_id']||!$order['trans_no']){
  1200. $this->success('',$logistics);
  1201. }
  1202. $logistics=TransferCheck::instance()->setNo($order['trans_no'])->setLogisticsCompany(LogisticsCompany::get($order['trans_id']))->setPhone($order['phone'])->setName($order['name'])->get();
  1203. $this->success('',$logistics);
  1204. }
  1205. /**
  1206. * 预占号码
  1207. * @ApiParams (name=id,description=号码ID)
  1208. * @ApiParams (name=chanId,description=通道ID)
  1209. */
  1210. public function take(){
  1211. $data=$this->_validate([
  1212. 'id|号码'=>['require','gt:0'],
  1213. ]);
  1214. $open=config('site.auto_take_open');
  1215. $discount=config('site.auto_take_discount');
  1216. if(!$open){
  1217. $this->success('未开启');
  1218. }
  1219. if($discount<=0||$discount>10){
  1220. $this->success('参数错误');
  1221. }
  1222. Db::startTrans();
  1223. $mobile=Mobile::lock(true)->findOrFail($data['id']);
  1224. if($mobile['is_activity']){
  1225. Db::rollback();
  1226. $this->success('已开启');
  1227. }
  1228. $chanId=getChanId();
  1229. $amount_kill=bcmul($mobile['amount_base'],$discount/10,0);
  1230. $mobile->makeActivity($amount_kill,$chanId);
  1231. Db::commit();
  1232. $this->success('改价成功');
  1233. }
  1234. /**
  1235. * 流量卡上传身份证照片
  1236. * @ApiMethod (POST)
  1237. * @ApiParams (name=id,description=订单id)
  1238. * @ApiParams (name=idcard_face_img,description=身份证正面照片)
  1239. * @ApiParams (name=idcard_back_img,description=身份证反面照片)
  1240. * @ApiParams (name=face_img,description=本人照片)
  1241. */
  1242. public function upload_identity_flow(){
  1243. $data = $this->_validate([
  1244. 'id'=>['require'],
  1245. 'idcard_face_img|身份证正面照片'=>['require','url'],
  1246. 'idcard_back_img|身份证反面照片'=>['require','url'],
  1247. 'face_img|本人照片'=>['require','url']
  1248. ]);
  1249. $order = MobileOrder::findOrFail($data['id']);
  1250. $dataGantanhao = $order['gantanhao_data'] ? json_decode($order['gantanhao_data'], true) : [];
  1251. if(!$dataGantanhao || !isset($dataGantanhao['str_rand']) || !$dataGantanhao['str_rand']){
  1252. $this->error('暂无法重新上传');
  1253. }
  1254. try{
  1255. GantanhaoService::orderPhotos($dataGantanhao['str_rand'], $data);
  1256. $order['open_idcard_face_img'] = $data['idcard_face_img'];
  1257. $order['open_idcard_back_img'] = $data['idcard_back_img'];
  1258. $order['open_face_img'] = $data['face_img'];
  1259. $order->save();
  1260. }
  1261. catch(\Exception $e){
  1262. if(stripos($e,'413')){
  1263. $this->error('图片过大');
  1264. }
  1265. Log::error("流量卡上传身份证照片:".json_encode($e));
  1266. $this->error('保存失败');
  1267. }
  1268. $this->success('上传成功');
  1269. }
  1270. /**
  1271. * 计算年龄
  1272. */
  1273. private function countAge($birthDay = ''){
  1274. if(!$birthDay) return false;
  1275. $age = strtotime($birthDay['year'].$birthDay['month'].$birthDay['day']);
  1276. if($age === false) return false;
  1277. list($y, $m, $d) = explode('-', date('Y-m-d'));
  1278. $age = $y - $birthDay['year'];
  1279. if((int)($m.$d) < (int)($birthDay['month'].$birthDay['day'])) $age -= 1;
  1280. return $age;
  1281. }
  1282. public function test(){
  1283. dump(ROOT_PATH);
  1284. dump(parse_url('https://lh.hdlkeji.com/uploads/20230221/0866987639c981b0f59dcc43cdffdc16_hr5n1hkhdap6gcadj63eh7vrmg.jpeg'));
  1285. }
  1286. /**
  1287. * 选号
  1288. * @ApiMethod (POST)
  1289. * @ApiParams (name=product_no,description=产品编码)
  1290. */
  1291. public function select_num_flow(){
  1292. $data = $this->_validate([
  1293. 'product_sku'=>['require'],
  1294. ]);
  1295. $list = GantanhaoService::getSelectNum($data['product_sku']);
  1296. $this->success('成功',$list);
  1297. }
  1298. //es缓存测试
  1299. public function es_ceshi(){
  1300. $mobile = Mobile::where('id',142519741)->with(['info'])->find();
  1301. // $mobile=Mobile::where('id','id')->with(['info'])->find($data['id']);
  1302. EsMobileService::addMobile($mobile);
  1303. // $mobile['amount']=intval($mobile['amount']);
  1304. // $mobile['amount'] = $a;
  1305. // dump($mobile['amount']);
  1306. // EsMobileService::delMobiles([$mobile['id']]);
  1307. // EsMobileService::addMobiles($mobile);
  1308. // EsMobileService::delMobile($mobile);
  1309. // $mobile=Mobile::where('id','id')->with(['info'])->find($data['id']);
  1310. // print_r(EsMobileService::get(13155666082));
  1311. }
  1312. }