where('status', $status))->sum('extract_price') ?: 0; } public static function extractStatistics() { //待提现金额 $data['price'] = floatval(self::where('status', 0)->sum('extract_price')); //佣金总金额 $data['brokerage_count'] = floatval(SystemStoreBill::getBrokerageCount()); //已提现金额 $data['priced'] = floatval(self::where('status', 1)->sum('extract_price')); //未提现金额 $data['brokerage_not'] = bcsub(bcsub($data['brokerage_count'], $data['priced'], 2), $data['price'], 2); return compact('data'); } /** * @param $where * @return array */ public static function systemPage($where) { $model = new self; if ($where['date'] != '') { list($startTime, $endTime) = explode(' - ', $where['date']); $model = $model->where('a.add_time', '>', strtotime($startTime)); $model = $model->where('a.add_time', '<', (int)bcadd(strtotime($endTime), 86400, 0)); } if ($where['status'] != '') $model = $model->where('a.status', $where['status']); if ($where['extract_type'] != '') $model = $model->where('a.extract_type', $where['extract_type']); if ($where['nireid'] != '') $model = $model->where('a.real_name|a.id|b.name|a.bank_code|a.alipay_code', 'like', "%$where[nireid]%"); $model = $model->alias('a'); $model = $model->field('a.*,b.name'); $model = $model->join('system_store b', 'b.id=a.store_id', 'LEFT'); $model = $model->order('a.id desc'); return self::page($model, $where); } public static function changeFail($id, $fail_msg) { $fail_time = time(); $data = self::get($id); $extract_number = $data['extract_price']; $mark = '提现失败,退回佣金' . $extract_number . '元'; $uid = $data['store_id']; $status = -1; $User = SystemStore::where('id', $uid)->find()->toArray(); SystemStoreBill::income('提现失败', $uid, 'brokerage_price', 'extract', $extract_number, $id, bcadd($User['brokerage_price'], $extract_number, 2), $mark); SystemStore::bcInc($uid, 'brokerage_price', $extract_number, 'id'); return self::edit(compact('fail_time', 'fail_msg', 'status'), $id); } public static function changeSuccess($id) { return self::edit(['status' => 1], $id); } public static function userExtract($userInfo, $data) { if (!in_array($data['extract_type'], self::$extractType)) return self::setErrorInfo('提现方式不存在'); $userInfo = SystemStore::get($userInfo['id']); $extractPrice = $userInfo['brokerage_price']; if ($extractPrice < 0) return self::setErrorInfo('提现佣金不足' . $data['money']); if ($data['money'] > $extractPrice) return self::setErrorInfo('提现佣金不足' . $data['money']); if ($data['money'] <= 0) return self::setErrorInfo('提现佣金大于0'); $balance = bcsub($userInfo['brokerage_price'], $data['money'], 2); if ($balance < 0) $balance = 0; $insertData = [ 'store_id' => $userInfo['id'], 'extract_type' => $data['extract_type'], 'extract_price' => $data['money'], 'add_time' => time(), 'balance' => $balance, 'status' => 0 ]; if (isset($data['name']) && strlen(trim($data['name']))) $insertData['real_name'] = $data['name']; else $insertData['real_name'] = $userInfo['name']; if (isset($data['cardnum'])) $insertData['bank_code'] = $data['cardnum']; else $insertData['bank_code'] = ''; if (isset($data['bankname'])) $insertData['bank_address'] = $data['bankname']; else $insertData['bank_address'] = ''; if (isset($data['weixin'])) $insertData['wechat'] = $data['weixin']; else $insertData['wechat'] = $userInfo['name']; if ($data['extract_type'] == 'alipay') { if (!$data['alipay_code']) return self::setErrorInfo('请输入支付宝账号'); $insertData['alipay_code'] = $data['alipay_code']; $mark = '使用支付宝提现' . $insertData['extract_price'] . '元'; } else if ($data['extract_type'] == 'bank') { if (!$data['cardnum']) return self::setErrorInfo('请输入银行卡账号'); if (!$data['bankname']) return self::setErrorInfo('请输入开户行信息'); $mark = '使用银联卡' . $insertData['bank_code'] . '提现' . $insertData['extract_price'] . '元'; } else if ($data['extract_type'] == 'weixin') { if (!$data['weixin']) return self::setErrorInfo('请输入微信账号'); $mark = '使用微信提现' . $insertData['extract_price'] . '元'; } self::beginTrans(); try { $res1 = self::create($insertData); if (!$res1) return self::setErrorInfo('提现失败'); $res2 = SystemStore::edit(['brokerage_price' => $balance], $userInfo['id'], 'id'); $res3 = SystemStoreBill::expend('佣金提现', $userInfo['id'], 'brokerage_price', 'extract', $data['money'], $res1['id'], $balance, $mark ?? ''); $res = $res2 && $res3; if ($res) { self::commitTrans(); return true; } else return self::setErrorInfo('提现失败!'); } catch (\Exception $e) { self::rollbackTrans(); return self::setErrorInfo('提现失败!'); } } //获取头部提现信息 public static function getExtractHead() { //本月提现人数 $month = self::getModelTime(['data' => 'month'], self::where('status', 1))->group('store_id')->count(); //本月提现笔数 $new_month = self::getModelTime(['data' => 'month'], self::where('status', 1))->distinct(true)->count(); //上月提现人数 $last_month = self::whereTime('add_time', 'last month')->where('status', 1)->group('store_id')->distinct(true)->count(); //上月提现笔数 $last_count = self::whereTime('add_time', 'last month')->where('status', 1)->count(); //本月提现金额 $extract_price = self::getModelTime(['data' => 'month'], self::where('status', 1))->sum('extract_price'); //上月提现金额 $last_extract_price = self::whereTime('add_time', 'last month')->where('status', 1)->sum('extract_price'); return [ [ 'name' => '总提现店铺数', 'field' => '个', 'count' => self::where('status', 1)->group('store_id')->count(), 'content' => '', 'background_color' => 'layui-bg-blue', 'sum' => '', 'class' => 'fa fa-bar-chart', ], [ 'name' => '总提现笔数', 'field' => '笔', 'count' => self::where('status', 1)->distinct(true)->count(), 'content' => '', 'background_color' => 'layui-bg-cyan', 'sum' => '', 'class' => 'fa fa-line-chart', ], [ 'name' => '本月提现店铺数', 'field' => '人', 'count' => $month, 'content' => '', 'background_color' => 'layui-bg-orange', 'sum' => '', 'class' => 'fa fa-line-chart', ], [ 'name' => '本月提现笔数', 'field' => '笔', 'count' => $new_month, 'content' => '', 'background_color' => 'layui-bg-green', 'sum' => '', 'class' => 'fa fa-line-chart', ], [ 'name' => '本月提现金额', 'field' => '元', 'count' => $extract_price, 'content' => '提现总金额', 'background_color' => 'layui-bg-cyan', 'sum' => self::where('status', 1)->sum('extract_price'), 'class' => 'fa fa-line-chart', ], [ 'name' => '上月提现店铺数', 'field' => '个', 'count' => $last_month, 'content' => '环比增幅', 'background_color' => 'layui-bg-blue', 'sum' => $last_month == 0 ? '100%' : bcdiv($month, $last_month, 2) * 100, 'class' => $last_month == 0 ? 'fa fa-level-up' : 'fa fa-level-down', ], [ 'name' => '上月提现笔数', 'field' => '笔', 'count' => $last_count, 'content' => '环比增幅', 'background_color' => 'layui-bg-black', 'sum' => $last_count == 0 ? '100%' : bcdiv($new_month, $last_count, 2) * 100, 'class' => $last_count == 0 ? 'fa fa-level-up' : 'fa fa-level-down', ], [ 'name' => '上月提现金额', 'field' => '元', 'count' => $last_extract_price, 'content' => '环比增幅', 'background_color' => 'layui-bg-gray', 'sum' => $last_extract_price == 0 ? '100%' : bcdiv($extract_price, $last_extract_price, 2) * 100, 'class' => $last_extract_price == 0 ? 'fa fa-level-up' : 'fa fa-level-down', ], ]; } //获取提现分布图和提现人数金额曲线图 public static function getExtractList($where, $limit = 15) { $legdata = ['提现店铺数', '提现金额']; $list = self::getModelTime($where, self::where('status', 1)) ->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(store_id) as count,sum(extract_price) as sum_price')->group('un_time')->order('un_time asc')->select(); if (count($list)) $list = $list->toArray(); $xdata = []; $itemList = [0 => [], 1 => []]; $chatrList = []; $zoom = ''; foreach ($list as $value) { $xdata[] = $value['un_time']; $itemList[0][] = $value['count']; $itemList[1][] = $value['sum_price']; } foreach ($legdata as $key => $name) { $item['name'] = $name; $item['type'] = 'line'; $item['data'] = $itemList[$key]; $chatrList[] = $item; } unset($item, $name, $key); if (count($xdata) > $limit) $zoom = $xdata[$limit - 5]; //饼状图 $cake = ['支付宝', '银行卡', '微信']; $fenbulist = self::getModelTime($where, self::where('status', 1)) ->field('count(store_id) as count,extract_type')->group('extract_type')->order('count asc')->select(); if (count($fenbulist)) $fenbulist = $fenbulist->toArray(); $sum_count = self::getModelTime($where, self::where('status', 1))->count(); $color = ['#FB7773', '#81BCFE', '#91F3FE']; $fenbudata = []; foreach ($fenbulist as $key => $item) { if ($item['extract_type'] == 'bank') { $item_date['name'] = '银行卡'; } else if ($item['extract_type'] == 'alipay') { $item_date['name'] = '支付宝'; } else if ($item['extract_type'] == 'weixin') { $item_date['name'] = '微信'; } $item_date['value'] = bcdiv($item['count'], $sum_count, 2) * 100; $item_date['itemStyle']['color'] = $color[$key]; $fenbudata[] = $item_date; } return compact('xdata', 'chatrList', 'legdata', 'zoom', 'cake', 'fenbudata'); } /** * 获取用户累计提现金额 * @param int $uid * @return int|mixed */ public static function getUserCountPrice($uid = 0) { if (!$uid) return 0; $price = self::where('store_id', $uid)->where('status', 1)->sum('extract_price'); return $price ? $price : 0; } /** * 获取用户累计提现次数 * @param int $uid * @return int|string */ public static function getUserCountNum($uid = 0) { if (!$uid) return 0; return self::where('store_id', $uid)->count(); } }