Jelajahi Sumber

crm transfer 1

zz 5 tahun lalu
induk
melakukan
e8e128cc2a

+ 0 - 103
app/Console/Commands/InnerOuterWeixinStats.php

@@ -1,103 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use Illuminate\Console\Command;
-use DB;
-use Redis;
-
-class InnerOuterWeixinStats extends Command
-{
-    /**
-     * The name and signature of the console command.
-     *
-     * @var string
-     */
-    protected $signature = 'InnerOuterWeixinStats {--day=}';
-
-    /**
-     * 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()
-    {
-        $day = $this->option('day');
-        if(!$day){
-            $day = date('Y-m-d',time()-86400);
-        }
-        $this->getByDay($day);
-    }
-
-    private function getByDay($day)
-    {
-        $keys = Redis::SMEMBERS('InnerOuterWeixinStats:'.$day);
-        if (!$keys) {
-            return ;
-        }
-        $data = [];
-        $i = 0;
-        foreach ($keys as $k){
-
-            list($from,$distribution_channel_id) = explode(':',$k);
-            if(!$from || !$distribution_channel_id) continue;
-            $pv_key = sprintf('InnerOuterWeixinStats:pv:%s:%s',$from,$distribution_channel_id);
-            $uv_key = sprintf('InnerOuterWeixinStats:uv:%s:%s:%s',$from,$distribution_channel_id,$day);
-            $pv = Redis::hget($pv_key,$day);
-            $uv = Redis::scard($uv_key);
-            $type = '';
-            $param = '';
-            if(is_numeric($from)){
-                $type = 'send_order';
-                $param = $from;
-            }
-
-            if(str_contains($from,['template'])){
-                $type = 'template';
-                list($temp,$param) = explode('_',$from);
-            }
-
-            if(str_contains($from,['custom'])){
-                $type = 'custom';
-                list($temp,$param) = explode('_',$from);
-            }
-            Redis::del($uv_key);
-            Redis::hdel($pv_key,$day);
-            if(!$type || !$param || !is_numeric($param)) continue;
-
-            $data[] = [
-                'type'=>$type,
-                'param'=>$param,
-                'pv'=>$pv,
-                'uv'=>$uv,
-                'day'=>$day,
-                'charge'=>0,
-                'updated_at'=>date('Y-m-d H:i:s'),
-                'created_at'=>date('Y-m-d H:i:s')
-            ];
-            if($i++ % 100 == 0){
-                DB::table('inner_outer_weixin_stats')->insert($data);
-                $data = [];
-            }
-        }
-        if($data){DB::table('inner_outer_weixin_stats')->insert($data);}
-        Redis::del('InnerOuterWeixinStats:'.$day);
-    }
-}

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

@@ -1,106 +0,0 @@
-<?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
-                ]));
-            }
-
-        }
-    }
-}

+ 0 - 1
app/Console/Kernel.php

@@ -24,7 +24,6 @@ class Kernel extends ConsoleKernel
         Commands\YqBook::class,
         Commands\channelCpcCode::class,
         Commands\updateFromNewYunqi::class,
-        Commands\InnerOuterWeixinStats::class,
         Commands\CheckOrderStatus::class,
     ];
 

+ 46 - 0
app/Modules/User/Services/UserService.php

@@ -369,6 +369,10 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
     }
 
     public static function transfer(int $from,int $to,int $distribution_channel_id){
+        $transfer_record = DB::table('crm_transfer')->where('from_uid',$from)->first();
+        if($transfer_record){
+            return ;
+        }
         //阅读记录迁移***************************************
         $record = Redis::hgetall('book_read:'.$from);
         $not_uid_key = ['last_read','sign_counts','sign_info','sign_day'];
@@ -378,6 +382,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                 $data[$k] = $item;
             }
         }
+        //\Log::info('read record is');
+        //\Log::info($data);
         if($data) Redis::hmset('book_read:'.$to,$data);
         //签到记录
         $user_sign_model = new UserSign();
@@ -395,6 +401,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'updated_at'=>date('Y-m-d H:i:s'),
                 ];
             }
+            //\Log::info('user_sign  is');
+            //\Log::info($temp);
             DB::table('user_sign'.date('Ym'))->insert($temp);
         }
         //订阅记录(按本)
@@ -413,6 +421,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'updated_at'=>date('Y-m-d H:i:s'),
                 ];
             }
+            //\Log::info('book_order  is');
+            //\Log::info($temp);
             DB::table('book_orders')->insert($temp);
         }
         //订阅记录(按章)
@@ -436,6 +446,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'updated_at'=>date('Y-m-d H:i:s')
                 ];
             }
+            //\Log::info('chapter order  is');
+            //\Log::info($temp);
             $chapter_model->insert($temp);
         }
         //打赏记录
@@ -456,6 +468,8 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'updated_at'=>date('Y-m-d H:i:s')
                 ];
             }
+            //\Log::info('book gift   is');
+            //\Log::info($temp);
             DB::table('book_gifts_send')->insert($tmp);
         }
         //书架
@@ -471,7 +485,39 @@ WHERE u.openid in (SELECT openid from users WHERE  id = %s)";
                     'updated_at'=>date('Y-m-d H:i:s')
                 ];
             }
+            //\Log::info('user book shelf  is');
+            //\Log::info($temp);
             DB::table('user_shelf_books')->insert($tmp);
         }
+        //包年
+        $result = DB::table('year_orders')->where('uid',$from)->where('end_time','>=',date('Y-m-d H:i:s'))->first();
+        if($result){
+            DB::table('year_orders')->insert([
+                'uid'=>$to,
+                'begin_time'=>$result->begin_time,
+                'end_time'=>$result->end_time,
+                'distribution_channel_id'=>$distribution_channel_id,
+                'send_order_id'=>$result->send_order_id,
+                'fee'=>$result->fee,
+                'created_at'=>date('Y-m-d H:i:s'),
+                'updated_at'=>$result->updated_at,
+            ]);
+            //\Log::info('year_orders  is');
+            //print_r($result);
+        }
+
+        //书币
+        $from_user = self::getById($from);
+        $to_user = self::getById($to);
+        $to_user->balance += $from_user->balance;
+        $to_user->reward_balance +=   $from_user->balance;
+        $to_user->save();
+        DB::table('crm_transfer')->insert([
+            'from_uid'=>$from,
+            'to_uid'=>$to,
+            'is_enable'=>1,
+            'created_at'=>date('Y-m-d H:i:s'),
+            'updated_at'=>date('Y-m-d H:i:s')
+        ]);
     }
 }