123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <?php
- namespace app\admin\model\system;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use think\facade\Db;
- /**
- * 店铺消费新增金额明细 model
- * Class User
- * @package app\admin\model\user
- */
- class SystemStoreBill extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'system_store_bill';
- use ModelTrait;
- /*
- * 获取总佣金
- * */
- public static function getBrokerage($uid, $category = 'brokerage_price', $type = '', $where = [])
- {
- $model = self::where('store_id', 'in', $uid)->where('category', $category)
- ->where('pm', 1)->where('status', 1);
- if ($type) $model = $model->where('type', $type);
- return self::getModelTime($where, $model)->sum('number');
- }
- //修改积分减少积分记录
- public static function expend($title, $store_id, $category, $type, $number, $link_id = 0, $balance = 0, $mark = '', $status = 1)
- {
- $pm = 0;
- $add_time = time();
- return self::create(compact('title', 'store_id', 'link_id', 'category', 'type', 'number', 'balance', 'mark', 'status', 'pm', 'add_time'));
- }
- //修改积分增加积分记录
- public static function income($title, $store_id, $category, $type, $number, $link_id = 0, $balance = 0, $mark = '', $status = 1)
- {
- $pm = 1;
- $add_time = time();
- return self::create(compact('title', 'store_id', 'link_id', 'category', 'type', 'number', 'balance', 'mark', 'status', 'pm', 'add_time'));
- }
- public static function getList($where, $store_id)
- {
- $model = self::where('store_id', $store_id);
- if (isset($where['time']) && $where['time'] != '') {
- $start_time = strtotime($where['time']);
- $end_time = strtotime('+1month', strtotime($where['time']));
- $model = $model->where('add_time', 'between', [$start_time, $end_time]);
- }
- if (isset($where['type']) && $where['type'] != '') {
- $model = $model->where('type', $where['type']);
- }
- $count = $model->count();
- $data = $model->order('add_time', 'desc')->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
- $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
- $item['_status'] = ($item['status'] == 1 ? '已结算' : ($item['status'] == 2 ? '已失效' : '待结算'));
- });
- return compact('count', 'data');
- }
- //获取柱状图和饼状图数据
- public static function getUserBillChart($where, $category = 'now_money', $type = 'brokerage', $pm = 1, $zoom = 15)
- {
- $model = self::getModelTime($where, new self());
- $list = $model->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,sum(number) as sum_number')
- ->order('un_time asc')
- ->where('category', $category)
- ->where('type', $type)
- ->where('pm', $pm)
- ->group('un_time')
- ->select();
- if (count($list)) $list = $list->toArray();
- $legdata = [];
- $listdata = [];
- $dataZoom = '';
- foreach ($list as $item) {
- $legdata[] = $item['un_time'];
- $listdata[] = $item['sum_number'];
- }
- if (count($legdata) >= $zoom) $dataZoom = $legdata[$zoom - 1];
- //获取用户分布钱数
- $fenbulist = self::getModelTime($where, new self(), 'a.add_time')
- ->alias('a')
- ->join('system_store r', 'a.store_id=r.id')
- ->field('a.store_id,sum(a.number) as sum_number,r.name')
- ->where('a.category', $category)
- ->where('a.type', $type)
- ->where('a.pm', $pm)
- ->order('sum_number desc')
- ->group('a.store_id')
- ->limit(8)
- ->select();
- //获取用户当前时间段总钱数
- $sum_number = self::getModelTime($where, new self())
- ->alias('a')
- ->where('a.category', $category)
- ->where('a.type', $type)
- ->where('a.pm', $pm)
- ->sum('number');
- if (count($fenbulist)) $fenbulist = $fenbulist->toArray();
- $fenbudate = [];
- $fenbu_legend = [];
- $color = ['#ffcccc', '#99cc00', '#fd99cc', '#669966', '#66CDAA', '#ADFF2F', '#00BFFF', '#00CED1', '#66cccc', '#ff9900', '#ffcc00', '#336699', '#cccc00', '#99ccff', '#990066'];
- foreach ($fenbulist as $key => $value) {
- $fenbu_legend[] = $value['nickname'];
- $items['name'] = $value['nickname'];
- $items['value'] = bcdiv($value['sum_number'], $sum_number, 2) * 100;
- $items['itemStyle']['color'] = $color[$key];
- $fenbudate[] = $items;
- }
- return compact('legdata', 'listdata', 'fenbudate', 'fenbu_legend', 'dataZoom');
- }
- //获取头部信息
- public static function getRebateBadge($where)
- {
- $datawhere = ['category' => 'now_money', 'type' => 'brokerage', 'pm' => 1];
- return [
- [
- 'name' => '返利数(笔)',
- 'field' => '个',
- 'count' => self::getModelTime($where, new self())->where($datawhere)->count(),
- 'content' => '返利总笔数',
- 'background_color' => 'layui-bg-blue',
- 'sum' => self::where($datawhere)->count(),
- 'class' => 'fa fa-bar-chart',
- ],
- [
- 'name' => '返利金额(元)',
- 'field' => '个',
- 'count' => self::getModelTime($where, new self())->where($datawhere)->sum('number'),
- 'content' => '返利总金额',
- 'background_color' => 'layui-bg-cyan',
- 'sum' => self::where($datawhere)->sum('number'),
- 'class' => 'fa fa-line-chart',
- ],
- ];
- }
- //获取返佣用户信息列表
- public static function getFanList($where)
- {
- $list = self::alias('a')->join('system_store r', 'a.store_id=r.id')
- ->where('a.category', 'now_money')
- ->where('a.type', 'brokerage')
- ->where('a.pm', 1)
- ->order('a.number desc')
- ->join('store_order o', 'o.id=a.link_id')
- ->field('o.order_id,FROM_UNIXTIME(a.add_time,"%Y-%c-%d") as add_time,a.store_id,o.uid as down_uid,r.name,r.image,a.number')
- ->page((int)$where['page'], (int)$where['limit'])
- ->select();
- if (count($list)) $list = $list->toArray();
- return $list;
- }
- //获取返佣用户总人数
- public static function getFanCount()
- {
- return self::alias('a')->join('system_store r', 'a.store_id=r.id')->join('store_order o', 'o.id=a.link_id')->where('a.category', 'now_money')->where('a.type', 'brokerage')->where('a.pm', 1)->count();
- }
- //获取佣金提现列表
- public static function getExtrctOneList($where, $uid)
- {
- $list = self::setOneWhere($where, $uid)
- ->field('number,link_id,mark,FROM_UNIXTIME(add_time,"%Y-%m-%d %H:%i:%s") as _add_time,status')
- ->select();
- count($list) && $list = $list->toArray();
- $count = self::setOneWhere($where, $uid)->count();
- foreach ($list as &$value) {
- $value['order_id'] = Db::name('store_order')->where('order_id', $value['link_id'])->value('order_id');
- }
- return ['data' => $list, 'count' => $count];
- }
- //设置单个用户查询
- public static function setOneWhere($where, $uid)
- {
- $model = self::where('store_id', $uid)->where('category', 'now_money')->where('type', 'brokerage');
- $time['data'] = '';
- if (strlen(trim($where['start_time'])) && strlen(trim($where['end_time']))) {
- $time['data'] = $where['start_time'] . ' - ' . $where['end_time'];
- $model = self::getModelTime($time, $model);
- }
- if (strlen(trim($where['nickname']))) {
- $model = $model->where('link_id|mark', 'like', "%$where[nickname]%");
- }
- return $model;
- }
- //查询个人余额变动记录
- public static function getOneBalanceChangList($where)
- {
- $list = self::setWhereList(
- $where, '',
- // ['system_add','pay_product','extract','pay_product_refund','system_sub','brokerage','recharge','user_recharge_refund'],
- ['FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time', 'title', 'type', 'mark', 'number', 'balance', 'pm', 'status'],
- 'now_money'
- );
- foreach ($list as &$item) {
- switch ($item['type']) {
- case 'extract':
- $item['_type'] = '提现';
- break;
- case 'brokerage':
- $item['_type'] = '系统返佣';
- break;
- }
- $item['_pm'] = $item['pm'] == 1 ? '获得' : '支出';
- }
- return $list;
- }
- //设置where条件分页.返回数据
- public static function setWhereList($where, $type = '', $field = [], $category = 'integral')
- {
- $models = self::where('store_id', $where['store_id'])
- ->where('category', $category)
- ->page((int)$where['page'], (int)$where['limit'])
- ->order('id', 'desc')
- ->field($field);
- if (is_array($type)) {
- $models = $models->where('type', 'in', $type);
- } else {
- if (!empty($type)) $models = $models->where('type', $type);
- }
- return ($list = $models->select()) && count($list) ? $list->toArray() : [];
- }
- /**
- * 用户获得总佣金
- * @return float
- */
- public static function getBrokerageCount()
- {
- return self::where('type', 'brokerage')->where('category', 'now_money')->where('status', 1)->where('pm', 1)->sum('number');
- }
- }
|