...
|
...
|
@@ -10,165 +10,142 @@ namespace app\admin\controller; |
|
|
use cmf\controller\AdminBaseController;
|
|
|
use think\Db;
|
|
|
|
|
|
class ActivityController extends AdminBaseController {
|
|
|
class ActivityController extends AdminBaseController
|
|
|
{
|
|
|
|
|
|
public function index() {
|
|
|
$search=[];
|
|
|
$search['is_del']=['eq', 0];
|
|
|
$post=request()->param();
|
|
|
$t_id=(isset($post['t_id'])) ? $post['t_id'] : 0;
|
|
|
$name=(isset($post['name'])) ? $post['name'] : null;
|
|
|
if($t_id != 0) {
|
|
|
$search['t_id']=['eq', $_POST['t_id']];
|
|
|
public function index()
|
|
|
{
|
|
|
$search = [];
|
|
|
$search['is_del'] = ['eq', 0];
|
|
|
$post = request()->param();
|
|
|
$t_id = (isset($post['t_id'])) ? $post['t_id'] : 0;
|
|
|
$name = (isset($post['name'])) ? $post['name'] : null;
|
|
|
if ($t_id != 0) {
|
|
|
$search['t_id'] = ['eq', $_POST['t_id']];
|
|
|
}
|
|
|
if($name != null) {
|
|
|
$search['name']=['like', "%$_POST[name]%"];
|
|
|
if ($name != null) {
|
|
|
$search['name'] = ['like', "%$_POST[name]%"];
|
|
|
}
|
|
|
$res=Db::name('activity')->alias('a')
|
|
|
$res = Db::name('activity')->alias('a')
|
|
|
->field('a.*,t.type_name,q.qr_code')
|
|
|
->join('type t', 'a.t_id=t.id')
|
|
|
->join('qr q', 'q.activity_id=a.id')
|
|
|
->where($search)
|
|
|
->paginate(20, false, [
|
|
|
'query' => request()->param()
|
|
|
'query' => request()->param()
|
|
|
]);
|
|
|
return $this->fetch('index', [
|
|
|
'activity' => $res,
|
|
|
'page' => $res->render(),
|
|
|
'type' => Db::name('type')->field('id,type_name')->select(),
|
|
|
'search' => ['t_id' => $t_id, 'name' => $name]
|
|
|
'activity' => $res,
|
|
|
'page' => $res->render(),
|
|
|
'type' => Db::name('type')->field('id,type_name')->select(),
|
|
|
'search' => ['t_id' => $t_id, 'name' => $name]
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public function add() {
|
|
|
$request=request();
|
|
|
if($request->isPost()) {
|
|
|
$post=$request->param();
|
|
|
$post['is_down_payment']=(isset($post['is_down_payment'])) ? 1 : 0;
|
|
|
$post['is_new']=(isset($post['is_new'])) ? 1 : 0;
|
|
|
$post['is_hot']=(isset($post['is_hot'])) ? 1 : 0;
|
|
|
$post['is_on_sale']=(isset($post['is_on_sale'])) ? 1 : 0;
|
|
|
if(!empty($post['thumb'])) {
|
|
|
public function add()
|
|
|
{
|
|
|
$request = request();
|
|
|
if ($request->isPost()) {
|
|
|
$post = $request->param();
|
|
|
$post['is_down_payment'] = (isset($post['is_down_payment'])) ? 1 : 0;
|
|
|
$post['is_new'] = (isset($post['is_new'])) ? 1 : 0;
|
|
|
$post['is_hot'] = (isset($post['is_hot'])) ? 1 : 0;
|
|
|
$post['is_on_sale'] = (isset($post['is_on_sale'])) ? 1 : 0;
|
|
|
$post['date_type'] = 1;
|
|
|
if (!empty($post['thumb'])) {
|
|
|
$post['thumb'] = cmf_get_image_url($post['thumb']);
|
|
|
}
|
|
|
if(!empty($post['content'])) {
|
|
|
if (!empty($post['content'])) {
|
|
|
$post['content'] = htmlspecialchars_decode($post['content']);
|
|
|
}
|
|
|
if(!empty($post['banner'])) {
|
|
|
$banner='';
|
|
|
for($j=0; $j<count($post['banner']); $j++) {
|
|
|
$banner.=cmf_get_image_url($post['banner'][$j]).',';
|
|
|
if (!empty($post['banner'])) {
|
|
|
$banner = '';
|
|
|
for ($j = 0; $j < count($post['banner']); $j++) {
|
|
|
$banner .= cmf_get_image_url($post['banner'][$j]) . ',';
|
|
|
}
|
|
|
$post['banner']=substr($banner, 0, strlen($banner)-1);
|
|
|
$post['banner'] = substr($banner, 0, strlen($banner) - 1);
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
$schedule=$post['schedule'];
|
|
|
$schedule = $post['schedule'];
|
|
|
unset($post['schedule']);
|
|
|
if(Db::name('activity')->insert($post)) {
|
|
|
$activity_id=Db::name('activity')->getLastInsID();
|
|
|
$data=[];
|
|
|
for ($i=0; $i<count($schedule); $i++) {
|
|
|
$data[$i]=[
|
|
|
'activity_id' => $activity_id,
|
|
|
'start_time' => strtotime($schedule[$i]['start_time']),
|
|
|
'end_time' => strtotime($schedule[$i]['end_time']),
|
|
|
'price' => $schedule[$i]['price'],
|
|
|
'maximum' => $schedule[$i]['maximum'],
|
|
|
'deadline' => strtotime($schedule[$i]['deadline'])
|
|
|
if (Db::name('activity')->insert($post)) {
|
|
|
$activity_id = Db::name('activity')->getLastInsID();
|
|
|
$data = [];
|
|
|
for ($i = 0; $i < count($schedule); $i++) {
|
|
|
$data[$i] = [
|
|
|
'activity_id' => $activity_id,
|
|
|
'start_time' => strtotime($schedule[$i]['start_time']),
|
|
|
'end_time' => strtotime($schedule[$i]['end_time']),
|
|
|
'price' => $schedule[$i]['price'],
|
|
|
'maximum' => $schedule[$i]['maximum'],
|
|
|
'deadline' => strtotime($schedule[$i]['deadline'])
|
|
|
];
|
|
|
}
|
|
|
if(Db::name('activity_schedule')->insertAll($data)) {
|
|
|
if (Db::name('activity_schedule')->insertAll($data)) {
|
|
|
//生成二维码
|
|
|
$qr=[
|
|
|
'activity_id' => $activity_id,
|
|
|
'qr_code' => $this->qrCode($activity_id),
|
|
|
$qr = [
|
|
|
'activity_id' => $activity_id,
|
|
|
'qr_code' => $this->qrCode($activity_id),
|
|
|
];
|
|
|
if(Db::name('qr')->insert($qr)) {
|
|
|
if (Db::name('qr')->insert($qr)) {
|
|
|
Db::commit();
|
|
|
$this->success('添加成功');
|
|
|
}else {
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error('添加失败');
|
|
|
}
|
|
|
}else {
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error('添加失败');
|
|
|
}
|
|
|
}else {
|
|
|
} else {
|
|
|
Db::rollback();
|
|
|
$this->error('添加失败');
|
|
|
}
|
|
|
}else {
|
|
|
} else {
|
|
|
return $this->fetch('add', [
|
|
|
'type' => Db::name('type')->field('id,type_name')->select()
|
|
|
'type' => Db::name('type')->field('id,type_name')->select()
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function edit() {
|
|
|
$request=request();
|
|
|
if($request->isPost()) {
|
|
|
$post=$request->param();
|
|
|
$post['is_down_payment']=(isset($post['is_down_payment'])) ? 1 : 0;
|
|
|
$post['is_new']=(isset($post['is_new'])) ? 1 : 0;
|
|
|
$post['is_hot']=(isset($post['is_hot'])) ? 1 : 0;
|
|
|
$post['is_on_sale']=(isset($post['is_on_sale'])) ? 1 : 0;
|
|
|
if($post['is_down_payment'] == 0) {
|
|
|
$post['down_price']=0;
|
|
|
public function edit()
|
|
|
{
|
|
|
$request = request();
|
|
|
if ($request->isPost()) {
|
|
|
$post = $request->param();
|
|
|
$post['is_down_payment'] = (isset($post['is_down_payment'])) ? 1 : 0;
|
|
|
$post['is_new'] = (isset($post['is_new'])) ? 1 : 0;
|
|
|
$post['is_hot'] = (isset($post['is_hot'])) ? 1 : 0;
|
|
|
$post['is_on_sale'] = (isset($post['is_on_sale'])) ? 1 : 0;
|
|
|
$post['date_type'] = 1;
|
|
|
if ($post['is_down_payment'] == 0) {
|
|
|
$post['down_price'] = 0;
|
|
|
}
|
|
|
if(!empty($post['thumb'])) {
|
|
|
if (!empty($post['thumb'])) {
|
|
|
$post['thumb'] = cmf_get_image_url($post['thumb']);
|
|
|
}
|
|
|
if(!empty($post['content'])) {
|
|
|
if (!empty($post['content'])) {
|
|
|
$post['content'] = htmlspecialchars_decode($post['content']);
|
|
|
}
|
|
|
if(!empty($post['banner'])) {
|
|
|
$banner='';
|
|
|
for($j=0; $j<count($post['banner']); $j++) {
|
|
|
$banner.=cmf_get_image_url($post['banner'][$j]).',';
|
|
|
if (!empty($post['banner'])) {
|
|
|
$banner = '';
|
|
|
for ($j = 0; $j < count($post['banner']); $j++) {
|
|
|
$banner .= cmf_get_image_url($post['banner'][$j]) . ',';
|
|
|
}
|
|
|
$post['banner']=substr($banner, 0, strlen($banner)-1);
|
|
|
$post['banner'] = substr($banner, 0, strlen($banner) - 1);
|
|
|
}
|
|
|
$schedule=(isset($post['schedule'])) ? $post['schedule'] : null;
|
|
|
if(empty($schedule)) {
|
|
|
$this->error('请添加批次');
|
|
|
}
|
|
|
$schedule=$post['schedule'];
|
|
|
unset($post['schedule']);
|
|
|
Db::startTrans();
|
|
|
if(Db::name('activity')->update($post) >= 0) {
|
|
|
if(Db::name('activity_schedule')->where(['activity_id'=>$request->param('id')])->delete()) {
|
|
|
$data=[];
|
|
|
for ($i=0; $i<count($schedule); $i++) {
|
|
|
$data[$i]=[
|
|
|
'activity_id' => $request->param('id'),
|
|
|
'start_time' => strtotime($schedule[$i]['start_time']),
|
|
|
'end_time' => strtotime($schedule[$i]['end_time']),
|
|
|
'price' => $schedule[$i]['price'],
|
|
|
'maximum' => $schedule[$i]['maximum'],
|
|
|
'deadline' => strtotime($schedule[$i]['deadline'])
|
|
|
];
|
|
|
}
|
|
|
if(Db::name('activity_schedule')->insertAll($data)) {
|
|
|
Db::commit();
|
|
|
$this->success('编辑成功');
|
|
|
}else {
|
|
|
Db::rollback();
|
|
|
$this->error('编辑失败');
|
|
|
}
|
|
|
}else {
|
|
|
Db::rollback();
|
|
|
$this->error('编辑失败');
|
|
|
}
|
|
|
}else {
|
|
|
Db::rollback();
|
|
|
$this->error('编辑失败');
|
|
|
if (Db::name('activity')->update($post)) {
|
|
|
$this->success('编辑成功');
|
|
|
} else {
|
|
|
$this->error('您为做出任何修改');
|
|
|
}
|
|
|
}else {
|
|
|
} else {
|
|
|
$info = Db::name('activity')->where(['id' => $request->param('id')])->find();
|
|
|
$banner = $info['banner'];
|
|
|
$arr = [];
|
|
|
if(!empty($banner)) {
|
|
|
if (!empty($banner)) {
|
|
|
$temp = explode(',', $banner);
|
|
|
for ($i = 0; $i < count($temp); $i++) {
|
|
|
$arr[$i]['url'] = $temp[$i];
|
...
|
...
|
@@ -183,11 +160,12 @@ class ActivityController extends AdminBaseController { |
|
|
}
|
|
|
}
|
|
|
|
|
|
public function del() {
|
|
|
$id=request()->param('id');
|
|
|
if(Db::name('activity')->update(['id'=>$id,'is_del'=>1])) {
|
|
|
public function del()
|
|
|
{
|
|
|
$id = request()->param('id');
|
|
|
if (Db::name('activity')->update(['id' => $id, 'is_del' => 1])) {
|
|
|
$this->success('删除成功');
|
|
|
}else {
|
|
|
} else {
|
|
|
$this->error('删除失败');
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -197,7 +175,8 @@ class ActivityController extends AdminBaseController { |
|
|
* @param $id
|
|
|
* @return string
|
|
|
*/
|
|
|
private function qrCode($id) {
|
|
|
private function qrCode($id)
|
|
|
{
|
|
|
$savePath = APP_PATH . '/../Public/qrcode/';
|
|
|
$webPath = '/qrcode/';
|
|
|
$qrData = 'https://www.baidu.com';
|
...
|
...
|
@@ -208,8 +187,57 @@ class ActivityController extends AdminBaseController { |
|
|
if ($filename = createQRcode($savePath, $qrData, $qrLevel, $qrSize, $savePrefix)) {
|
|
|
$pic = $webPath . $filename;
|
|
|
}
|
|
|
$qr_code=cmf_get_image_url($pic);
|
|
|
$qr_code = cmf_get_image_url($pic);
|
|
|
return $qr_code;
|
|
|
}
|
|
|
|
|
|
public function addSchedule()
|
|
|
{
|
|
|
$request = request();
|
|
|
if ($request->isPost()) {
|
|
|
$post = $request->param();
|
|
|
$schedule = $post['schedule'];
|
|
|
$data = [];
|
|
|
for ($i = 0; $i < count($schedule); $i++) {
|
|
|
$data[$i] = [
|
|
|
'activity_id' => $request->param('activity_id'),
|
|
|
'start_time' => strtotime($schedule[$i]['start_time']),
|
|
|
'end_time' => strtotime($schedule[$i]['end_time']),
|
|
|
'price' => $schedule[$i]['price'],
|
|
|
'maximum' => $schedule[$i]['maximum'],
|
|
|
'deadline' => strtotime($schedule[$i]['deadline'])
|
|
|
];
|
|
|
}
|
|
|
if (Db::name('activity_schedule')->insertAll($data)) {
|
|
|
$this->success('新增批次成功');
|
|
|
} else {
|
|
|
$this->error('新增批次失败');
|
|
|
}
|
|
|
} else {
|
|
|
return $this->fetch('add_schedule', [
|
|
|
'activity_id' => $request->param('id'),
|
|
|
'schedule' => Db::name('activity_schedule')->where(['activity_id' => $request->param('id')])->select(),
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function delSchedule()
|
|
|
{
|
|
|
$schedule_id = request()->param('id');
|
|
|
if (Db::name('activity_schedule')->delete($schedule_id)) {
|
|
|
return $this->success('', '', true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function editSchedule()
|
|
|
{
|
|
|
$post = request()->param();
|
|
|
$post['start_time'] = strtotime($post['start_time']);
|
|
|
$post['end_time'] = strtotime($post['end_time']);
|
|
|
$post['deadline'] = strtotime($post['deadline']);
|
|
|
if (Db::name('activity_schedule')->update($post)) {
|
|
|
return $this->success('编辑批次成功', '', true);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|