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' => '存在商品未下架']); } } }