123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- <?php
- namespace app\home\controller;
- use think\facade\View;
- use think\facade\Lang;
- use think\facade\Db;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Sellerpromotionxianshi extends BaseSeller
- {
- public function initialize()
- {
- parent::initialize(); // TODO: Change the autogenerated stub
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/sellerpromotionxianshi.lang.php');
- if (intval(config('ds_config.promotion_allow')) !== 1) {
- $this->error(lang('promotion_unavailable'), 'seller/index');
- }
- }
- public function index()
- {
- $xianshiquota_model = model('pxianshiquota');
- $pxianshi_model = model('pxianshi');
- if (check_platform_store()) {
- View::assign('isPlatformStore', true);
- } else {
- $current_xianshi_quota = $xianshiquota_model->getXianshiquotaCurrent(session('store_id'));
- View::assign('current_xianshi_quota', $current_xianshi_quota);
- }
- $condition = array();
- $condition[] = array('store_id', '=', session('store_id'));
- if ((input('param.xianshi_name'))) {
- $condition[] = array('xianshi_name', 'like', '%' . input('param.xianshi_name') . '%');
- }
- if ((input('param.state'))) {
- $condition[] = array('xianshi_state', '=', intval(input('param.state')));
- }
- $xianshi_list = $pxianshi_model->getXianshiList($condition, 10, Db::raw('FIELD(xianshi_state, 1,0,2,3), xianshi_end_time desc'));
- View::assign('xianshi_list', $xianshi_list);
- View::assign('show_page', $pxianshi_model->page_info->render());
- View::assign('xianshi_state_array', $pxianshi_model->getXianshiStateArray());
- $this->setSellerCurMenu('Sellerpromotionxianshi');
- $this->setSellerCurItem('xianshi_list');
- return View::fetch($this->template_dir . 'index');
- }
- /**
- * 添加秒杀活动
- * */
- public function xianshi_add()
- {
- if (check_platform_store()) {
- View::assign('isPlatformStore', true);
- } else {
- View::assign('isPlatformStore', false);
- $xianshiquota_model = model('pxianshiquota');
- $current_xianshi_quota = $xianshiquota_model->getXianshiquotaCurrent(session('store_id'));
- if (empty($current_xianshi_quota)) {
- if (intval(config('ds_config.promotion_xianshi_price')) != 0) {
- $this->error(lang('xianshi_quota_current_error1'));
- } else {
- $current_xianshi_quota = array('xianshiquota_starttime' => TIMESTAMP, 'xianshiquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
- }
- }
- View::assign('current_xianshi_quota', $current_xianshi_quota);
- }
- //输出导航
- $this->setSellerCurMenu('Sellerpromotionxianshi');
- $this->setSellerCurItem('xianshi_add');
- return View::fetch($this->template_dir . 'xianshi_add');
- }
- /**
- * 保存添加的秒杀活动
- * */
- public function xianshi_save()
- {
- //验证输入
- $xianshi_name = trim(input('post.xianshi_name'));
- $start_time = strtotime(input('post.start_time'));
- $end_time = strtotime(input('post.end_time'));
- $lower_limit = intval(input('post.lower_limit'));
- if ($lower_limit <= 0) {
- $lower_limit = 1;
- }
- if (empty($xianshi_name)) {
- ds_json_encode(10001, lang('xianshi_name_error'));
- }
- if ($start_time >= $end_time) {
- ds_json_encode(10001, lang('greater_than_start_time'));
- }
- if (!check_platform_store()) {
- //获取当前套餐
- $xianshiquota_model = model('pxianshiquota');
- $current_xianshi_quota = $xianshiquota_model->getXianshiquotaCurrent(session('store_id'));
- if (empty($current_xianshi_quota)) {
- if (intval(config('ds_config.promotion_xianshi_price')) != 0) {
- ds_json_encode(10001, lang('please_buy_package_first'));
- } else {
- $current_xianshi_quota = array('xianshiquota_starttime' => TIMESTAMP, 'xianshiquota_endtime' => TIMESTAMP + 86400 * 30); //没有套餐时,最多一个月
- }
- }
- $quota_start_time = intval($current_xianshi_quota['xianshiquota_starttime']);
- $quota_end_time = intval($current_xianshi_quota['xianshiquota_endtime']);
- if ($start_time < $quota_start_time) {
- ds_json_encode(10001, sprintf(lang('xianshi_add_start_time_explain'), date('Y-m-d', $current_xianshi_quota['xianshiquota_starttime'])));
- }
- if ($end_time > $quota_end_time) {
- ds_json_encode(10001, sprintf(lang('xianshi_add_end_time_explain'), date('Y-m-d', $current_xianshi_quota['xianshiquota_endtime'])));
- }
- }
- if ($end_time < TIMESTAMP) {
- ds_json_encode(10001, sprintf(lang('xianshi_add_end_time_explain'), date('Y-m-d')));
- }
- //生成活动
- $pxianshi_model = model('pxianshi');
- $param = array();
- $param['xianshi_name'] = $xianshi_name;
- $param['xianshi_title'] = input('post.xianshi_title');
- $param['xianshi_explain'] = input('post.xianshi_explain');
- $param['xianshiquota_id'] = isset($current_xianshi_quota['xianshiquota_id']) ? $current_xianshi_quota['xianshiquota_id'] : 0;
- $param['xianshi_starttime'] = $start_time;
- $param['xianshi_end_time'] = $end_time;
- $param['store_id'] = session('store_id');
- $param['store_name'] = session('store_name');
- $param['member_id'] = session('member_id');
- $param['member_name'] = session('member_name');
- $param['xianshi_lower_limit'] = $lower_limit;
- $result = $pxianshi_model->addXianshi($param);
- if ($result) {
- $this->recordSellerlog(lang('add_limited_time_discount_activity') . $xianshi_name . lang('activity_number') . $result);
- // 添加计划任务
- $this->addcron(array('cron_exetime' => $param['xianshi_end_time'], 'cron_value' => serialize(intval($result)), 'cron_type' => 'editExpireXianshi'), true);
- ds_json_encode(10000, lang('xianshi_add_success'));
- } else {
- ds_json_encode(10001, lang('xianshi_add_fail'));
- }
- }
- /**
- * 编辑秒杀活动
- * */
- public function xianshi_edit()
- {
- if (check_platform_store()) {
- View::assign('isPlatformStore', true);
- } else {
- View::assign('isPlatformStore', false);
- }
- $pxianshi_model = model('pxianshi');
- $xianshi_info = $pxianshi_model->getXianshiInfoByID(input('param.xianshi_id'));
- if (empty($xianshi_info) || !$xianshi_info['editable']) {
- $this->error(lang('param_error'));
- }
- View::assign('xianshi_info', $xianshi_info);
- //输出导航
- $this->setSellerCurMenu('Sellerpromotionxianshi');
- $this->setSellerCurItem('xianshi_edit');
- return View::fetch($this->template_dir . 'xianshi_add');
- }
- /**
- * 编辑保存秒杀活动
- * */
- public function xianshi_edit_save()
- {
- $xianshi_id = input('post.xianshi_id');
- $pxianshi_model = model('pxianshi');
- $xianshigoods_model = model('pxianshigoods');
- $xianshi_info = $pxianshi_model->getXianshiInfoByID($xianshi_id, session('store_id'));
- if (empty($xianshi_info) || !$xianshi_info['editable']) {
- ds_json_encode(10001, lang('param_error'));
- }
- //验证输入
- $xianshi_name = trim(input('post.xianshi_name'));
- $lower_limit = intval(input('post.lower_limit'));
- if ($lower_limit <= 0) {
- $lower_limit = 1;
- }
- if (empty($xianshi_name)) {
- ds_json_encode(10001, lang('xianshi_name_error'));
- }
- //生成活动
- $param = array();
- $param['xianshi_name'] = $xianshi_name;
- $param['xianshi_title'] = input('post.xianshi_title');
- $param['xianshi_explain'] = input('post.xianshi_explain');
- $param['xianshi_lower_limit'] = $lower_limit;
- $param_goods = array();
- $param_goods['xianshi_name'] = $xianshi_name;
- $param_goods['xianshi_title'] = input('post.xianshi_title');
- $param_goods['xianshi_explain'] = input('post.xianshi_explain');
- $param_goods['xianshigoods_lower_limit'] = $lower_limit;
- $result = $pxianshi_model->editXianshi($param, array('xianshi_id' => $xianshi_id));
- $result1 = $xianshigoods_model->editXianshigoods($param_goods, array('xianshi_id' => $xianshi_id));
- if ($result) {
- $this->recordSellerlog(lang('edit_limited_time_discount_activity') . $xianshi_name . lang('activity_number') . $xianshi_id);
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- /**
- * 秒杀活动删除
- * */
- public function xianshi_del()
- {
- $xianshi_id = intval(input('post.xianshi_id'));
- $pxianshi_model = model('pxianshi');
- $data = array();
- $data['result'] = true;
- $xianshi_info = $pxianshi_model->getXianshiInfoByID($xianshi_id, session('store_id'));
- if (!$xianshi_info) {
- ds_json_encode(10001, lang('param_error'));
- }
- $pxianshi_model = model('pxianshi');
- $result = $pxianshi_model->delXianshi(array('xianshi_id' => $xianshi_id));
- if ($result) {
- $this->recordSellerlog(lang('delete_limited_time_discount_activity') . $xianshi_info['xianshi_name'] . lang('activity_number') . $xianshi_id);
- ds_json_encode(10000, lang('ds_common_op_succ'));
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
- /**
- * 秒杀活动管理
- * */
- public function xianshi_manage()
- {
- $pxianshi_model = model('pxianshi');
- $xianshigoods_model = model('pxianshigoods');
- $xianshi_id = intval(input('param.xianshi_id'));
- $xianshi_info = $pxianshi_model->getXianshiInfoByID($xianshi_id, session('store_id'));
- if (empty($xianshi_info)) {
- $this->error(lang('param_error'));
- }
- View::assign('xianshi_info', $xianshi_info);
- //获取秒杀商品列表
- $condition = array();
- $condition[] = array('xianshi_id', '=', $xianshi_id);
- $xianshigoods_list = $xianshigoods_model->getXianshigoodsExtendList($condition);
- View::assign('xianshi_goods_list', $xianshigoods_list);
- //输出导航
- $this->setSellerCurMenu('Sellerpromotionxianshi');
- $this->setSellerCurItem('xianshi_manage');
- return View::fetch($this->template_dir . 'xianshi_manage');
- }
- /**
- * 秒杀套餐购买
- * */
- public function xianshi_quota_add()
- {
- //输出导航
- $this->setSellerCurMenu('Sellerpromotionxianshi');
- $this->setSellerCurItem('xianshi_quota_add');
- return View::fetch($this->template_dir . 'xianshi_quota_add');
- }
- /**
- * 秒杀套餐购买保存
- * */
- public function xianshi_quota_add_save()
- {
- if (intval(config('ds_config.promotion_xianshi_price')) == 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $xianshi_quota_quantity = intval(input('post.xianshi_quota_quantity'));
- if ($xianshi_quota_quantity <= 0 || $xianshi_quota_quantity > 12) {
- ds_json_encode(10001, lang('xianshi_quota_quantity_error'));
- }
- //获取当前价格
- $current_price = intval(config('ds_config.promotion_xianshi_price'));
- //获取该用户已有套餐
- $xianshiquota_model = model('pxianshiquota');
- $current_xianshi_quota = $xianshiquota_model->getXianshiquotaCurrent(session('store_id'));
- $xianshi_add_time = 86400 * 30 * $xianshi_quota_quantity;
- if (empty($current_xianshi_quota)) {
- //生成套餐
- $param = array();
- $param['member_id'] = session('member_id');
- $param['member_name'] = session('member_name');
- $param['store_id'] = session('store_id');
- $param['store_name'] = session('store_name');
- $param['xianshiquota_starttime'] = TIMESTAMP;
- $param['xianshiquota_endtime'] = TIMESTAMP + $xianshi_add_time;
- $xianshiquota_model->addXianshiquota($param);
- } else {
- $param = array();
- $param['xianshiquota_endtime'] = Db::raw('xianshiquota_endtime+' . $xianshi_add_time);
- $xianshiquota_model->editXianshiquota($param, array('xianshiquota_id' => $current_xianshi_quota['xianshiquota_id']));
- }
- //记录店铺费用
- $this->recordStorecost($current_price * $xianshi_quota_quantity, lang('buy_limited_time_discount'));
- $this->recordSellerlog(lang('buy') . $xianshi_quota_quantity . lang('limited_time_discount_package') . $current_price . lang('ds_yuan'));
- ds_json_encode(10000, lang('xianshi_quota_add_success'));
- }
- /**
- * 选择活动商品
- * */
- public function goods_select()
- {
- $goods_model = model('goods');
- $condition = array();
- $condition[] = array('goods.store_id', '=', session('store_id'));
- $condition[] = array('goods.goods_name', 'like', '%' . input('param.goods_name') . '%');
- $goods_list = $goods_model->getGoodsListForPromotion($condition, 'goods.goods_id,goods.goods_commonid,goods.goods_name,goods.goods_image,goods.goods_price', 10, 'xianshi');
- View::assign('goods_list', $goods_list);
- View::assign('show_page', $goods_model->page_info->render());
- echo View::fetch($this->template_dir . 'goods_select');
- }
- /**
- * 秒杀商品添加
- * */
- public function xianshi_goods_add()
- {
- $goods_id = intval(input('post.goods_id'));
- $xianshi_id = intval(input('post.xianshi_id'));
- $xianshi_price = floatval(input('post.xianshi_price'));
- $goods_model = model('goods');
- $pxianshi_model = model('pxianshi');
- $xianshigoods_model = model('pxianshigoods');
- $data = array();
- $data['result'] = true;
- $goods_info = $goods_model->getGoodsInfoByID($goods_id);
- if (empty($goods_info) || $goods_info['store_id'] != session('store_id')) {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- echo json_encode($data);
- die;
- }
- $xianshi_info = $pxianshi_model->getXianshiInfoByID($xianshi_id, session('store_id'));
- if (!$xianshi_info) {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- echo json_encode($data);
- die;
- }
- //检查商品是否已经参加同时段活动
- $condition = array();
- $condition[] = array('xianshigoods_end_time', '>', $xianshi_info['xianshi_starttime']);
- $condition[] = array('goods_id', '=', $goods_id);
- $xianshigoods = $xianshigoods_model->getXianshigoodsExtendList($condition);
- if (!empty($xianshigoods)) {
- $data['result'] = false;
- $data['message'] = lang('product_participated_simultaneous_activities');
- echo json_encode($data);
- die;
- }
- //添加到活动商品表
- $param = array();
- $param['xianshi_id'] = $xianshi_info['xianshi_id'];
- $param['xianshi_name'] = $xianshi_info['xianshi_name'];
- $param['xianshi_title'] = $xianshi_info['xianshi_title'];
- $param['xianshi_explain'] = $xianshi_info['xianshi_explain'];
- $param['goods_id'] = $goods_info['goods_id'];
- $param['goods_commonid'] = $goods_info['goods_commonid'];
- $param['store_id'] = $goods_info['store_id'];
- $param['goods_name'] = $goods_info['goods_name'];
- $param['goods_price'] = $goods_info['goods_price'];
- $param['xianshigoods_price'] = $xianshi_price;
- $param['goods_image'] = $goods_info['goods_image'];
- $param['xianshigoods_starttime'] = $xianshi_info['xianshi_starttime'];
- $param['xianshigoods_end_time'] = $xianshi_info['xianshi_end_time'];
- $param['xianshigoods_lower_limit'] = $xianshi_info['xianshi_lower_limit'];
- $result = array();
- $xianshigoods_info = $xianshigoods_model->addXianshigoods($param);
- if ($xianshigoods_info) {
- $result['result'] = true;
- $data['message'] = lang('add_success');
- $data['xianshi_goods'] = $xianshigoods_info;
- // 自动发布动态
- // goods_id,store_id,goods_name,goods_image,goods_price,goods_freight,xianshi_price
- $data_array = array();
- $data_array['goods_id'] = $goods_info['goods_id'];
- $data_array['store_id'] = session('store_id');
- $data_array['goods_name'] = $goods_info['goods_name'];
- $data_array['goods_image'] = $goods_info['goods_image'];
- $data_array['goods_price'] = $goods_info['goods_price'];
- $data_array['goods_freight'] = $goods_info['goods_freight'];
- $data_array['xianshigoods_price'] = $xianshi_price;
- $this->storeAutoShare($data_array, 'xianshi');
- $this->recordSellerlog(lang('add_limited_time_discount_items') . $xianshi_info['xianshi_name'] . ',' . lang('goods_name') . ':' . $goods_info['goods_name']);
- // 添加任务计划
- $this->addcron(array('cron_type' => 'updateGoodsPromotionPriceByGoodsId', 'cron_value' => serialize($goods_info['goods_id']), 'cron_exetime' => $param['xianshigoods_starttime']));
- } else {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- }
- echo json_encode($data);
- die;
- }
- /**
- * 秒杀商品价格修改
- * */
- public function xianshi_goods_price_edit()
- {
- $xianshigoods_id = intval(input('post.xianshigoods_id'));
- $xianshi_price = floatval(input('post.xianshi_price'));
- $data = array();
- $data['result'] = true;
- $xianshigoods_model = model('pxianshigoods');
- $xianshigoods_info = $xianshigoods_model->getXianshigoodsInfoByID($xianshigoods_id, session('store_id'));
- if (!$xianshigoods_info) {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- echo json_encode($data);
- die;
- }
- $update = array();
- $update['xianshigoods_price'] = $xianshi_price;
- $condition = array();
- $condition[] = array('xianshigoods_id', '=', $xianshigoods_id);
- $result = $xianshigoods_model->editXianshigoods($update, $condition);
- if ($result) {
- $xianshigoods_info['xianshigoods_price'] = $xianshi_price;
- $xianshigoods_info = $xianshigoods_model->getXianshigoodsExtendInfo($xianshigoods_info);
- $data['xianshi_price'] = $xianshigoods_info['xianshigoods_price'];
- $data['xianshi_discount'] = $xianshigoods_info['xianshi_discount'];
- // 添加对列修改商品促销价格
- model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'updateGoodsPromotionPriceByGoodsId', 'cron_value' => serialize($xianshigoods_info['goods_id'])));
- $this->recordSellerlog(lang('limited_time_discount_price_modified') . $xianshigoods_info['xianshigoods_price'] . ',' . lang('goods_name') . ':' . $xianshigoods_info['goods_name']);
- } else {
- $data['result'] = false;
- $data['message'] = lang('ds_common_op_succ');
- }
- echo json_encode($data);
- die;
- }
- /**
- * 秒杀商品删除
- * */
- public function xianshi_goods_delete()
- {
- $xianshigoods_model = model('pxianshigoods');
- $pxianshi_model = model('pxianshi');
- $data = array();
- $data['result'] = true;
- $xianshigoods_id = intval(input('post.xianshigoods_id'));
- $xianshigoods_info = $xianshigoods_model->getXianshigoodsInfoByID($xianshigoods_id);
- if (!$xianshigoods_info) {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- echo json_encode($data);
- die;
- }
- $xianshi_info = $pxianshi_model->getXianshiInfoByID($xianshigoods_info['xianshi_id'], session('store_id'));
- if (!$xianshi_info) {
- $data['result'] = false;
- $data['message'] = lang('param_error');
- echo json_encode($data);
- die;
- }
- if (!$xianshigoods_model->delXianshigoods(array('xianshigoods_id' => $xianshigoods_id))) {
- $data['result'] = false;
- $data['message'] = lang('xianshi_goods_delete_fail');
- echo json_encode($data);
- die;
- }
- // 添加对列修改商品促销价格
- model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'updateGoodsPromotionPriceByGoodsId', 'cron_value' => serialize($xianshigoods_info['goods_id'])));
- $this->recordSellerlog(lang('delete_time_limited_discount_items') . $xianshi_info['xianshi_name'] . ',' . lang('goods_name') . ':' . $xianshigoods_info['goods_name']);
- echo json_encode($data);
- die;
- }
- /**
- * 用户中心右边,小导航
- *
- * @param string $menu_type 导航类型
- * @param string $name 当前导航的name
- * @param array $array 附加菜单
- * @return
- */
- protected function getSellerItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'xianshi_list', 'text' => lang('promotion_active_list'),
- 'url' => (string) url('Sellerpromotionxianshi/index')
- ),
- );
- switch (request()->action()) {
- case 'xianshi_add':
- $menu_array[] = array(
- 'name' => 'xianshi_add', 'text' => lang('promotion_join_active'),
- 'url' => (string) url('Sellerpromotionxianshi/xianshi_add')
- );
- break;
- case 'xianshi_edit':
- $menu_array[] = array(
- 'name' => 'xianshi_edit', 'text' => lang('editing_activity'), 'url' => 'javascript:;'
- );
- break;
- case 'xianshi_quota_add':
- $menu_array[] = array(
- 'name' => 'xianshi_quota_add', 'text' => lang('promotion_buy_product'),
- 'url' => (string) url('Sellerpromotionxianshi/xianshi_quota_add')
- );
- break;
- case 'xianshi_manage':
- $menu_array[] = array(
- 'name' => 'xianshi_manage', 'text' => lang('promotion_goods_manage'),
- 'url' => (string) url('Sellerpromotionxianshi/xianshi_manage', ['xianshi_id' => input('param.xianshi_id')])
- );
- break;
- }
- return $menu_array;
- }
- }
|