TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'] ] ] ]; } /** * @inheritdoc */ public function rules() { return [ [['store_id', 'scale', 'is_transfer', 'transfer_fee_rate', 'enable', 'enable_bussiness_mode', 'enable_goods_deduct', 'enable_balance', 'enable_draw', 'draw_comfirm', 'enable_transmit', 'transmit_user_type', 'enable_exchange', 'ts_cardinal_number', 'ex_cardinal_number', 'is_auto_pay', 'is_open_one', 'dividend_switch', 'dividend_deduct_switch','dividend_deduct_ratio'], 'integer'], [['guid_price', 'exchange_price', 'exchange_rate', 'balance_rate', 'draw_fee_ratio', 'balance_fee_ratio', 'transmit_rate', 'remainder', 'cny_price', 'rights_amplify_ratio','issue_quantity'], 'number'], [['unit', 'name', 'code', 'type'], 'string', 'max' => 32], [['symbol', 'plugin_code'], 'string', 'max' => 32], [['remark'], 'string', 'max' => 255], [['contract_address', 'auto_pay_address'], 'string', 'max' => 255], [['logo', 'private_key', 'allinfo','shop_dividend_json','scan_dividend_json'], 'string'], [['created_at', 'updated_at'], 'safe'] ]; } public static function addSaasMoney($currency_id,$saas_id,$type,$money,$remark,$store_id=0) { try { $coininfo = CurrencyCoin::findOne($currency_id); $wallet = UserWalletCoin::findOne(['currency_id' => $currency_id, 'saas_id' => $saas_id]); if (!$wallet) { $wallet = new UserWalletCoin(); $wallet->currency_id = $currency_id; $wallet->saas_id = $saas_id; $wallet->store_id = 0; $wallet->user_id = 0; $wallet->money = 0; $wallet->store_id = 0; $wallet->user_id = 0; } $before_money = $wallet->money; if ($type == 1) { $wallet->money += floatval($money); } else { $wallet->money -= floatval($money); } if ($wallet->money < 0) throw new \Exception("钱包余额不足"); $table = "cyy_wallet_log_" . $coininfo->code; \Yii::$app->db->createCommand()->insert("{$table}", [ 'cloud_user_id' => 0, 'user_id' => 0, 'saas_id' => $saas_id, 'store_id' => 0, 'currency_id' => $currency_id, 'currency_yewu_id' => 1, 'currency_code' => $coininfo->code, 'created_at' => time(), 'money' => $money, 'before_money' => $before_money, 'after_money' => $wallet->money, 'desc' => $remark, 'type' => $type ])->execute(); $wallet->save(); if($store_id>0){ //扣除店铺商确权 $wallet_store = UserWalletCoin::findOne(['currency_id' => $currency_id, 'store_id' => $store_id]); $cloud_before_money = $wallet_store->money; $cloud_after_money = $wallet_store->money - $money; Yii::$app->db->createCommand(" UPDATE cyy_user_wallet_coin SET money = money - :money WHERE store_id = :store_id AND currency_id = :currency_id AND currency_yewu_id = :currency_yewu_id ")->bindValues([ ':money' => $money, ':store_id' => $store_id, ':currency_id' => $currency_id, ':currency_yewu_id' => 1 ])->execute(); $type = "ORDER_CUT"; \Yii::$app->db->createCommand()->insert("{$table}", [ 'cloud_user_id'=>0, 'user_id'=>0, 'saas_id'=>0, 'store_id'=>$store_id, 'currency_id'=>$currency_id, 'currency_yewu_id'=>1, 'currency_code'=>$coininfo->code, 'created_at'=>time(), 'money'=> (-1)*$money, 'before_money'=>$cloud_before_money, 'after_money'=>$cloud_after_money, 'desc'=>$remark, 'type'=>$type ])->execute(); } return true; } catch (\Exception $e) { $self = new self(); $self->errorMessage = $e->getMessage(); ActionLog::addLog(1, 'CurrencyCoin::addSaasMoney/currencyAward', $e->getMessage()); return false; }catch (\Throwable $e) { $self = new self(); $self->errorMessage = $e->getMessage(); ActionLog::addLog(1, 'CurrencyCoin::addSaasMoney/currencyAward', $e->getMessage()); return false; } } }