| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace addons\StarChain\common\models;
- use Yii;
- /**
- * This is the model class for table "{{%addons_star_chain_message}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property int|null $msg_id 消息ID
- * @property string|null $tenant_id
- * @property int|null $enum_num 消息类型
- * @property string|null $content 消息内容
- * @property int|null $status 0 未处理 1 已处理
- * @property string|null $fail_msg 处理失败消息
- * @property int|null $create_time 消息时间
- * @property int|null $handled_at 处理时间
- */
- class Message extends BaseModel
- {
- /**
- * 处理成功
- */
- const SUCCESS = 1;
- /**
- * 处理失败
- */
- const FAIL = 2;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_star_chain_message}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'msg_id', 'enum_num', 'status', 'create_time', 'handled_at'], 'integer'],
- [['content'], 'string'],
- [['tenant_id'], 'string', 'max' => 64],
- [['fail_msg'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'msg_id' => 'Msg ID',
- 'tenant_id' => 'Tenant ID',
- 'enum_num' => 'Enum Num',
- 'content' => 'Content',
- 'status' => 'Status',
- 'fail_msg' => 'Fail Msg',
- 'create_time' => 'Create Time',
- 'handled_at' => 'Handled At',
- ];
- }
- /**
- * 新增消息
- *
- * @param array $list
- * @param int $mall_id
- * @return int
- */
- public static function addMsg($mall_id, $list)
- {
- $list = array_map(function ($item) use ($mall_id) {
- return [
- 'msg_id' => $item['id'],
- 'mall_id' => $mall_id,
- 'tenant_id' => $item['tenantId'],
- 'enum_num' => $item['enumNum'],
- 'content' => $item['content'],
- 'create_time' => strtotime($item['createTime']),
- ];
- }, $list);
- return self::batchInsert($list, false);
- }
- /**
- * 设置消息为已处理
- *
- * @param array $msg_ids
- * @return int
- */
- public static function setHandled($msg_ids)
- {
- return self::updateAll(
- [
- 'handled_at' => time(),
- 'status' => static::SUCCESS,
- ],
- [
- 'msg_id' => $msg_ids,
- ]
- );
- }
- /**
- * 设置消息为处理失败
- *
- * @return int
- */
- public static function setHandledFail($msg_ids, string $fail_msg)
- {
- return static::updateAll(
- [
- 'handled_at' => time(),
- 'status' => static::FAIL,
- 'fail_msg' => $fail_msg,
- ],
- [
- 'msg_id' => $msg_ids,
- ]
- );
- }
- }
|