Browse Source

店铺新用户--修改查询语句

master
liangyuyan 5 years ago
parent
commit
7fc802ed32
  1. 15
      app/Admin/Common/Type.php
  2. 81
      app/Admin/Repositories/StoreUserReport.php
  3. 2
      app/Models/FinancialRecord0.php
  4. 2
      app/Models/FinancialRecord1.php
  5. 2
      app/Models/FinancialRecord2.php
  6. 2
      app/Models/FinancialRecord3.php
  7. 2
      app/Models/FinancialRecord4.php
  8. 3
      app/Models/StoreAccount.php
  9. 34
      app/Models/v3/Store.php

15
app/Admin/Common/Type.php

@ -7,6 +7,7 @@ namespace App\Admin\Common;
class Type
{
/**
* lanzu_financial_record
* 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项
*/
const MONEY_TYPE_CS_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成)
@ -29,6 +30,20 @@ class Type
const MONEY_TYPE_MM = 103; //市场经理提现类型
const MONEY_TYPE_CS = 104; //社区提现类型
// 账户类型
const USER_TYPE_LEDGER = -1; // 虚拟账户
const USER_TYPE_USER = 1; // user用户
const USER_TYPE_MP = 2; // 服务商 mp用户
const USER_TYPE_MM = 3; // 市场经理 mm用户
const USER_TYPE_CS = 4; // 社区代理点 cs用户
const USER_TYPE_STORE = 5; // 商户 store用户
// 流水关联id类型
const SOURCE_TYPE_NONE = 0; // 无类型
const SOURCE_TYPE_ORDER = 1; // 订单,关联主订单
const SOURCE_TYPE_STORE_WITHDRAW = 2; // 商户提现,关联商户提现表
/**
* lanzu_user_balance 提现类型
*/

81
app/Admin/Repositories/StoreUserReport.php

@ -6,7 +6,14 @@ use App\Models\v3\Store as Model;
use Dcat\Admin\Grid\Model as GridModel;
use Dcat\Admin\Repositories\EloquentRepository;
use App\Models\StoreAccount as StoreAccountModel;
use App\Models\FinancialRecord0 as FinancialRecordModel0;
use App\Models\FinancialRecord1 as FinancialRecordModel1;
use App\Models\FinancialRecord2 as FinancialRecordModel2;
use App\Models\FinancialRecord3 as FinancialRecordModel3;
use App\Models\FinancialRecord4 as FinancialRecordModel4;
use Dcat\Admin\Layout\Row;
use Illuminate\Support\Facades\DB;
use App\Admin\Common\Type;
class StoreUserReport extends EloquentRepository
{
@ -19,21 +26,77 @@ class StoreUserReport extends EloquentRepository
/**
* 获取统计列表数据
* 旧表流水数据未洗到新表,所以统计需要查询旧表和新表数据
*/
public function get(GridModel $model)
{
$this->setSort($model);
$this->setPaginate($model);
/* 根据流水查询 2020-08-18 目前用全匹配文字方式查询新用户 */
$storeAccountModel = new StoreAccountModel();
$query = $storeAccountModel::join('ims_cjdc_store as store','ims_cjdc_store_account.store_id','store.id')
->select('store_id','store.market_id','store.name as store_name',DB::raw("count(distinct ims_cjdc_store_account.id) as new_user_total"))
->whereRaw("note = '新用户下单成功,平台奖励'")
->groupBy('store_id')
->orderBy('store.market_id','desc')
->orderBY('new_user_total','desc')
->orderBY('store_id','desc');
/* 根据流水查询 2020-08-18 用全匹配文字方式查询新用户 旧表 */
// $storeAccountModel = new StoreAccountModel();
// $query = StoreAccountModel::join(Model::$tableName.' as store',StoreAccountModel::$tableName.'.store_id','store.id')
// ->select('store_id','store.market_id','store.name as store_name',DB::raw("count(distinct ".StoreAccountModel::$tableName.".id) as new_user_total"))
// ->whereRaw("note = '新用户下单成功,平台奖励'")
// ->groupBy('store_id')
// ->orderBy('store.market_id','desc')
// ->orderBY('new_user_total','desc')
// ->orderBY('store_id','desc');
// $l = $query->get()->toArray();
// dd($l);
/* 根据流水查询 2020-10-29 用类型字段查询新用户 新表 */
$financial0 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f0.id) as new_user_total'))
->join(FinancialRecordModel0::$tableName.' as f0',Model::$tableName.'.user_id','=','f0.user_id','left')
->whereRaw(Model::$tableName.'.user_id MOD 5 = 0')
->where('user_type',Type::USER_TYPE_STORE)
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
->where('f0.created_at','>','1600444800')
->groupBy('store_id','store_name','market_id');
$financial1 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f1.id) as new_user_total'))
->join(FinancialRecordModel1::$tableName.' as f1',Model::$tableName.'.user_id','=','f1.user_id','left')
->whereRaw(Model::$tableName.'.user_id MOD 5 = 1')
->where('user_type',Type::USER_TYPE_STORE)
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
->where('f1.created_at','>','1600444800')
->groupBy('store_id','store_name','market_id');
$financial2 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f2.id) as new_user_total'))
->join(FinancialRecordModel2::$tableName.' as f2',Model::$tableName.'.user_id','=','f2.user_id','left')
->whereRaw(Model::$tableName.'.user_id MOD 5 = 2')
->where('user_type',Type::USER_TYPE_STORE)
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
->where('f2.created_at','>','1600444800')
->groupBy('store_id','store_name','market_id');
$financial3 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f3.id) as new_user_total'))
->join(FinancialRecordModel3::$tableName.' as f3',Model::$tableName.'.user_id','=','f3.user_id','left')
->whereRaw(Model::$tableName.'.user_id MOD 5 = 3')
->where('user_type',Type::USER_TYPE_STORE)
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
->where('f3.created_at','>','1600444800')
->groupBy('store_id','store_name','market_id');
$financial4 = Model::select(Model::$tableName.'.id as store_id',Model::$tableName.'.name as store_name','market_id',DB::raw('count(distinct f4.id) as new_user_total'))
->join(FinancialRecordModel4::$tableName.' as f4',Model::$tableName.'.user_id','=','f4.user_id','left')
->whereRaw(Model::$tableName.'.user_id MOD 5 = 4')
->where('user_type',Type::USER_TYPE_STORE)
// ->where('source_type',Type::SOURCE_TYPE_ORDER)
// ->where('money_type',Type::MONEY_TYPE_STORE_PLAT_NEW_USER)
->where('f4.created_at','>','1600444800')
->groupBy('store_id','store_name','market_id')
->union($financial0)
->union($financial1)
->union($financial2)
->union($financial3);
$query = $financial4->get()->toArray();
dd($query);
$model->getQueries()->unique()->each(function ($value) use (&$query) {
if ($value['method'] == 'paginate') {

2
app/Models/FinancialRecord0.php

@ -8,4 +8,6 @@ class FinancialRecord0 extends FinancialRecord
{
protected $table = 'lanzu_financial_record_0';
public static $tableName = 'lanzu_financial_record_0';
}

2
app/Models/FinancialRecord1.php

@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class FinancialRecord1 extends FinancialRecord
{
protected $table = 'lanzu_financial_record_1';
public static $tableName = 'lanzu_financial_record_1';
}

2
app/Models/FinancialRecord2.php

@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class FinancialRecord2 extends FinancialRecord
{
protected $table = 'lanzu_financial_record_2';
public static $tableName = 'lanzu_financial_record_2';
}

2
app/Models/FinancialRecord3.php

@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class FinancialRecord3 extends FinancialRecord
{
protected $table = 'lanzu_financial_record_3';
public static $tableName = 'lanzu_financial_record_3';
}

2
app/Models/FinancialRecord4.php

@ -7,4 +7,6 @@ use Illuminate\Database\Eloquent\Model;
class FinancialRecord4 extends FinancialRecord
{
protected $table = 'lanzu_financial_record_4';
public static $tableName = 'lanzu_financial_record_4';
}

3
app/Models/StoreAccount.php

@ -14,6 +14,9 @@ class StoreAccount extends Model
{
use HasDateTimeFormatter;
protected $table = 'ims_cjdc_store_account';
public static $tableName = 'ims_cjdc_store_account';
protected $dateFormat = 'U';
public $timestamps = false;

34
app/Models/v3/Store.php

@ -11,6 +11,8 @@ class Store extends Model
use HasDateTimeFormatter;
use SoftDeletes;
public static $tableName = 'lanzu_store';
protected $table = 'lanzu_store';
protected $dateFormat = 'U';
@ -103,4 +105,36 @@ class Store extends Model
return $value;
}
}
// 关联旧流水
public function storeAccount()
{
return $this->belongsTo('App\Models\v3\StoreAccount','store_id','id','light');
}
// 关联流水
public function financialRecord0()
{
return $this->belongsTo('App\Models\FinancialRecord0','user_id','user_id','light');
}
// 关联流水
public function financialRecord1()
{
return $this->belongsTo('App\Models\FinancialRecord1','user_id','user_id','light');
}
// 关联流水
public function financialRecord2()
{
return $this->belongsTo('App\Models\FinancialRecord2','user_id','user_id','light');
}
// 关联流水
public function financialRecord3()
{
return $this->belongsTo('App\Models\FinancialRecord3','user_id','user_id','light');
}
// 关联流水
public function financialRecord4()
{
return $this->belongsTo('App\Models\FinancialRecord4','user_id','user_id','light');
}
}
Loading…
Cancel
Save