MobileController.php 61 KB

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