'留言项ID', 'mall_id' => '商城ID', 'order_id' => '订单ID', 'mch_id' => '多商户ID', 'store_id' => '门店id', 'message' => '留言信息', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'share_user_id' => '分享的用户Id' ]; } /** * 批量插入 * * @param array $insert_data * @return int */ public static function batchInsert(array $insert_data) { return \Yii::$app->db ->createCommand() ->batchInsert(static::tableName(), array_keys($insert_data[0]), $insert_data) ->execute(); } /** * 留言批量插入 * @param array $params * @return bool */ public static function batchLeave(array $params): bool { try { $orderIds = explode(',', $params['order_ids']); foreach ($orderIds as $id) { $orderInfo = Order::find()->where(['id' => $id])->select('id,mch_id,store_id,mall_id')->one(); if ($orderInfo) { $orderExtra = self::findOne(['order_id' => $id]); if (!$orderExtra) { $orderExtra = new self(); } $orderExtra->mall_id = $orderInfo->mall_id; $orderExtra->mch_id = $orderInfo->mch_id; $orderExtra->store_id = $orderInfo->store_id; $orderExtra->message = $params['content']; $orderExtra->order_id = $id; $orderExtra->save(); } } return true; } catch (\Exception $e) { if (isset($trans)) $trans->rollback(); self::$static_error = $e->getMessage(); return false; } } /** * 根据条件获取留言数据 * @param array $where * @param string $field * @return array|\yii\db\ActiveRecord[] */ public static function getList(array $where, string $field = '*'): array { return self::find()->where($where)->select($field)->orderBy('id desc')->asArray()->all(); } /** * 获取留言信息 * @param $where * @param string $field * @return array|\yii\db\ActiveRecord|null */ public static function getInfo($where, string $field = '*') { return self::find()->where($where)->select($field)->orderBy('id desc')->asArray()->one(); } public static function updateShareUserId($order,$data) { try { $model = OrderExtra::findOne(['order_id'=>$order['id']]); if(empty($model)){ $model = new OrderExtra(); $model->loadDefaultValues(); $model->mall_id = $order['mall_id']; $model->order_id = $order['id']; $model->mch_id = $order['mch_id']; $model->store_id = $order['store_id']; } $model->share_user_id = $data['share_user_id']; if(!$model->save()){ throw new \Exception($model->getErrorMessage()); } return true; } catch (\Exception $e) { var_dump('订单创建事件维护share_user_id失败,错误:' . $e->getMessage() . ',行数:' . $e->getLine()); return true; } } }