| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\SaasProfitCash;
- use app\models\SaasUser;
- use app\models\StoreShareMoney;
- use app\models\User;
- use app\utils\Wechat\WechatNewPay;
- use yii\base\Model;
- class PlatformProfitCashForm extends Model
- {
- public $id;
- public $reason;
- public $search_type;
- public $status = -1;
- public $dateStart;
- public $dateEnd;
- public $keyword;
- public $name;
- public $mobile;
- public $type;
- public $store_id;
- public $is_daili;//是否为代理账户
- public function rules()
- {
- return [
- [['store_id', 'search_type', 'status', 'type', 'id', 'is_daili'], 'integer'],
- [['keyword', 'dateStart', 'dateEnd', 'name', 'mobile'], 'string', 'max' => 255],
- [['keyword'], 'trim'],
- ];
- }
- public function search() {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- $saas_user_id = 0;
- if ((int)$this->is_daili === 1) {
- $admin = get_admin();
- $saas_user_id = $admin->saas_user_id;
- $SaasUser = SaasUser::findOne($saas_user_id);
- }
- $query = SaasProfitCash::find()->alias('spc')
- ->leftJoin(['su' => SaasUser::tableName()],'su.id=spc.user_id')->where(['spc.is_delete' => 0]);
- if (!empty($saas_user_id)) {
- $query->andWhere(['spc.user_id' => $saas_user_id]);
- }
- // 名称
- if ($this->name) {
- $query->andWhere(['like', 'su.name', $this->name]);
- }
- // 手机号
- if ($this->mobile) {
- $query->andWhere(['like', 'spc.mobile', $this->mobile]);
- }
- // 提现方式
- if ((int)$this->type !== -1 && $this->type !== null && $this->type !== '') {
- $query->andWhere(['spc.type' => $this->type]);
- }
- // 状态
- if ((int)$this->status !== -1 && $this->status !== null) {
- $query->andWhere(['spc.status' => $this->status]);
- }
- $query->orderBy('spc.created_at DESC, spc.updated_at DESC')
- ->groupBy('spc.order_no')
- ->select('spc.*, su.name, su.avatar, su.name');
- $list = pagination_make($query);
- foreach ($list['list'] as &$val) {
- $val['created_at'] = date('Y-m-d H:i:s', $val['created_at']);
- $val['updated_at'] = date('Y-m-d H:i:s', $val['updated_at']);
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'data' => $list['list'],
- 'pageNo' => $list['pageNo'],
- 'totalCount' => $list['totalCount'],
- 'share_profit' => $SaasUser->share_profit ?? '0.00'
- ]
- ];
- }
- /**
- * 联盟佣金提现审核
- * @return array
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function audit() {
- $cash = SaasProfitCash::findOne(['is_delete' => 0, 'id' => $this->id, 'status' => SaasProfitCash::CASH_STATUS_WAIT]);
- if (!$cash) {
- return [
- 'code' => 1,
- 'msg' => '记录不存在'
- ];
- }
- // 拒绝
- if ($this->status == SaasProfitCash::CASH_STATUS_FAIL) {
- $saas_user = SaasUser::findOne($cash->user_id);
- $saas_user->share_profit = (($saas_user->share_profit * 1) + ($cash->amount * 1) + ($cash->service_money * 1));
- $saas_user->save();
- $cash->status = SaasProfitCash::CASH_STATUS_FAIL;
- $cash->refuse_reason = !empty($this->reason) ? trim($this->reason) : '';
- if (!$cash->save()) {
- return [
- 'code' => 1,
- 'msg' => implode(';', array_values($cash->firstErrors))
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- }
- // 通过
- if ($this->status == SaasProfitCash::CASH_STATUS_PASS) {
- $cash->status = SaasProfitCash::CASH_STATUS_PASS;
- if (!$cash->save()) {
- return [
- 'code' => 1,
- 'msg' => implode(';', array_values($cash->firstErrors))
- ];
- }
- $form = new StoreShareMoney();
- $form->user_id = $cash->user_id;
- $form->store_id = 0;
- $form->profit = 0;
- $form->total_price = $cash->amount;
- $form->desc = "用户提现";
- $form->order_id = $cash->id;
- $form->created_at = time();
- $form->status = StoreShareMoney::STATUS_STORE_PAYOUTS;
- $form->commission = 0;
- if (!$form->save()) {
- return [
- 'code' => 1,
- 'msg' => implode(';', array_values($form->firstErrors))
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- }
- return [
- 'code' => 1,
- 'msg' => '操作异常'
- ];
- }
- public function del()
- {
- try {
- $id = $this->id;
- $cash = SaasProfitCash::findOne($id);
- if (!$cash) {
- throw new \Exception("查找失败");
- }
- $cash->is_delete = 1;
- if (get_saas_user_id()) {
- throw new \Exception("身份信息错误");
- }
- if (!$cash->save()) {
- throw new \Exception(json_encode($cash->errors));
- }
- return [
- 'code' => 0,
- 'msg' => "操作成功"
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => '操作异常' . $e->getMessage()
- ];
- }
- }
- }
|