| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\Order;
- use app\models\OrderDetail;
- use app\models\OrderMessage;
- use app\models\Shop;
- use app\models\ShopShare;
- use app\models\User;
- use Yii;
- use yii\base\Model;
- use yii\data\Pagination;
- class OrderMessageForm extends Model
- {
- public $store_id;
- public $limit;
- public $page;
- public $is_read;
- public function rules()
- {
- return [
- [['limit', 'page'], 'integer'],
- [['limit'], 'default', 'value' => 5],
- [['page'], 'default', 'value' => 1]
- ];
- }
- public function search()
- {
- if (!$this->validate()) {
- return $this->errorResponse;
- }
- $query = OrderMessage::find()->alias('om')->where([
- 'om.store_id' => $this->store_id,
- 'om.is_delete' => 0,
- 'om.order_type' => [0, 1, 2, 3, 4, 6, 7],
- ]);
- if ($this->is_read) {
- $query->andWhere(['or',['om.is_read' => 0],['om.is_sound'=>0]]);
- }
- $query->andWhere(['>=','om.created_at', strtotime('2022-09-23')]);
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
- $list = $query->orderBy(['om.created_at' => SORT_DESC])
- ->limit($pagination->limit)
- ->offset($pagination->offset)
- ->asArray()
- ->all();
- $urlManager = \Yii::$app->urlManager;
- // 此处考虑在 cache 或 setting 内做缓存,存储 order_message 表的更新时间,以及查询结果
- // 插入 order_message 时,在 beforeInsert 内清空缓存
- // -- wi1dcard
- foreach ($list as &$value) {
- $time = time() - $value['created_at'];
- if ($time < 60) {
- $value['time'] = $time . '秒前';
- } elseif ($time < 3600) {
- $value['time'] = ceil($time / 60) . '分钟前';
- } elseif ($time < 86400) {
- $value['time'] = ceil($time / 3600) . '小时前';
- } else {
- $value['time'] = ceil($time / 86400) . '天前';
- }
- $value['created_at'] = date("Y-m-d H:i:s", $value['created_at']);
- }
- return [
- 'list' => $list,
- 'count' => $count,
- 'pagination' => $pagination
- ];
- }
- }
|