| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\modules\admin\controllers\pond;
- use app\models\Goods;
- use app\models\Pond;
- use app\models\PondLog;
- use app\models\User;
- use app\modules\admin\controllers\BaseController;
- use yii\data\Pagination;
- class LogController extends BaseController
- {
- public function actionIndex()
- {
- $query = PondLog::find()->alias('log')
- ->leftJoin(['p' => Pond::tableName()], 'log.pond_id = p.id')
- ->leftJoin(['u' => User::tableName()], 'log.user_id = u.id')
- ->leftJoin(['g' => Goods::tableName()], 'log.gift_id = g.id')
- ->where(['log.store_id' => get_store_id()])
- ->select('log.*, p.name as gift_name, u.nickname, g.name as goods_name');
- if ($type = post_params('type')) {
- $query->andWhere(['log.type' => $type]);
- }
- if ($nickname = post_params('nickname')) {
- $query->andWhere(['u.nickname' => $nickname]);
- }
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count]);
- // $query = $query->limit($pagination->limit)->offset($pagination->offset);
- $query->orderBy('log.id desc');
- $list = pagination_make($query);
- foreach ($list['list'] as &$item) {
- $item['create_time'] = date('Y-m-d H:i:s', $item['create_time']);
- $item['gift_name'] = $item['gift_name'] ?: $item['goods_name'];
- if ($item['pond_name']) {
- $item['gift_name'] = $item['pond_name'];
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => $list,
- ]);
- }
- public function actionSend()
- {
- $id = post_params('id');
- $model = PondLog::findOne($id);
- if (!$model) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '中奖记录不存在',
- ]);
- }
- $model->status = 1;
- $model->raffle_time = time();
- if($model->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '兑换成功',
- ]);
- }
- return $this->asJson([
- 'code' => 1,
- 'msg' => '数据有误',
- ]);
- }
- }
|