| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\modules\client\models\v1\pond;
- use app\constants\OptionSetting;
- use app\models\Option;
- use app\models\PondLog;
- use yii\base\Model;
- use yii\data\Pagination;
- class PondLogForm extends Model
- {
- public $user_id;
- public $store_id;
- public $page;
- public $limit;
- public $id;
- public function search()
- {
- $form = PondLog::find()
- ->where([
- 'store_id' => $this->store_id,
- 'user_id' => $this->user_id,
- 'is_delete' => 0,
- ])->andWhere(['<>', 'type', '1'])
- ->with(['gift' => function ($query) {
- $query->where([
- 'store_id' => $this->store_id,
- 'is_delete' => 0
- ]);
- }]);
- $count = $form->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]);
- $list = $form->limit($pagination->limit)->offset($pagination->offset)->orderBy('create_time DESC,id DESC')->asArray()->all();
- foreach ($list as &$v) {
- $v['type'] = (int)$v['type'];
- $v['create_time'] = date('Y:m:d H:i:s', $v['create_time']);
- switch ($v['type']) {
- case 2:
- $v['name'] = $v['gift']['name'];
- break;
- case 1:
- $v['name'] = '谢谢参与';
- break;
- default:
- }
- }
- unset($v);
- $kf_wechat_img = Option::get(OptionSetting::WEB_KF_WECHAT_IMG, $this->store_id, 'display')['value'];
- if ($list) {
- return [
- 'code' => 0,
- 'data' => [
- 'kf_wechat_img' => $kf_wechat_img,
- 'list' => $list,
- ]
- ];
- } else {
- return [
- 'code' => 0,
- 'data' => [
- 'list' => []
- ],
- ];
- }
- }
- public function del()
- {
- $log = PondLog::findOne([
- 'id' => $this->id,
- 'store_id' => $this->store_id,
- 'user_id' => $this->user_id,
- 'is_delete' => 0,
- ]);
- if (!$log) {
- return [
- 'code' => 1,
- 'msg' => '网络异常'
- ];
- }
- $log->is_delete = 1;
- if ($log->save()) {
- return [
- 'code' => 0,
- 'msg' => '删除成功'
- ];
- }
- return [
- 'code' => 1,
- 'msg' => '网络异常'
- ];
- }
- }
|