| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\constants\OptionSetting;
- use app\models\Cash;
- use app\models\CashExt;
- use app\models\IntegralAppreciationCashLog;
- use app\models\Mch;
- use app\models\Option;
- use app\models\Share;
- use app\models\User;
- use app\models\SaasUser;
- use app\utils\Export;
- use app\utils\ExportList;
- use yii\base\Model;
- /**
- * Undocumented class
- *
- * @Author LGL 24963@qq.com
- * @DateTime 2021-01-14
- * @desc: 提现表操作
- */
- class CashForm extends Model
- {
- public $export;
- public $id;
- public $store_id;
- public $user_id;
- public $saas_id;
- public $price;
- public $status;
- public $is_delete;
- public $pay_time;
- public $type;
- public $mobile;
- public $name;
- public $bank_name;
- public $pay_type;
- public $order_no;
- public $service_charge;
- public $cash_type;
- //搜索
- public $search_key;
- public $search_is_show;
- public $key;
- public $action;//操作状态:1、微信打款,2、线下打款,3、驳回,4、确认申请
- public $dateStart;
- public $dateEnd;
- public $keyword;
- public $mch;
- public $mch_id;
- public $mch_common_cat_id;
- public $flag;
- public $fields;
- public $brands_id = 0;
- const SCENARIO_ADD = 'add';
- const SCENARIO_EDIT = 'edit';
- const SCENARIO_DEL = 'del';
- const SCENARIO_LIST = 'list';
- const SCENARIO_ACTION = 'action';
- const STATUS_TEXT = [
- Cash::STATUS_APPLY => '待审核',
- Cash::STATUS_CONFIRM => '待打款',
- Cash::STATUS_GIVEN => '已打款',
- Cash::STATUS_REFUSE => '驳回',
- Cash::STATUS_RECHARGE => '余额通过',
- ];
- const TYPE_TEXT = [
- Cash::TYPE_WX => '微信',
- Cash::TYPE_ALIPAY => '支付宝',
- Cash::TYPE_BANK => '银行卡',
- Cash::TYPE_RECHARGE => '余额'
- ];
- const PAY_TYPE_TEXT = [
- Cash::PAY_TYPE_NO => '未统计',
- Cash::PAY_TYPE_WX => '微信自动打款',
- Cash::PAY_TYPE_HAND => '手动拨款'
- ];
- const CAHS_TYPE = [
- Cash::IS_CASH_TYPE_SHARE => '非自提点',
- Cash::IS_CASH_TYPE_SHOP => '自提点'
- ];
- public $pay_wechat;
- public $pay_alipay;
- public $bank;
- public $lg;
- public $remaining_sum;
- public $cash_service_charge;
- public $min_money;
- public $cash_max_single_day;
- public $cash_max_day;
- public $cash_price_type;
- public $cash_price_amount;
- public $cash_price_balance;
- public $cash_price_integral;
- public $auto_money;
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['id', 'user_id', 'saas_id','store_id', 'status', 'is_delete', 'pay_time', 'type', 'pay_type', 'cash_type', 'brands_id'], 'integer'],
- [['price', 'service_charge'], 'number'],
- [['keyword', 'flag'], 'trim'],
- [['mobile', 'name', 'order_no', 'keyword', 'dateStart', 'dateEnd', 'cash_price_type'], 'string', 'max' => 255],
- [['bank_name', 'flag'], 'string', 'max' => 30],
- ['is_delete', 'default', 'value'=> Cash::IS_DELETE_NO],
- ['type', 'default', 'value'=> Cash::TYPE_WX],
- ['status', 'default', 'value'=> Cash::STATUS_APPLY],
- ['pay_type', 'default', 'value'=> Cash::PAY_TYPE_NO],
- ['cash_type', 'default', 'value'=> Cash::IS_CASH_TYPE_SHARE],
- [['fields'], 'safe'],
- // 操作
- [['name', 'pic_url', 'total_num', 'expire_day', 'money', 'price', 'sort'],'required', 'on'=> [self::SCENARIO_ADD, self::SCENARIO_EDIT]],
- // [['id'],'required', 'on'=> [self::SCENARIO_DEL, self::SCENARIO_EDIT]],
- [['key', 'action'], 'required', 'on'=> self::SCENARIO_ACTION],
- ['search_key', 'string', 'on' => self::SCENARIO_LIST],
- [['mch', 'mch_id', 'mch_common_cat_id'], 'safe'],
- [['export'], 'safe'],
- [['pay_alipay', 'pay_wechat', 'bank', 'remaining_sum', 'lg'], 'in', 'range' => [0, 1]],
- [['cash_service_charge', 'min_money', 'cash_max_single_day', 'cash_max_day', 'cash_price_amount', 'cash_price_balance', 'cash_price_integral', 'auto_money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => '用户id',
- 'store_id' => '商城id',
- 'price' => '提现金额',
- 'status' => '申请状态 0--申请中 1--确认申请 2--已打款 3--驳回 5--余额通过',
- 'is_delete' => '是否删除',
- 'pay_time' => '付款',
- 'type' => '支付方式 0--微信支付 1--支付宝 2--银行卡 3--余额',
- 'mobile' => '支付宝账号',
- 'name' => '支付宝姓名',
- 'bank_name' => '开户行名称',
- 'pay_type' => '打款方式 0--之前未统计的 1--微信自动打款 2--手动打款',
- 'order_no' => '微信自动打款订单号',
- 'service_charge' => '提现手续费',
- 'cash_type' => '0、正常,1、自提点提现',
- ];
- }
- public function scenarios()
- {
- $scenarios = parent::scenarios();
- return $scenarios;
- }
- public function saveCash()
- {
- if ($this->validate()) {
- $t = \Yii::$app->db->beginTransaction();
- if ($this->scenario == self::SCENARIO_EDIT) {
- $model = Cash::findOne(['id' => $this->id]);
- } else {
- $model = new Cash();
- }
- $model->attributes = $this->attributes;
- if (!$model->save()) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => $model->getErrorSummary(false)[0]
- ];
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- } else {
- // 验证失败:$errors 是一个包含错误信息的数组
- return [
- 'code' => 1,
- "msg" => $this->getErrorSummary(false)[0]
- ];
- }
- }
- public function searchShopCash()
- {
- $query = Cash::find()->alias('c')
- ->leftJoin(['u' => User::tableName()], "u.id=c.user_id")
- ->select("c.*, u.nickname user_name, u.avatar_url user_head_url");
- $query->where(['c.is_delete' => Cash::IS_DELETE_NO, 'cash_type' => Cash::IS_CASH_TYPE_SHOP])->orderBy("id desc");
- // 搜索
- if ($this->search_key) {
- $query->andWhere([
- 'or',
- ['like', 'u.nickname', $this->search_key],
- ['like', 'c.name', $this->search_key]
- ]);
- }
- if ($this->status == 0 and $this->status != '') {//待审核
- $query->andWhere(['c.status' => 0]);
- }
- if ($this->status == 1) {//待打款
- $query->andWhere(['c.status' => 1]);
- }
- if ($this->status == 2) {//已打款
- $query->andWhere(['in', 'c.status', [2, 5]]);
- }
- if ($this->status == 3) {//无效
- $query->andWhere(['c.status' => 3]);
- }
- if ($this->flag == Export::EXPORT) {
- $export = new ExportList();
- $data = $query->orderBy('c.status ASC,c.created_at DESC')->select(['c.*', 'u.nickname', 'u.avatar_url','u.platform', 'u.id user_id'])->asArray()->all();
- $export->shareExportData($data, $this->fields);
- }
- $list = pagination_make($query);
- foreach ($list['list'] as &$val) {
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- $val['status_text'] = self::STATUS_TEXT[$val['status']];
- $val['type_text'] = self::TYPE_TEXT[$val['type']];
- $val['pay_type_text'] = self::PAY_TYPE_TEXT[$val['pay_type']];
- // $val['is_shop_text'] = self::CAHS_TYPE[$val['is_shop']];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'export_list' => $this->getCustomField(),
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount']
- ]
- ];
- }
- public function delCash()
- {
- if ($this->validate()) {
- $t = \Yii::$app->db->beginTransaction();
- if ($this->scenario !== self::SCENARIO_DEL) {
- return [
- 'code' => 1,
- 'msg' => '删除失败'
- ];
- }
- $model = Cash::findOne(['id' => $this->key]);
- $model->is_delete = Cash::IS_DELETE_YES;
- if (!$model || !$model->save()) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => $model->getErrorSummary(false)[0]
- ];
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '删除成功'
- ];
- // 所有输入数据都有效 all inputs are valid
- } else {
- // 验证失败:$errors 是一个包含错误信息的数组
- return [
- 'code' => 1,
- "msg" => $this->getErrorSummary(false)[0]
- ];
- }
- }
- /**
- * 获取分销提现列表
- * @return array
- */
- public function getShareCashList()
- {
- $query = Cash::find()->alias('c')
- ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $this->store_id])
- ->leftJoin('{{%user}} u', 'u.id=c.user_id');
- if ($this->cash_type == Cash::IS_CASH_TYPE_SHARE) {
- $query->leftJoin('{{%share}} s', 's.user_id=c.user_id');
- $query->andWhere(['s.is_delete' => Share::SHARE_NOT_DELETE, 'u.is_distributor' => User::IS_DISTRIBUTOR]);
- }
- $query->andWhere(['c.cash_type' => $this->cash_type ? $this->cash_type : Cash::IS_CASH_TYPE_SHARE]);
- if ($this->keyword) {
- if ($this->cash_type == Cash::IS_CASH_TYPE_SHARE) {
- $query->andWhere([
- 'or',
- ['like', 'u.nickname', $this->keyword],
- ['like', 's.name', $this->keyword]
- ]);
- } else {
- $query->andWhere(['like', 'u.nickname', $this->keyword]);
- }
- }
- if (isset($this->mch) && $this->mch == 1) {
- if ($this->mch_id > 0) {
- $query->andWhere(['c.mch_id' => $this->mch_id]);
- }else{
- $query->andWhere(['>', 'c.mch_id', 0]);
- }
- if($this->brands_id > 0){
- $mchList = Mch::find()->where(['is_delete' => 0, 'store_id' => get_store_id(), 'brands_id' => $this->brands_id])->select('id')->column();
- $query->andWhere(['c.mch_id' => $mchList]);
- }
- if (isset($this->mch_common_cat_id) && $this->mch_common_cat_id > 0) {
- $query->andWhere(['c.mch_id' => \app\models\Mch::find()->select('id')->where(['store_id' => $this->store_id, 'mch_common_cat_id' => $this->mch_common_cat_id])]);
- }
- }else{
- $query->andWhere(['c.mch_id' => 0]);
- }
- if ($this->dateStart) {
- $query->andWhere(['>=', 'c.created_at', strtotime($this->dateStart)]);
- }
- if ($this->dateEnd) {
- $query->andWhere(['<=', 'c.created_at', strtotime($this->dateEnd)]);
- }
- if ($this->status == Cash::STATUS_APPLY and $this->status != '') {//待审核
- $query->andWhere(['c.status' => Cash::STATUS_APPLY]);
- }
- if ($this->status == Cash::STATUS_CONFIRM) {//待打款
- // $query->andWhere(['c.status' => Cash::STATUS_CONFIRM]);
- $query->andWhere(['in', 'c.status', [Cash::STATUS_CONFIRM, Cash::STATUS_LG_CONFIRM]]);
- }
- if ($this->status == Cash::STATUS_GIVEN) {//已打款
- $query->andWhere(['in', 'c.status', [Cash::STATUS_GIVEN, Cash::STATUS_HAND, Cash::STATUS_RECHARGE]]);
- }
- if ($this->status == Cash::STATUS_REFUSE) {//无效
- $query->andWhere(['c.status' => Cash::STATUS_REFUSE]);
- }
- if ($this->id) {
- $query->andWhere(['s.id' => $this->id]);
- }
- if (isset($this->type) && $this->type > -1) {
- $query->andWhere(['c.type' => $this->type]);
- }
- if ($this->flag == Export::EXPORT) {
- $export = new ExportList();
- $data = $query->orderBy('id DESC')
- ->select(['c.*', 'u.nickname', 'u.avatar_url','u.platform', 'u.id user_id'])->asArray()->all();
- $export->shareExportData($data, $this->fields);
- }
- $query->distinct()->orderBy('id DESC')->select([
- 'c.*', 'u.nickname','u.platform', 'u.avatar_url','u.binding'
- ]);
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- if($this->cash_type == Cash::IS_CASH_TYPE_MCH){
- $mchList = (new MchForm(['store_id' => $this->store_id]))->mchSelectList();
- $mchCommonCatSelectList = (new MchForm(['store_id' => $this->store_id]))->mchCommonCatSelectList();
- }
- $wechat = \Yii::$app->controller->wechatPay;
- try {
- $Wxv3 = (new \app\utils\WechatMerchant\WxV3($wechat));
- } catch (\Exception $e) {
- $Wxv3 = null;
- }
- foreach($list as &$value){
- // if (intval($value['pay_type']) === 1) {
- // \app\events\OrderEvent::handleWechatCashFail($Wxv3, $this->store_id, $value['order_no']);
- // }
- $value['wx_cash_status'] = intval($value['wx_cash_status']);
- $value['type_name'] = Cash::getTypeName($value);
- $value['status_name'] = Cash::getCashStatusName($value);
- $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : '';
- $value['money'] = Cash::getServiceMoney($value);
- $saas_user = SaasUser::findOne(['mobile' => $value['binding']]);
- $value['avatar_url'] = !empty($saas_user['avatar']) ? $saas_user['avatar'] : $value['avatar_url'];
- $value['card_no'] = '';
- if (intval($value['type']) === Cash::TYPE_BANK) {
- if ($saas_user->withdraw_method) {
- $withdraw_method = json_decode($saas_user->withdraw_method, true);
- if (!empty($withdraw_method)) {
- foreach ($withdraw_method as $method_item) {
- if ($method_item['type'] === 'bank_card') {
- $value['card_no'] = $method_item['card_no'];
- }
- }
- }
- }
- }
- if($this->cash_type == Cash::IS_CASH_TYPE_MCH){
- $value['mch'] = $mchList['data'][$value['mch_id']];
- $value['mch_common_cat'] = $mchCommonCatSelectList['data'][$value['mch']['mch_common_cat_id']];
- }
- $cashExtArr = CashExt::find()->where(['cash_id' => $value['id']])->select('cash_price_type, real_price')->asArray()->all();
- $value['cash_ext_text'] = null;
- if ($cashExtArr) {
- $value['cash_ext_text'] = '提现明细:';
- foreach ($cashExtArr as $cashExtItem) {
- $value['cash_ext_text'] .= CashExt::$cashPriceTypeMap[$cashExtItem['cash_price_type']] . ':' . $cashExtItem['real_price'] . ';';
- }
- }
- $value['integral_appreciation_num'] = 0;
- $value['integral_appreciation_price'] = 0;
- if (intval($value['cash_type']) === Cash::IS_CASH_TYPE_INTEGRAL_APPRECIATION) {
- $integralCashLog = IntegralAppreciationCashLog::findOne(['cash_id' => $value['id']]);
- $value['integral_appreciation_num'] = $integralCashLog->integral ?: 0;
- $value['integral_appreciation_price'] = $integralCashLog->integral_price ?: 0;
- }
- }
- if($this->export){
- return $this->export($list);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'q' => $query->createCommand()->getRawSql(),
- 'export_list' => $this->getCustomField(),
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ];
- }
- private function export($list) {
- $rows = [[
- 'ID',
- '入驻商',
- '会员信息',
- '手机号',
- '申请提现金额(元)',
- '手续费(元)',
- '实际打款(元)',
- '姓名',
- '提现到',
- '账户',
- '开户行',
- '状态',
- '申请时间',
- '审核时间',
- ]];
- foreach($list as $item){
- $r = [
- $item['id'],
- $item['mch'] ? $item['mch']['name'] : '',
- $item['nickname'],
- $item['binding'],
- $item['price'],
- $item['service_money'],
- $item['money'],
- $item['name'],
- Cash::$type[$item['type']] ?? '--',
- $item['mobile'],
- $item['bank_name'],
- Cash::$status[$item['status']] ?? '',
- $item['created_at'],
- $item['updated_at'],
- ];
- $rows[] = $r;
- }
- $writer = \Spatie\SimpleExcel\SimpleExcelWriter::streamDownload(time() . '.xlsx')->noHeaderRow()
- ->addRows($rows)->toBrowser();
- }
- /**
- * 用户分销提现列表
- */
- public function shareCashUserList() {
- if ($this->user_id) {
- $query = Cash::find()->alias('c')
- ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $this->store_id, 'c.user_id' => $this->user_id])
- ->leftJoin('{{%user}} u', 'u.id=c.user_id')
- ->leftJoin('{{%share}} s', 's.user_id=c.user_id')
- ->andWhere(['s.is_delete' => Share::SHARE_NOT_DELETE, 'u.is_distributor' => User::IS_DISTRIBUTOR,
- 'c.cash_type' => Cash::IS_CASH_TYPE_SHARE]);
- $query->distinct()->orderBy('c.status ASC,c.created_at DESC')->select([
- 'c.*', 'u.nickname','u.platform', 'u.avatar_url','u.binding'
- ]);
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$value){
- $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : '';
- $value['money'] = Cash::getServiceMoney($value);
- $sassuser = SaasUser::findOne(['mobile' => $value['binding']]);
- $value['avatar_url'] = !empty($sassuser['avatar']) ? $sassuser['avatar'] : $value['avatar_url'];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'export_list' => $this->getCustomField(),
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ];
- } else {
- return [
- 'code' => 0,
- 'msg' => '缺少参数',
- ];
- }
- }
- /**
- * saas用户分销提现列表
- */
- public function shareCashSaasList() {
- $query = Cash::find()->alias('c')
- ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $this->store_id])
- ->leftJoin('{{%saas_user}} s', 's.id=c.saas_id')
- ->andWhere(['c.cash_type' => Cash::IS_CASH_TYPE_SHARE]);
- $query->distinct()->orderBy('c.status ASC,c.created_at DESC')->select([
- 'c.*','s.name saas_name','s.avatar avatar_url','s.mobile telphone'
- ]);
- if ($this->keyword) {
- $query->andWhere([
- 'or',
- ['like', 's.name', $this->keyword]
- ]);
- }
- if ($this->dateStart) {
- $query->andWhere(['>=', 'c.created_at', strtotime($this->dateStart)]);
- }
- if ($this->dateEnd) {
- $query->andWhere(['<=', 'c.created_at', strtotime($this->dateEnd)]);
- }
- if ($this->status == Cash::STATUS_APPLY and $this->status != '') {//待审核
- $query->andWhere(['c.status' => Cash::STATUS_APPLY]);
- }
- if ($this->status == Cash::STATUS_CONFIRM) {//待打款
- $query->andWhere(['c.status' => Cash::STATUS_CONFIRM]);
- }
- if ($this->status == Cash::STATUS_GIVEN) {//已打款
- $query->andWhere(['in', 'c.status', [Cash::STATUS_GIVEN, Cash::STATUS_RECHARGE]]);
- }
- if ($this->status == Cash::STATUS_REFUSE) {//无效
- $query->andWhere(['c.status' => Cash::STATUS_REFUSE]);
- }
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$value){
- $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : '';
- $value['money'] = Cash::getServiceMoney($value);
- //$sassuser = SaasUser::findOne(['mobile' => $value['binding']]);
- //$value['avatar_url'] = !empty($sassuser['avatar']) ? $sassuser['avatar'] : $value['avatar_url'];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'export_list' => $this->getCustomField(),
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ];
- }
- public function getCustomField()
- {
- return [
- [
- 'key' => 'order_no',
- 'value' => '订单号'
- ],
- [
- 'key' => 'nickname',
- 'value' => '姓名',
- ],
- [
- 'key' => 'price',
- 'value' => '提现金额',
- ],
- [
- 'key' => 'addtime',
- 'value' => '申请日期',
- ],
- [
- 'key' => 'bank_name',
- 'value' => '银行名称',
- ],
- [
- 'key' => 'bank_card',
- 'value' => '打款账号',
- ],
- [
- 'key' => 'name',
- 'value' => '真实姓名',
- ],
- [
- 'key' => 'type',
- 'value' => '类型',
- ],
- [
- 'key' => 'pay_type',
- 'value' => '打款方式',
- ],
- [
- 'key' => 'pay_time',
- 'value' => '付款时间',
- ],
- ];
- }
- public function getCashSetting()
- {
- $cash = Option::get(OptionSetting::CASH_SETTING, get_store_id(), 'store')['value'];
- if ($cash) {
- $data = json_decode($cash, true);
- } else {
- $data = [
- 'pay_wechat' => 0,
- 'pay_alipay' => 0,
- 'bank' => 0,
- 'remaining_sum' => 0,
- 'lg' => 0,
- 'min_money' => 0, //最小提现额度
- 'cash_max_day' => 0, //每天最大提现额度
- 'cash_max_single_day' => 0, //每人每天提现额度
- 'cash_service_charge' => floatval(0), //提现手续费
- 'cash_price_type' => '',
- 'cash_price_amount' => floatval(0),
- 'cash_price_balance' => floatval(0),
- 'cash_price_integral' => floatval(0),
- 'auto_money' => 0
- ];
- }
- $data['auto_money'] = $data['auto_money'] ?? 0;
- return ['code' => 0, 'msg' => 'success', 'data' => $data];
- }
- public function editCashSetting()
- {
- if (isset($this->cash_price_type)) {
- $total_profit = 0;
- $cash_price_type = explode(',', $this->cash_price_type);
- if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) {
- $total_profit = bcadd($total_profit, $this->cash_price_amount, 2);
- }
- if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) {
- $total_profit = bcadd($total_profit, $this->cash_price_integral, 2);
- }
- if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) {
- $total_profit = bcadd($total_profit, $this->cash_price_balance, 2);
- }
- if ($total_profit != 100) {
- return [
- 'code' => 1,
- 'msg' => '佣金/积分/余额比例设置错误'
- ];
- }
- }
- $data = [
- 'pay_wechat' => $this->pay_wechat,
- 'pay_alipay' => $this->pay_alipay,
- 'bank' => $this->bank,
- 'remaining_sum' => $this->remaining_sum,
- 'lg' => $this->lg,
- 'min_money' => $this->min_money, //最小提现额度
- 'cash_max_day' => $this->cash_max_day, //每天最大提现额度
- 'cash_max_single_day' => $this->cash_max_single_day, //每人每天提现额度
- 'cash_service_charge' => floatval($this->cash_service_charge), //提现手续费
- 'cash_price_type' => $this->cash_price_type,
- 'cash_price_amount' => floatval($this->cash_price_amount),
- 'cash_price_balance' => floatval($this->cash_price_balance),
- 'cash_price_integral' => floatval($this->cash_price_integral),
- 'auto_money' => floatval($this->auto_money),
- ];
- Option::set(OptionSetting::CASH_SETTING, json_encode($data), get_store_id(), 'store');
- return ['code' => 0, 'msg' => 'success', 'data' => $data];
- }
- public function getCashList()
- {
- $query = Cash::find()->alias('c')
- ->where(['c.is_delete' => Cash::IS_DELETE_NO, 'c.store_id' => $this->store_id])
- ->leftJoin(['u' => User::tableName()], 'u.id=c.user_id');
- if ($this->keyword) {
- $query->andWhere(['like', 'u.nickname', $this->keyword]);
- }
- if ($this->dateStart) {
- $query->andWhere(['>=', 'c.created_at', strtotime($this->dateStart)]);
- }
- if ($this->dateEnd) {
- $query->andWhere(['<=', 'c.created_at', strtotime($this->dateEnd)]);
- }
- if ($this->status == Cash::STATUS_APPLY and $this->status !== '') {//待审核
- $query->andWhere(['c.status' => Cash::STATUS_APPLY]);
- }
- if ($this->status == Cash::STATUS_CONFIRM) {//待打款
- $query->andWhere(['in', 'c.status', [Cash::STATUS_CONFIRM, Cash::STATUS_LG_CONFIRM]]);
- }
- if ($this->status == Cash::STATUS_GIVEN) {//已打款
- $query->andWhere(['in', 'c.status', [Cash::STATUS_GIVEN, Cash::STATUS_HAND, Cash::STATUS_RECHARGE]]);
- }
- if ($this->status == Cash::STATUS_REFUSE) {//无效
- $query->andWhere(['c.status' => Cash::STATUS_REFUSE]);
- }
- if ($this->id) {
- $query->andWhere(['s.id' => $this->id]);
- }
- if (isset($this->type) && $this->type > -1) {
- $query->andWhere(['c.type' => $this->type]);
- }
- if ($this->flag == Export::EXPORT) {
- $export = new ExportList();
- $data = $query->orderBy('id DESC')
- ->select(['c.*', 'u.nickname', 'u.avatar_url','u.platform', 'u.id user_id'])->asArray()->all();
- $export->shareExportData($data, $this->fields);
- }
- $query->distinct()->orderBy('id DESC')->select([
- 'c.*', 'u.nickname','u.platform', 'u.avatar_url','u.binding'
- ]);
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- foreach($list as &$value){
- $value['wx_cash_status'] = intval($value['wx_cash_status']);
- $value['type_name'] = Cash::getTypeName($value);
- $value['status_name'] = Cash::getCashStatusName($value);
- $value['service_money'] = $value['service_charge'] * $value['price'] / 100;
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['updated_at'] = !empty($value['updated_at']) ? date('Y-m-d H:i:s', $value['updated_at']) : '';
- $value['money'] = Cash::getServiceMoney($value);
- $saas_user = SaasUser::findOne(['mobile' => $value['binding']]);
- $value['avatar_url'] = !empty($saas_user['avatar']) ? $saas_user['avatar'] : $value['avatar_url'];
- $value['card_no'] = '';
- if ($saas_user->withdraw_method) {
- $withdraw_method = json_decode($saas_user->withdraw_method, true);
- if (!empty($withdraw_method)) {
- foreach ($withdraw_method as $method_item) {
- if (intval($value['type']) === Cash::TYPE_ALIPAY && $method_item['type'] === 'alipay') {
- $value['cash_img'] = $method_item['cash_img'];
- } else if (intval($value['type']) === Cash::TYPE_WX && $method_item['type'] === 'wechat'){
- $value['cash_img'] = $method_item['cash_img'];
- } else if (intval($value['type']) === Cash::TYPE_BANK && $method_item['type'] === 'bank_card') {
- $value['card_no'] = $method_item['card_no'];
- }
- }
- }
- }
- $value['real_price'] = $value['money'];;
- $cashExtArr = CashExt::find()->where(['cash_id' => $value['id']])->select('cash_price_type, real_price')->asArray()->all();
- $value['cash_ext_text'] = null;
- if ($cashExtArr) {
- $value['cash_ext_text'] = '提现明细:';
- foreach ($cashExtArr as $cashExtItem) {
- if ($cashExtItem['cash_price_type'] == CashExt::CASH_PRICE_TYPE_AMOUNT) {
- $value['real_price'] = $cashExtItem['real_price'];
- }
- $value['cash_ext_text'] .= CashExt::$cashPriceTypeMap[$cashExtItem['cash_price_type']] . ':' . $cashExtItem['real_price'] . ';';
- }
- }
- $value['integral_appreciation_num'] = 0;
- $value['integral_appreciation_price'] = 0;
- }
- if($this->export){
- return $this->export($list);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'q' => $query->createCommand()->getRawSql(),
- 'export_list' => $this->getCustomField(),
- 'data' => $list,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ],
- ];
- }
- }
|