Commit 573f6661 authored by hujun's avatar hujun

返现红包列表

parent 2bede17e
<?php
/**
* Created by PhpStorm.
* User: 43897
* Date: 2019/3/11
* Time: 15:49
*/
namespace app\index\controller;
use app\index\extend\Basic;
use app\model\CActivity;
use app\model\CCoupon;
use app\model\Users;
use think\Request;
class Coupon extends Basic
{
private $m_coupon;
private $m_activity;
public function __construct(?Request $request = null)
{
parent::__construct($request);
$this->m_coupon = new CCoupon();
$this->m_activity = new CActivity();
}
public function couponList() {
if (!$this->request->isAjax()) {
return view('couponList');
}
$page_no = empty($this->params['page_no']) ? 1 : $this->params['page_no'];
$page_size = empty($this->params['page_size']) ? 15 : $this->params['page_size'];
$where = $this->binWhere($this->params);
$field = 'id,user_id,activity_id,status,create_time';
$list = $this->m_coupon->getList($page_no, $page_size, 'id desc', $field, $where);
$total = $this->m_coupon->getTotal($where);
$m_user = new Users();
$field_activity = 'money,return_action,activity_start_time,activity_end_time';
foreach ($list as $k => $v) {
$activity_data = $this->m_activity->getFind($field_activity, ['id'=>$v['activity_id']]);
$list[$k]['money'] = $activity_data['money'];
$list[$k]['return_action'] = $activity_data['return_action'];
$list[$k]['activity_start_time'] = $activity_data['activity_start_time'];
$list[$k]['activity_end_time'] = $activity_data['activity_end_time'];
$list[$k]['user_id'] = $v['user_id'];
$list[$k]['user_name'] = '';
$list[$k]['user_phone'] = '';
}
$data['total'] = $total;
$data['list'] = $list;
return $this->response(200, '', $data);
}
/**
* @param $params
* @return array
*/
protected function binWhere($params) {
$where = [];
if (isset($params['start_time']) && isset($params['end_time'])) {
$where['create_time'] = ['between', [$params['end_time'], $params['end_time']]];
}
if (isset($params['start_time']) && !isset($where['a.create_time'])) {
$where['create_time'] = $params['start_time'];
}
if (isset($params['end_time']) && !isset($where['a.create_time'])) {
$where['create_time'] = $params['end_time'];
}
if (isset($params['user_id'])) {
$where['user_id'] = $params['user_id'];
}
if (isset($params['id'])) {
$where['id'] = $params['id'];
}
if (isset($params['activity_id'])) {
$where['activity_id'] = $params['activity_id'];
}
if (isset($params['status'])) {
$where['status'] = $params['status'];
}
return $where;
}
}
\ No newline at end of file
......@@ -128,4 +128,15 @@ class CActivity extends Model
return $this->db_->table($this->table)->where('id', $activity_id)->setInc('get_number',1);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFind($field, $where) {
return $this->field($field)->where($where)->find();
}
}
......@@ -11,7 +11,7 @@ namespace app\model;
use think\Db;
class CCoupon
class CCoupon extends BaseModel
{
// 设置当前模型对应的完整数据表名称
protected $table = 'c_coupon';
......
......@@ -425,6 +425,7 @@ Route::group('index', [
'saveActivity' => ['index/Activity/saveActivity', ['method' => 'POST|GET']],//新增或修改活动
'getActivityList' => ['index/Activity/getActivityList', ['method' => 'POST|GET']],//获取活动
'couponList' => ['index/Coupon/couponList', ['method' => 'GET']],//获取活动
]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment