123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\service\mobile_get;
- use app\common\library\MobileConstant;
- use app\common\model\Area;
- use app\common\model\Mobile;
- use app\common\model\SysConfig;
- use app\common\service\MobileComputer;
- use GuzzleHttp\Client;
- use think\helper\Str;
- abstract class MobileGetService {
- protected function post($url,$data,$headers=[]){
- static $client;
- if(!$client){
- $client=new Client();
- }
- $body=[
- 'json'=>$data,
- ];
- if($headers){
- $body['headers']=$headers;
- }
- $result=$client->post($url,$body);
- return json_decode($result->getBody()->getContents(),true);
- }
- public function addMobile($data){
- $mobile=Mobile::where('no',$data['no'])->find();
- if(!$mobile){
- $mobile=new Mobile;
- $newer=1;
- }else{
- #非api号码不予增加
- if($mobile['type']!=$mobile::API){
- return false;
- }
- }
- $mobile->fill($data);
- $mobile['type']=$mobile::API;
- if(!empty($data['city'])){
- $city=Area::getModelByName($data['city'],2);
- if(!$city){
- return false;
- }
- $mobile['city_id']=$city['id'];
- $mobile['province_id']=$city['pid'];
- }
- if(isset($newer)) {
- // 底价都是0 ,售价就是我们设置的,代理价设置默认售价的5折,原价是售价的2倍
- //`amount_original` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '原价',
- //`amount_base` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '售价',
- //`amount_di` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '底价',
- //`amount_proxy` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '代理价',
- list($mobile['amount_base'],$rules)=$this->getAmount($mobile['no']);
- $mobile['amount_proxy'] = $mobile['amount_base']*0.5;
- $mobile['amount_original'] = $mobile['amount_base']*2;
- $mobile['amount_di'] = 0;
- $mobile->fill($rules);
- }
- $info_describe = $mobile['describe'];
- unset($mobile['describe']);
- if(!$mobile->save()){
- return false;
- };
- if(!$mobile->info) {
- $mobile->info()->save(['describe'=>$info_describe]);
- }
- return $mobile;
- }
- public function getAmount($no){
- static $config;
- if(!is_array($config)){
- $config=SysConfig::look('api_rule_price',[]);
- }
- $com=MobileComputer::setMobile($no);
- $tailRule=[];
- $rules=$com->filter();
- foreach ($rules as $key=>$is){
- if((Str::startsWith($key,'filter_middle') || Str::startsWith($key,'filter_tail')) && $is==1){
- $tailRule[]=MobileConstant::getFilterColumns()[$key];
- }
- }
- $tailRule=array_unique($tailRule);
- $prices=[0];
- foreach ($config as $key=>$priceArr){
- if(in_array($key,$tailRule)){
- if(empty($priceArr)||($priceArr['amount_min']==0 && $priceArr['amount_max']==0)){
- continue;
- }
- $prices[]=mt_rand($priceArr['amount_min'],$priceArr['amount_max']);
- }
- }
- if(!array_filter($prices)){
- $prices[]=mt_rand($config['none']['amount_min']??0,$config['none']['amount_max']??0);
- }
- return [
- max($prices),
- $rules,
- ];
- }
- protected static function log($data){
- user_log(basename(static::class),$data);
- }
- // 删除号码
- public function delMobile($api_goods_id){
- // 3天前 259200
- // $time = strtotime(date("Y-m-d",time())) - 259200;
- $num = (new Mobile())->where('mobile.type', Mobile::BEAUTI)
- ->whereIn('api_goods_id',$api_goods_id)
- ->whereNotIn('status','1')
- // ->where('create_time','<',$time)
- ->delete();
- Mobile::deleteOtherTableInfo();
- user_log('Noapidel',$logData=[
- 'date'=>date("Y-m-d",time()),
- 'num'=>$num,
- 'api_goods_id'=>$api_goods_id,
- ]);
- }
- }
|