order_id = $order['id']; $model->store_id = $order['store_id']; $model->user_id = $order['uid']; $model->nickname = $order['other_data']->nickname; $model->phone = $order['other_data']->phone; $model->deadline = time() + 86400 * 15; $model->total_debt = $order['total_price']; $model->surplus_debt = $order['total_price']; $model->save(); } public static function edit($params) { Db::startTrans(); try { $accountsReceivable = AccountsReceivable::where(['id' => $params['accounts_receivable_id']])->find(); if ($accountsReceivable->surplus_debt <= 0) { throw new BusinessException('该账单已支付'); } $surplusDebt = bcsub($accountsReceivable->surplus_debt, $params['pay_debt'], 2); $model = new AccountsReceivableInfo(); $model->accounts_receivable_id = $params['accounts_receivable_id']; $model->pay_type = $params['pay_type']; $model->total_debt = $params['surplus_debt']; $model->pay_debt = $params['pay_debt']; $model->recipient = $params['recipient']; $model->surplus_debt = $surplusDebt; $model->file = $params['file']; $model->mark = $params['mark']; if (!$model->save()) { throw new BusinessException('添加失败'); } $accountsReceivable->pay_debt = bcadd($accountsReceivable->pay_debt, $params['pay_debt'], 2); $accountsReceivable->surplus_debt = $surplusDebt; if (!$accountsReceivable->save()) { throw new BusinessException('更新账单出错'); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); throw new BusinessException($e->getMessage()); } } public static function record($params) { } }