浏览代码

cusomer stats

zz 6 年之前
父节点
当前提交
596bbae4d1

+ 106 - 0
app/Console/Commands/LatestCustomerMsg.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use Redis;
+use DB;
+use Hashids;
+
+class LatestCustomerMsg extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'LatestCustomerMsg';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Command description';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $this->start();
+    }
+
+    private function start()
+    {
+        Redis::del('latestcustomerinfo');
+        $sites = redisEnv('CUSTOM_CHAPTER_ORDER_SITES', '');
+        if (!$sites) return;
+        $sites = explode(',', $sites);
+        $result = \App\Modules\OfficialAccount\Models\CustomSendMsgs::where('send_time', '>=', date('Y-m-d H:i:s', time() - 10 * 3600 - 3 * 86400))
+            ->where('send_time', '<=', date('Y-m-d H:i:s', time() - 10 * 3600))
+            ->whereIn('distribution_channel_id', $sites)
+            ->select('id', 'redirect_url', 'send_time')
+            ->get();
+        if ($result->isEmpty()) return;
+        foreach ($result as $item) {
+            if (!$item->redirect_url) continue;
+            $url_info = parse_url($item->redirect_url);
+            if (isset($url_info['path']) && isset($url_info['query'])) {
+                if (strpos('/reader', $url_info['path']) === false ||
+                    strpos('/yun', $url_info['path']) === false ||
+                    strpos('/detail', $url_info['path']) === false
+                ) {
+                    continue;
+                }
+                $bid = null;
+                if (strpos('/reader', $url_info['path']) !== false) {
+                    parse_str($url_info['query'], $param);
+                    if (!isset($param['bid'])) {
+                        continue;
+                    }
+                    if ($param['bid'] == 'undefined') continue;
+                    $bid_info = Hashids::decode($param['bid']);
+                    $bid = isset($bid_info[0]) ? $bid_info[0] : 0;
+                }
+
+                /*if (strpos('/detail',$url_info['path']) !== false) {
+                    parse_str($url_info['query'],$param);
+                    if (!isset($param['id'])) {
+                        continue;
+                    }
+                    if($param['id'] == 'undefined') continue;
+                    $bid_info = \Hashids::decode($param['id']);
+                    $bid = isset($bid_info[0])?$bid_info[0]:0;
+                }
+
+                if (strpos($url_info['path'],'/yun/') !== false) {
+                    $send_order_id = str_replace('/yun/','',$url_info['path']);
+                    $send_order_info = \App\Modules\SendOrder\Services\SendOrderService::getById($send_order_id);
+                    if($send_order_info){
+                        $bid = $send_order_info->book_id;
+                    }
+                }*/
+                if (!$bid) continue;
+
+                Redis::hset('latestcustomerinfo', $item->id, json_encode([
+                    'bid' => $bid,
+                    'send_time' => $item->send_time
+                ]));
+            }
+
+        }
+    }
+}

+ 38 - 9
app/Console/Commands/channelCpcCode.php

@@ -6,6 +6,7 @@ use App\Modules\Channel\Services\ChannelService;
 use App\Modules\Channel\Services\CompanyService;
 use Illuminate\Console\Command;
 use Redis;
+use DB;
 
 class channelCpcCode extends Command
 {
@@ -14,7 +15,7 @@ class channelCpcCode extends Command
      *
      * @var string
      */
-    protected $signature = 'channel:cpccode';
+    protected $signature = 'channel:cpccode {--get}';
 
     /**
      * The console command description.
@@ -40,20 +41,48 @@ class channelCpcCode extends Command
      */
     public function handle()
     {
-        $this->start();
+        $options = $this->option('get');
+        if($options){
+            $this->fetchtoDB();
+        }else{
+            $this->start();
+        }
     }
 
     private function start()
     {
         $result = CompanyService::getAllCompanyCpcCode();
+        //$result = DB::table('')
         foreach ($result as $item){
-           $channels = ChannelService::getByChannelUserId($item->id);
-            $code = empty($item->channel)?'zw001':$item->channel;
-           if($channels->isNotEmpty()){
-               foreach ($channels as $channel) {
-                   Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
-               }
-           } 
+            $channel_user = DB::table('channel_users')->where('company_id',$item->id)->select('id')->get();
+            if($channel_user->isNotEmpty()){
+                foreach ($channel_user as $channel_user_id_info) {
+                    $channels = ChannelService::getByChannelUserId($channel_user_id_info->id);
+                    $code = empty($item->channel)?'zw001':$item->channel;
+                    if($channels->isNotEmpty()){
+                        foreach ($channels as $channel) {
+                            Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    private function fetchtoDB()
+    {
+        DB::select( 'truncate table cpc_channel_temp');
+        for ($i = 1;$i<7000;$i++){
+            //Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
+            $c = \Redis::hget('channel:setting:'.$i,'cpc_channel');
+            if ($c) {
+                \DB::table('cpc_channel_temp')->inset([
+                    'distribution_channel_id'=>$i,
+                    'channel'=>$c,
+                    'created_at'=>date('Y-m-d H:i:s')
+                ]);
+            }
         }
     }
 }

+ 33 - 0
app/Http/Controllers/Wap/Book/ChapterController.php

@@ -11,6 +11,7 @@ use App\Modules\Statistic\Services\AdVisitStatService;
 use App\Modules\Statistic\Services\DataAnalysisChapterService;
 use App\Modules\Statistic\Services\DataAnalysisSelectUserService;
 use App\Modules\Statistic\Services\WapVisitStatService;
+use App\Modules\Subscribe\Services\CustomChapterOrderService;
 use App\Modules\Subscribe\Services\OrderService;
 use App\Modules\Subscribe\Models\Order;
 use App\Modules\User\Services\ForceSubscribeUserIService;
@@ -745,6 +746,7 @@ class ChapterController extends BaseController
                 if($this->user){
                     $this->user->balance -= $fee;
                 }
+                $this->customChapterOrderStats($fee);
                 return true;
             }
         }
@@ -1853,6 +1855,37 @@ class ChapterController extends BaseController
         }
     }
 
+    private function customChapterOrderStats($fee)
+    {
+        //custom_290824
+        if(strpos($this->from_type,'custom') === false){
+            return ;
+        }
+        $customer_id= str_ireplace('custom_','',$this->from_type);
+        if(!$customer_id || !is_numeric($customer_id)) return ;
+        $info = Redis::hget('latestcustomerinfo',$customer_id);
+        if(!$info) return ;
+        $info_array = json_decode($info,1);
+        $customer_bid = isset($info_array['bid'])?$info_array['bid']:0;
+        $customer_send_time = isset($info_array['send_time'])?$info_array['send_time']:0;
+        if(!$customer_bid || !$customer_send_time) return ;
+        CustomChapterOrderService::create([
+            'distribution_channel_id'=>$this->distribution_channel_id,
+            'bid'=>$this->book_info->bid,
+            'cid'=>$this->cid,
+            'chapter_name'=>$this->chapter->name,
+            'uid'=>$this->uid,
+            'send_order_id'=>$this->send_order_id,
+            'fee'=>$fee,
+            'charge_balance'=>0,
+            'reward_balance'=>0,
+            'custom_id'=>$customer_id,
+            'flag'=>$customer_bid == $this->book_info->bid?1:0,
+            'send_time'=>$customer_send_time
+        ]);
+
+    }
+
     public function getWechatJsConfig(Request $request)
     {
         //try {

+ 12 - 0
app/Modules/Subscribe/Models/CustomChapterOrder.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Modules\Subscribe\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomChapterOrder extends Model
+{
+    protected $table = 'custom_chapter_orders';
+    protected $fillable = ['distribution_channel_id','bid','cid','chapter_name','book_name','uid','send_order_id',
+    'fee','custom_id','flag','charge_balance','reward_balance','send_time'];
+}

+ 22 - 0
app/Modules/Subscribe/Services/CustomChapterOrderService.php

@@ -0,0 +1,22 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: z-yang
+ * Date: 2019/5/14
+ * Time: 17:09
+ */
+
+namespace App\Modules\Subscribe\Services;
+
+use Exception;
+use App\Modules\Subscribe\Models\CustomChapterOrder;
+
+class CustomChapterOrderService
+{
+    public static function create(array $data){
+        try{
+            CustomChapterOrder::create($data);
+        }catch (Exception $e){
+        }
+    }
+}