quanwei
2 days ago 73b874c72ad55eb9eef21c36160ac0de58f0189e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
 
namespace app\branch\model\branch;
 
use app\common\model\branch\DepositRefund as DepositRefundModel;
use app\branch\model\branch\Branch as BranchModel;
use app\branch\model\order\Order as OrderModel;
use app\branch\model\product\Product as ProductModel;
use app\common\exception\BaseException;
/**
 * 供应商提现账号模型
 */
class DepositRefund extends DepositRefundModel
{
   
    /**
     * 提交申请
     */
    public function submit($branch)
    {
        // 数据验证
        $this->validation($branch);
         // 开启事务
        $this->startTrans();
        try {
            // 新增申请记录
            $this->save([
            'branch_id' => $branch['branch_id'],
            'deposit_money'=>$branch['deposit_money'],
            'app_id' => self::$app_id,
            ]);
            (new BranchModel())->where(['branch_id' => $branch['branch_id']])->update(['status'=>10]);
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
       
     
    }
 
    /**
     * 数据验证
     */
    private function validation($branch)
    {
        if ($branch['deposit_money'] <= 0) {
            throw new BaseException(['msg' => '没有可退款金额']);
        }
        $isrefund = $this->where(['branch_id'=>$branch['branch_id'],'status'=>0])->find();
        if($isrefund){
            throw new BaseException(['msg' => '申请退款中']);
        }
        // 筛选条件
        $filter = [];
        $filter['branch_id'] = $branch['branch_id'];
        $filter['pay_status'] = 20;
        $filter['is_settled'] = 0;
        //查询是否有未完成订单
        $isOrder = (new OrderModel())->where($filter)->where('order_status', '<>', 20)->find();
        if($isOrder){
            throw new BaseException(['msg' => '存在订单未结算完成']);
        }
        //查询商品是否全部下架
        $filter = [];
        $filter['branch_id'] = $branch['branch_id'];
        $filter['product_status'] = 10;
        $filter['audit_status'] = 10;
        $filter['is_delete'] = 0;
        $isProduct = (new ProductModel())->where($filter)->find();
        if($isProduct){
            throw new BaseException(['msg' => '存在商品未下架']);
        }
    }
}