TimestampBehavior::class, 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'] ] ] ]; } /** * @inheritdoc */ public function rules() { return [ [['is_send', 'send_time', 'start_time', 'end_time', 'is_scan', 'currency_id', 'main_currency_id'], 'integer'], [['money', 'balance_amount', 'dividend_amount', 'rate'], 'number'], [['created_at', 'updated_at'], 'safe'] ]; } /** * 增加合伙人分红池 * @param $order * @param $money * @param string $desc * @return false|void */ public static function poolPush($order, $money, $desc = '', $pay_price = 0, $model = 0) { $is_scan = $order instanceof ScanCodePayOrder ? 1 : 0; //debug_log([__METHOD__, __LINE__, "执行acpoolpush"], "app_debug.log"); $form = new CurrencyForm(); $data = $form->Inertupdate_bonus($order->id,$is_scan); //debug_log([__METHOD__, __LINE__, "===订单id:".$order->id.',payprice:'.$pay_price], "app_debug.log"); foreach ($data as $i){ $dividend = $i['dividend']; foreach ($dividend as $j){ $pool = self::find()->where(['and',['<', 'start_time', time()],['>=', 'end_time', time()],['=', 'is_send', 0],['=', 'currency_id', $j['id']]]) ->orderBy(['id' => SORT_DESC])->one(); //debug_log([__METHOD__, __LINE__, "---------------- 开始插入分红池1 -------------------currency_id".$j['id']], "app_debug.log"); // 如果没有奖金池,重新创建奖金池 if (!$pool) { $time_data = self::getTime($j['id']); $pool = new self(); $pool->start_time = $time_data['start_time']; $pool->main_currency_id = $i['main_currency_id']; $pool->currency_id = $j['id']; $pool->rate= $j['percent']; $pool->end_time = $time_data['end_time']; $pool->is_send = 0; $pool->send_time = 0; } $before_money = $pool->money ? $pool->money : 0; $add_money = $money*$j['percent']/100; $pool->money += $add_money; if (!$pool->save()) { //debug_log([__METHOD__, __LINE__, "---------------- 合伙人奖金池更新失败 -------------------" . json_encode($pool->errors)], "app_debug.log"); return false; } $pool_log = new AcPoolDetail(); $pool_log->order_id = $order->id; $pool_log->currency_id = $j['id']; $pool_log->order_no = $order->order_no; $pool_log->pay_price = $is_scan ? $pay_price : $order->pay_price+$order->take_price; $pool_log->store_id = $order->store_id; $pool_log->before_money = $before_money; $pool_log->after_money = $pool->money; $pool_log->total_pv = $money; $pool_log->money = $add_money; $pool_log->total_price = $order->total_price; $pool_log->is_scan = $is_scan; $pool_log->pool_id = $pool->id; $pool_log->model_type = $model; $pool_log->desc = '订单号:' . $order->order_no . '追加'; if (!$pool_log->save()) { //debug_log([__METHOD__, __LINE__, "---------------- 奖金池记录保存失败 -------------------" . json_encode($pool_log->errors)], "app_debug.log"); return false; } } } //debug_log([__METHOD__, __LINE__, "---------------- 开始插入分红池结束 -------------------"], "app_debug.log"); } public static function getTime($currency_id) { $data = Option::getDecode('currency_dividend_time',$currency_id,'currency');//使用币种id代替store_id $interval = $data['interval'] ?? 1; $timeunit = $data['timeunit']; if (!in_array($timeunit,['minute','hour','day','month'])) $timeunit = 'day'; switch ($timeunit){ case 'minute': $time = strtotime(date('Y-m-d H:i:00', time())); break; case 'hour': $time = strtotime(date('Y-m-d H:00:00', time())); break; case 'month': $time = strtotime(date('Y-m-1', time())); break; default: $time = strtotime(date('Y-m-d', time())); break; } return [ 'start_time' => $time, 'end_time' => strtotime('+'.$interval.' '.$timeunit,$time) ]; } }