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', 'admin_id'], 'integer'], [['money', 'balance_amount', 'dividend_amount', 'rangli_rate', 'moxing_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, $rl_rate = 0, $mx_rate = 0, $model = 0, $add_money = 0) { $salesman_id = Store::find()->where(['id' => $order->store_id])->select(['salesman_id'])->asArray()->scalar() ?: null; $salesman = Salesman::findOne(['id' => $salesman_id, 'is_delete' => 0, 'status' => 1]); if (empty($salesman) || !$salesman->admin_id) return false; $admin = Admin::findOne(['id' => $salesman->admin_id, 'is_delete' => 0]); if (empty($admin)) return false; $is_scan = $order instanceof ScanOrder ? 1 : 0; //debug_log([__METHOD__, __LINE__, "执行poolpush"], "app_debug.log"); $pool = self::find()->where([ 'and', [ '<', 'start_time', time() ], [ '>=', 'end_time', time() ], [ '=', 'is_scan', $is_scan ], [ '=', 'is_send', 0 ], [ '=', 'admin_id', $admin->id ] ])->orderBy(['id' => SORT_DESC])->one(); //debug_log([__METHOD__, __LINE__, "---------------- 开始插入分红池1 -------------------"], "app_debug.log"); // 如果没有奖金池,重新创建奖金池 if (!$pool) { $pool = new self(); $pool->start_time = strtotime(date('Y-m-d', time())); $end_time = $pool->start_time + (24 * 3600); $pool->end_time = $end_time; $pool->is_send = 0; $pool->send_time = 0; $pool->is_scan = $is_scan; $pool->admin_id = $admin->id; } $pool->moxing_rate = $mx_rate; $pool->rangli_rate = $rl_rate; $before_money = $pool->money ? $pool->money : 0; $pool->money += $money; if (!$pool->save()) { //debug_log([__METHOD__, __LINE__, "---------------- 合伙人奖金池更新失败 -------------------" . json_encode($pool->errors)], "app_debug.log"); return false; } $pool_log = new UnitFounderPoolDetail(); $pool_log->order_id = $order['id']; $pool_log->admin_id = $admin->id; $pool_log->order_no = $order->order_no; $pool_log->money = $money; $pool_log->pay_price = $is_scan ? $pay_price : $order->pay_price; $pool_log->store_id = $order->store_id; $pool_log->before_money = $before_money; $pool_log->after_money = $pool->money; $pool_log->total_pv = $add_money; $pool_log->rl_rate = $rl_rate; $pool_log->mx_rate = $mx_rate; $pool_log->money = $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 = $desc ?: '订单号:' . $order->order_no . '追加'; if (!$pool_log->save()) { //debug_log([__METHOD__, __LINE__, "---------------- 奖金池记录保存失败 -------------------" . json_encode($pool_log->errors)], "app_debug.log"); return false; } if ($is_scan) { switch ($model) { case 0: ScanCodePayOrder::updateAll(['small_model_pv_bonus' => $money], ['id' => $order['id']]); break; case 1: ScanCodePayOrder::updateAll(['big_model_pv_bonus' => $money], ['id' => $order['id']]); break; default: break; } } //debug_log([__METHOD__, __LINE__, "---------------- 开始插入分红池结束 -------------------"], "app_debug.log"); } }