| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "{{%mch_account_log}}".
- *
- */
- class MchAccountLog extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%mch_account_log}}';
- }
-
-
- public static function saveLog($mch_id, $user_id, $amount, $log_type, $order_id = 0, $order_no = '', $desc = "", $profit = 0, $isTotal = 1)
- {
- $t = \Yii::$app->db->beginTransaction();
- try{
- $form = new self();
- $mch = Mch::findOne($mch_id);
- $form->store_id = $mch->store_id;
- $form->user_id = $user_id;
- $form->mch_id = $mch_id;
- $form->amount = $amount;
- $form->before = $mch->account_money;
- if ($log_type == AccountLog::LOG_TYPE_INCOME) {
- $form->after = $form->before + $amount;
- } else {
- $form->after = $form->before - $amount;
- }
- $form->desc = $desc;
- $form->order_id = $order_id;
- $form->order_no = $order_no;
- $form->operator = '';
- $form->operator_id = 0;
- $form->log_type = $log_type;
- $form->operator_type = AccountLog::TYPE_OPERATOR_NORMAL;
- $form->created_at = time();
- if ($profit) {
- $form->profit = $profit;
- }
- if (!$form->save()) {
- \Yii::error([__METHOD__, $form->getErrors()]);
- throw new \Exception('入驻商佣金发放log保存失败' . array_shift($form->getFirstErrors()));
- }
- if ($log_type == AccountLog::LOG_TYPE_INCOME) {
- if($isTotal){
- $mch->account_money_total += $amount;
- }
- $mch->account_money += $amount;
- } else {
- $mch->account_money -= $amount;
- if($mch->account_money < 0){
- \Yii::error([__METHOD__, $mch->getErrors()]);
- throw new \Exception('入驻商佣金不足' . array_shift($mch->getFirstErrors()));
- }
- }
- $save = $mch->save();
- if(!$save){
- \Yii::error([__METHOD__, $mch->getErrors()]);
- throw new \Exception('入驻商佣金修改失败' . array_shift($mch->getFirstErrors()));
- }
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => 'ok',
- ];
- } catch (\Exception $ex) {
- $t->rollBack();
- return [
- 'code' => 1,
- 'msg' => '操作失败,' . $ex->getMessage(),
- ];
- }
- }
- }
|