| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace common\models\order;
- use common\models\order\Order;
- /**
- * This is the model class for table "{{%order_detail}}".
- *
- *
- * @property int $id 订单项ID
- * @property int|null $mall_id 商城ID
- * @property int|null $order_id 订单ID
- * @property int|null $user_id 用户id
- * @property int|null $mch_id 多商户ID
- * @property int|null $store_id 门店ID
- * @property string $message 留言信息
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- * @property int $share_user_id 分享用户ID
- */
- class OrderExtra extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%order_extra}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['order_id', 'mall_id', 'mch_id', 'store_id', 'created_at', 'updated_at'], 'integer'],
- [['share_user_id'], 'safe'],
- [['message'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '留言项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;
- }
- }
- }
|