| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- /**
- * Niushop商城系统 - 团队十年电商经验汇集巨献!
- * =========================================================
- * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
- * ----------------------------------------------
- * 官方网址: https://www.niushop.com
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
- * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
- * =========================================================
- */
- namespace addon\store\shopapi\controller;
- use addon\sitecoupon\model\Coupon as CouponModel;
- use app\model\promotion\Promotion as PromotionModel;
- use app\model\system\Promotion as SysPromotionModel;
- use app\model\member\MemberCoupon as MemberCouponModel;
- /**
- * 互动营销控制器
- * Class Promotion
- * @package addon\shop\siteapi\controller
- */
- class Promotion extends BaseStoreApi
- {
- /**
- * 互动营销 活动列表
- */
- public function lists()
- {
- $sys_promotion_model = new SysPromotionModel();
- $promotion_type_list = $sys_promotion_model->getPromotionType('member');
- $promotion_model = new PromotionModel();
- $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
- $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : '1';
- $page_size = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
- $search_text = isset($this->params[ 'search_text' ]) ? $this->params[ 'search_text' ] : '';
- $start_time = isset($this->params[ 'start_time' ]) ? $this->params[ 'start_time' ] : '';
- $end_time = isset($this->params[ 'end_time' ]) ? $this->params[ 'end_time' ] : '';
- $state = isset($this->params[ 'state' ]) ? $this->params[ 'state' ] : '';
- $promotion_type = isset($this->params[ 'promotion_type' ]) ? $this->params[ 'promotion_type' ] : '';
- $order = isset($this->params[ 'order' ]) ? $this->params[ 'order' ] : '';
- $sort = isset($this->params[ 'sort' ]) ? $this->params[ 'sort' ] : '';
- $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
- // 上架状态
- if ($state !== '') {
- $condition[] = [ 'state', '=', $state ];
- if ($state == 1) {
- $condition[] = [ 'end_time', '>', time() ];
- }
- }
- if (!empty($search_text)) {
- $condition[] = [ 'name', 'like', '%' . $search_text . '%' ];
- }
- if ($promotion_type !== "") {
- $condition[] = [ 'promotion_type', '=', $promotion_type ];
- }
- if ($promotion_id) {
- $condition[] = [ 'promotion_id', '=', $promotion_id ];
- }
- //时间
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ "start_time", ">=", date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ "start_time", "<=", date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'start_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- if ($order == '') {
- $order_by = 'create_time desc';
- } else {
- $order_by = $order . ' ' . $sort;
- }
- $res = $promotion_model->getPromotionPageList($condition, $page, $page_size, $order_by);
- foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
- $res[ 'data' ][ 'list' ][ $k ][ 'promotion_type_name' ] = $promotion_type_list[ $v[ 'promotion_type' ] ][ 'title' ];
- }
- return $this->response($res);
- }
- /**
- * 互动营销 活动详情
- */
- public function detail()
- {
- $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
- $site_id = $this->site_id;
- $condition = [
- [ 'promotion_id', '=', $promotion_id ],
- [ 'site_id', '=', $site_id ]
- ];
- $promotion_model = new PromotionModel();
- $promotion_info = $promotion_model->getPromotionInfo($condition);
- if (empty($promotion_info[ 'data' ])) return $this->response($this->error('未获取到活动数据'));
- return $this->response($promotion_info);
- }
- /**
- * 互动营销 优惠券详情
- */
- public function couponList()
- {
- $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';
- //获取优惠券详情
- $coupon_model = new MemberCouponModel();
- $coupon_list = $coupon_model->getCouponList([ [ 'from_type_id', '=', $promotion_id ], [ 'from_type', '=', 'promotion' ], [ 'site_id', '=', $this->site_id ] ]);
- return $this->response($coupon_list);
- }
- /**
- * 删除活动
- */
- public function deletePromotion()
- {
- $promotion_ids = isset($this->params[ 'promotion_ids' ]) ? $this->params[ 'promotion_ids' ] : 0;
- $model = new PromotionModel();
- $res = $model->modifyIsDelete($promotion_ids, 1, $this->site_id);
- return $this->response($res);
- }
- /**
- * 修改活动
- */
- public function modifyPromotionState()
- {
- $promotion_ids = isset($this->params[ 'promotion_ids' ]) ? $this->params[ 'promotion_ids' ] : 0;
- $state = isset($this->params[ 'state' ]) ? $this->params[ 'state' ] : 1;
- $model = new PromotionModel();
- $res = $model->modifyPromotionState($promotion_ids, $state, $this->site_id);
- return $this->response($res);
- }
- /**
- * 添加活动
- */
- public function addPromotion()
- {
- $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';#活动名称
- $image = isset($this->params[ 'image' ]) ? $this->params[ 'image' ] : '';#活动主图
- $content = isset($this->params[ 'content' ]) ? $this->params[ 'content' ] : '';#活动富文本
- $stock = isset($this->params[ 'stock' ]) ? $this->params[ 'stock' ] : 0;#数量
- $start_time = isset($this->params[ 'start_time' ]) ? date_to_time($this->params[ 'start_time' ]) : '';#活动开始时间
- $end_time = isset($this->params[ 'end_time' ]) ? date_to_time($this->params[ 'end_time' ]) : '';#活动结束时间
- $share_title = isset($this->params[ 'share_title' ]) ? $this->params[ 'share_title' ] : '';#分享标题
- $share_desc = isset($this->params[ 'share_desc' ]) ? $this->params[ 'share_desc' ] : '';#分享描述
- $is_show_wechat = isset($this->params[ 'is_show_wechat' ]) ? $this->params[ 'is_show_wechat' ] : '';#是否显示关注公众号悬浮框 0否 1是
- $group_chat = isset($this->params[ 'group_chat' ]) ? $this->params[ 'group_chat' ] : '';#群聊二维码
- $group_name = isset($this->params[ 'group_name' ]) ? $this->params[ 'group_name' ] : '';#群聊名称
- $group_desc = isset($this->params[ 'group_desc' ]) ? $this->params[ 'group_desc' ] : '';#群聊介绍
- $coupon_data = isset($this->params[ 'coupon_data' ]) ? $this->params[ 'coupon_data' ] : '';
- $data = [
- 'site_id' => $this->site_id,
- 'name' => $name,
- 'image' => $image,
- 'content' => $content,
- 'stock' => $stock,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'share_title' => $share_title,
- 'share_desc' => $share_desc,
- 'is_show_wechat' => $is_show_wechat,
- 'group_chat' => $group_chat,
- 'group_name' => $group_name,
- 'group_desc' => $group_desc,
- 'coupon_data' => $coupon_data,
- ];
- $coupon_model = new CouponModel();
- $res = $coupon_model->addCoupon($data);
- return $this->response($res);
- }
- /**
- * 编辑活动
- */
- public function editPromotion()
- {
- $coupon_model = new CouponModel();
- $promotion_id = isset($this->params[ 'promotion_id' ]) ? $this->params[ 'promotion_id' ] : '';#商品Id
- $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';#活动名称
- $image = isset($this->params[ 'image' ]) ? $this->params[ 'image' ] : '';#活动主图
- $content = isset($this->params[ 'content' ]) ? $this->params[ 'content' ] : '';#活动富文本
- $stock = isset($this->params[ 'stock' ]) ? $this->params[ 'stock' ] : 0;#数量
- $start_time = isset($this->params[ 'start_time' ]) ? date_to_time($this->params[ 'start_time' ]) : '';#活动开始时间
- $end_time = isset($this->params[ 'end_time' ]) ? date_to_time($this->params[ 'end_time' ]) : '';#活动结束时间
- $share_title = isset($this->params[ 'share_title' ]) ? $this->params[ 'share_title' ] : '';#分享标题
- $share_desc = isset($this->params[ 'share_desc' ]) ? $this->params[ 'share_desc' ] : '';#分享描述
- $is_show_wechat = isset($this->params[ 'is_show_wechat' ]) ? $this->params[ 'is_show_wechat' ] : '';#是否显示关注公众号悬浮框 0否 1是
- $group_chat = isset($this->params[ 'group_chat' ]) ? $this->params[ 'group_chat' ] : '';#群聊二维码
- $group_name = isset($this->params[ 'group_name' ]) ? $this->params[ 'group_name' ] : '';#群聊名称
- $group_desc = isset($this->params[ 'group_desc' ]) ? $this->params[ 'group_desc' ] : '';#群聊介绍
- $coupon_data = isset($this->params[ 'coupon_data' ]) ? $this->params[ 'coupon_data' ] : '';
- $data = [
- 'promotion_id' => $promotion_id,
- 'site_id' => $this->site_id,
- 'name' => $name,
- 'image' => $image,
- 'content' => $content,
- 'stock' => $stock,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'share_title' => $share_title,
- 'share_desc' => $share_desc,
- 'is_show_wechat' => $is_show_wechat,
- 'group_chat' => $group_chat,
- 'group_name' => $group_name,
- 'group_desc' => $group_desc,
- 'coupon_data' => $coupon_data,
- ];
- $res = $coupon_model->editCoupon($data);
- return $this->response($res);
- }
- }
|