| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- namespace app\modules\admin\models\integralAppreciation;
- use app\models\IntegralAppreciationCommunity;
- use app\models\IntegralAppreciationUser;
- use app\models\User;
- use app\modules\client\controllers\BaseController;
- use yii\base\Model;
- class CommunityForm extends Model
- {
- public $store_id;
- public $user_name;
- public $type;
- public $mobile;
- public $start_time;
- public $end_time;
- public $status;
- public $ids;
- public function rules() {
- return [
- [['mobile', 'user_name', 'start_time', 'end_time', 'ids'], 'string'],
- [['store_id', 'type', 'status'], 'integer'],
- ];
- }
- /**
- * 帖子列表
- */
- public function getList() {
- $type = $this->type;
- $mobile = $this->mobile;
- $status = $this->status;
- $store_id = $this->store_id;
- $start_time = $this->start_time;
- $end_time = $this->end_time;
- $user_name = $this->user_name;
- $query = IntegralAppreciationCommunity::find()->alias('c')
- ->leftJoin(['u' => User::tableName()], 'c.user_id = u.id')
- ->where(['c.store_id' => $store_id, 'c.is_delete' => 0]);
- if ($mobile) {
- $query->andWhere(['LIKE', 'c.mobile', $mobile]);
- }
- if ($user_name) {
- $query->andWhere(['LIKE', 'u.nickname', $user_name]);
- }
- if ($start_time) {
- $start_time = strtotime($start_time);
- $query->andWhere(['>=', 'c.created_at', $start_time]);
- }
- if ($end_time) {
- $end_time = strtotime($end_time);
- $query->andWhere(['<=', 'c.created_at', $end_time]);
- }
- if (isset($type) && in_array($type, [IntegralAppreciationCommunity::TYPE_BUY, IntegralAppreciationCommunity::TYPE_SELL])) {
- $query->andWhere(['c.type' => $type]);
- }
- if (isset($status) && in_array($status, [IntegralAppreciationCommunity::STATUS_NO_APPLY, IntegralAppreciationCommunity::STATUS_APPLY, IntegralAppreciationCommunity::STATUS_REFUSE])) {
- $query->andWhere(['c.status' => $status]);
- }
- $query->orderBy('c.id DESC')->select('c.id, c.type, c.integral, c.mobile,
- c.created_at, u.nickname, u.avatar_url avatar, u.binding user_mobile, c.status');
- $pagination = pagination_make($query);
- foreach ($pagination['list'] as &$item) {
- $item['type'] = intval($item['type']);
- $item['status'] = intval($item['status']);
- $item['created_at'] = date('Y-m-d H:i:s', $item['created_at']);
- $item['type_text'] = IntegralAppreciationCommunity::$typeArray[$item['type']];
- $item['status_text'] = IntegralAppreciationCommunity::$statusArray[$item['status']];
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $pagination
- ];
- }
- public function setStatus() {
- try {
- $ids = $this->ids;
- $status = $this->status;
- $ids = explode(',', $ids);
- if (!$ids) {
- throw new \Exception('请选择要删除的项');
- }
- if (!in_array($status, [IntegralAppreciationCommunity::STATUS_APPLY, IntegralAppreciationCommunity::STATUS_REFUSE])) {
- throw new \Exception('状态错误');
- }
- foreach ($ids as $id) {
- $community = IntegralAppreciationCommunity::findOne($id);
- if (intval($community->status) !== IntegralAppreciationCommunity::STATUS_NO_APPLY) {
- throw new \Exception('状态已经被修改');
- }
- $community->status = $status;
- if (!$community->save()) {
- throw new \Exception(implode(',', $community->getFirstErrors()));
- }
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- public function del() {
- try {
- $ids = $this->ids;
- $ids = explode(',', $ids);
- if (!$ids) {
- throw new \Exception('请选择要删除的项');
- }
- foreach ($ids as $id) {
- $goods = IntegralAppreciationCommunity::findOne($id);
- $goods->is_delete = 1;
- if (!$goods->save()) {
- throw new \Exception(implode(',', $goods->getFirstErrors()));
- }
- }
- return [
- 'code' => 0,
- 'msg' => '删除成功'
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- }
|