|
@@ -2,14 +2,9 @@
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
-use App\Modules\Statistic\Services\WapVisitStatService;
|
|
|
-use App\Modules\User\Services\UserService;
|
|
|
use Illuminate\Console\Command;
|
|
|
use GuzzleHttp\Client;
|
|
|
-use App\Modules\Book\Models\Book;
|
|
|
-use App\Modules\Book\Models\BookConfig;
|
|
|
use DB;
|
|
|
-use Redis;
|
|
|
|
|
|
class BookSpider extends Command
|
|
|
{
|
|
@@ -25,7 +20,7 @@ class BookSpider extends Command
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $description = '更新图书列表';
|
|
|
+ protected $description = 'zytest';
|
|
|
|
|
|
/**
|
|
|
* Create a new command instance.
|
|
@@ -45,85 +40,97 @@ class BookSpider extends Command
|
|
|
*/
|
|
|
public function handle()
|
|
|
{
|
|
|
- //return $this->innerSendOrderId();
|
|
|
- /*$a = $this->recordFirstIntoPayPage(1148,123,1645454);
|
|
|
- print_r($a);*/
|
|
|
-
|
|
|
- $this->getSpecialChannelIdStats();
|
|
|
+ //32401811
|
|
|
+ $this->cpc();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新书籍列表
|
|
|
- * @return int
|
|
|
- */
|
|
|
- public function innerSendOrderId(){
|
|
|
- $template = "select CONCAT('template_',id) as id from `wechat_template_msgs` where del_flag=0 and is_show_list=1 and created_at >='2018-11-02' order by id desc limit 1000;
|
|
|
-";
|
|
|
- $custom = "select CONCAT('custom_',id) as id from `custom_send_msgs` where del_flag=0 and is_show_list=1 and created_at >='2018-11-02' order by id desc limit 10000;
|
|
|
-";
|
|
|
- $t = DB::select($template);
|
|
|
- if($t){
|
|
|
- foreach ($t as $v){
|
|
|
- $uv = Redis::SMEMBERS('push:distribution_channel_id:alluv:from:' . $v->id);
|
|
|
- $pv = Redis::hget('push:distribution_channel_id:allpv' , $v->id);
|
|
|
- if($uv){
|
|
|
- Redis::sadd('push:inner_send_order_id:uv:' . $v->id,$uv);
|
|
|
- }
|
|
|
- if($uv){
|
|
|
- Redis::hset('push:inner_send_order_id:pv' ,$v->id,$pv);
|
|
|
+ private function cpc(){
|
|
|
+ //32426552
|
|
|
+
|
|
|
+ $sql_format = "SELECT u.id,f.subscribe_time,u.openid,(SELECT ifnull(sum(price),0) from orders where uid = u.id and `status` = 'PAID' LIMIT 1)as amount FROM users u
|
|
|
+JOIN force_subscribe_users f on u.id = f.uid
|
|
|
+WHERE u.openid in (SELECT openid from users WHERE id = %s)";
|
|
|
+ $all = 32427;
|
|
|
+ for ($i =0;$i<=$all;$i++){
|
|
|
+ $subscribes = DB::table('force_subscribe_users')->where('id','>',$i*1000)->select('uid')->limit(1000)->get();
|
|
|
+ if($subscribes->isEmpty()){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ foreach ($subscribes as $value){
|
|
|
+ $result = DB::select(sprintf($sql_format,$value->uid));
|
|
|
+ if($result){
|
|
|
+ $user_property_info = $this->level($result);
|
|
|
+ $this->create($user_property_info);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $c = DB::select($custom);
|
|
|
- if($c){
|
|
|
- foreach ($c as $val){
|
|
|
- $uv = Redis::SMEMBERS('push:distribution_channel_id:alluv:from:' . $val->id);
|
|
|
- $pv = Redis::hget('push:distribution_channel_id:allpv' , $val->id);
|
|
|
- if($uv){
|
|
|
- Redis::sadd('push:inner_send_order_id:uv:' . $val->id,$uv);
|
|
|
- }
|
|
|
- if($pv){
|
|
|
- Redis::hset('push:inner_send_order_id:pv' ,$val->id,$pv);
|
|
|
- }
|
|
|
+ private function level($res){
|
|
|
+ $earliest_subscribe_time = $res[0]->subscribe_time;
|
|
|
+ $subscribe_three_day_info = [];
|
|
|
+ $subscribe_no_three_day_info = [];
|
|
|
+ foreach ($res as $v){
|
|
|
+ (strtotime($v->subscribe_time) < strtotime($earliest_subscribe_time)) && $earliest_subscribe_time = $v->subscribe_time;
|
|
|
+ if(time()-strtotime($v->subscribe_time) >= 86400*3){
|
|
|
+ array_push($subscribe_three_day_info,$v->amount);
|
|
|
+ }else{
|
|
|
+ array_push($subscribe_no_three_day_info,$v->amount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'earliest_subscribe_time'=>$earliest_subscribe_time,
|
|
|
+ 'property'=>'',
|
|
|
+ 'type'=>'',
|
|
|
+ 'openid'=> $res[0]->openid
|
|
|
+ ];
|
|
|
+ if($subscribe_three_day_info){
|
|
|
+ //存量用户
|
|
|
+ $result['type'] = 'CUILIANG';
|
|
|
+ $amount = round(array_sum($subscribe_three_day_info)/count($subscribe_three_day_info),2);
|
|
|
+ if($amount>15){
|
|
|
+ $result['property'] = 'high';
|
|
|
+ }elseif($amount >2){
|
|
|
+ $result['property'] = 'medium';
|
|
|
+ } elseif($amount >0){
|
|
|
+ $result['property'] = 'low';
|
|
|
+ } else{
|
|
|
+ $result['property'] = 'none';
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //新用户
|
|
|
+ $result['type'] = 'NEW';
|
|
|
+ if($subscribe_no_three_day_info)
|
|
|
+ $amount = max($subscribe_no_three_day_info);
|
|
|
+ else
|
|
|
+ $amount = 0;
|
|
|
+ if($amount>50){
|
|
|
+ $result['property'] = 'high';
|
|
|
+ }elseif($amount >2){
|
|
|
+ $result['property'] = 'medium';
|
|
|
+ } elseif($amount >0){
|
|
|
+ $result['property'] = 'low';
|
|
|
+ } else{
|
|
|
+ $result['property'] = 'none';
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private function getSpecialChannelIdStats(){
|
|
|
- $result = WapVisitStatService::getSpecialChannelIdStats(168502,'2018-11-24');
|
|
|
- print_r($result);
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private function recordFirstIntoPayPage($bid,$distribution_channel_id,$uid)
|
|
|
- {
|
|
|
- $start_time = env('RECORD_FIRST_VISIT_PAY_PAGE_TIME');
|
|
|
- $template_id = 0;
|
|
|
- if ($distribution_channel_id == 123 && $start_time && $uid) {
|
|
|
- $user = UserService::getById($uid);
|
|
|
- if (strtotime($user->created_at) > $start_time) {
|
|
|
- $old = DB::table('user_first_visit_pay_page')->where('uid', $uid)->select('uid', 'template_type')->first();
|
|
|
- if ($old) {
|
|
|
- $template_id = $old->template_type;
|
|
|
- }
|
|
|
- if ($bid && $bid == 1148) {
|
|
|
- $template_id = $uid % 2 == 0 ? 2 : 1;
|
|
|
- if (!$old) {
|
|
|
- try {
|
|
|
- DB::table('user_first_visit_pay_page')->insert([
|
|
|
- 'uid' => $uid,
|
|
|
- 'template_type' => $template_id,
|
|
|
- 'created_at' => date('Y-m-d H:i:s'),
|
|
|
- 'updated_at' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
- } catch (\Exception $e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ private function create($data){
|
|
|
+ $old = DB::table('user_division_cpc_property')->where('openid',$data['openid'])->where('is_enable',1)->first();
|
|
|
+ if(!$old){
|
|
|
+ DB::table('user_division_cpc_property')->insert([
|
|
|
+ 'openid'=>$data['openid'] ,
|
|
|
+ 'property'=>$data['property'] ,
|
|
|
+ 'is_enable'=>1 ,
|
|
|
+ 'type'=>$data['type'] ,
|
|
|
+ 'earliest_subscribe_time'=>$data['earliest_subscribe_time'] ,
|
|
|
+ 'created_at'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updated_at'=>date('Y-m-d H:i:s')
|
|
|
+ ]);
|
|
|
}
|
|
|
- return $template_id;
|
|
|
}
|
|
|
+
|
|
|
}
|