123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <?php
- /**
- * Created by PhpStorm.
- * User: songlintao
- * Date: 2017/9/25
- * Time: 下午3:30
- */
- defined( 'InShopNC' ) or exit( 'Access Invalid!' );
- require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
- require_once(BASE_ROOT_PATH . '/helper/fcode/operator.php');
- use user_session\storage;
- class festvalControl extends mobileControl
- {
- const RELATIVE_UPLOAD = "/upfile";
- const UPFILE_PATH = BASE_UPLOAD_PATH . self::RELATIVE_UPLOAD;
- private $mod_activity_image;
- public function __construct() {
- parent::__construct();
- $this->mod_activity_image = Model('activity_image');
- }
- private $qixiConfig = [
- // 0 => ["common_id"=>2778,"batch_code"=>"HSDX01","goods_name"=>"唇油"],//131
- // 0 => ["common_id"=> 1111,"batch_code"=>"QXHD01","goods_name"=>"卸妆水"],
- // 1 => ["common_id"=>3400,"batch_code"=>"HSDX01","goods_name"=>"唇油"],
- 0 => ["common_id"=>7120,"batch_code"=>"QXHD03","goods_name"=>"唇油"],//兰芝 水润绚彩染唇油
- 1 => ["common_id"=>7848,"batch_code"=>"QXHD01","goods_name"=>"卸妆水"],//美宝莲 净澈多效卸妆水
- 2 => ["common_id"=>7844,"batch_code"=>"QXHD04","goods_name"=>"喷雾"],// Fa清香亚麻喷雾
- 3 => ["common_id"=>8041,"batch_code"=>"QXHD02","goods_name"=>"香皂"],// 安宝笛 鸢尾花味香皂
- ];
- public function qixiOp()
- {
- if(session_helper::need_wechat_author())
- {
- $author = new thrid_author\wxauthor();
- $url = urlencode(BASE_SITE_URL . "/mobile/index.php?act=festval&op=qixi");
- $url = $author->enter($url);
- return self::outsuccess(['direct_uri' => $url],"redirect");
- }
- $begin = strtotime("2018-08-14");
- $end = strtotime("2018-08-18");
- if($this->activity_validate($begin,$end)){
- return self::outsuccess(null,'festival/TanabataFestival/index');
- }else{
- return self::outsuccess(null,'festival/end/index');
- }
- }
- private function activity_validate($begin,$end)
- {
- $now = time();
- return ($now >= $begin && $now < $end);
- }
- public function getAwardOp()
- {
- $memberid = session_helper::memberid();
- if($memberid<=0) {
- return self::outerr(errcode::ErrUnLogin,"用户需要登陆");
- };
- $minfo = new member_info($memberid);
- $moblie = $minfo->mobile();
- $sid = session_id();
- $get = false;
- $grabed = false;
- $name = "";
- $qixiConf = $this->qixiConfig;
- foreach ($qixiConf as $key => $item)
- {
- $command_id = $item['common_id'];
- $batch_code = $item['batch_code'];
- $goods_name = $item['goods_name'];
- $oper = new fcode\operator($command_id,$batch_code,$moblie,$sid);
- $fcode = $oper->grabed();
- if($fcode) {
- $grabed = true;
- $name = $goods_name;
- $get = true;
- break;
- }
- $fcode = $oper->grab();
- if($fcode)
- {
- $res = $oper->bind($fcode);
- if($res){
- $name = $goods_name;
- $get = true;
- break;
- }
- }
- }
- if($get) {
- return self::outsuccess(["grabed"=>$grabed,"goods_name"=>$name]);
- } else {
- return self::outerr(errcode::ErrGoodsOutofStock,"七夕活动的奖品已被抽完咯,关注熊猫不要错过下次哦");
- }
- }
- public function indexOp()
- {
- $this->topup();
- $url = BASE_SITE_URL . "/hfive/festval/index.html";
- if(session_helper::need_wechat_author())
- {
- $author = new thrid_author\wxauthor();
- $url = $author->enter($url);
- }
- return self::outsuccess(['direct_uri' => $url],"redirect");
- }
- private function from_base64($base_input, &$file_name)
- {
- if(empty($base_input)) {
- return false;
- }
- $regx = '/^(data:\s*image\/(\w+);base64,)/';
- if (preg_match($regx, $base_input, $result))
- {
- $file_type = $result[2];
- $content = str_replace( $result[1], '', $base_input);
- $file_name = md5($content) .'.'. $file_type;
- return base64_decode($content);
- } else {
- return false;
- }
- }
- function add_imageOp()
- {
- $image_content = $this->from_base64($_POST['image_data'],$file_name);
- $act_id = intval($_POST['act_id']);
- if ($image_content == false || $act_id <= 0) {
- return self::outerr( errcode::ErrParamter, "参数错误", "festval/error" );
- }
- $file_path = self::UPFILE_PATH . "/{$file_name}";
- if(file_put_contents($file_path,$image_content) == false) {
- return self::outerr( errcode::ErrParamter, "保存文件失败", "festval/error" );
- }
- $datas = [];
- {
- if(session_helper::logined()) {
- $datas['member_id'] = session_helper::memberid();
- } else {
- $datas['member_id'] = 0;
- }
- if(session_helper::unionid() != false) {
- $datas['unionid'] = session_helper::unionid();
- } else {
- $datas['unionid'] = "";
- }
- $datas['act_id'] = $act_id;
- $datas['image_path'] = self::RELATIVE_UPLOAD . "/" . $file_name;
- $datas['add_time'] = time();
- $datas['likes'] = 0;
- }
- $ret = $this->mod_activity_image->insert($datas);
- if($ret > 0) {
- return self::outsuccess(null);
- } else {
- return self::outerr( errcode::ErrParamter, "保存文件失败", "festval/error" );
- }
- }
- function likeOp()
- {
- $act_id = $_GET['act_id'];
- $image_id = $_GET['image_id'];
- if($act_id < 0 || $image_id < 0) {
- return self::outerr(errcode::ErrParamter,"参数错误");
- }
- $supporter = new festval_support($act_id,$image_id);
- if($supporter->supported()) {
- $supporter->unsupport();
- $supported = false;
- } else {
- $supporter->support();
- $supported = true;
- }
- $ret = $this->mod_activity_image->likes($image_id,true);
- return self::outsuccess(['supported' => $supported,'likes' => intval($ret['likes'])]);
- }
- function listOp()
- {
- $act_id = intval($_POST['act_id']);
- if ($act_id <= 0) {
- return self::outerr( errcode::ErrParamter, "参数错误", "festval/error" );
- }
- $items = $this->mod_activity_image->image_list(['act_id' => $act_id],'*',$this->page_size());
- $pages = $this->mod_activity_image->gettotalpage();
- $result = [];
- foreach ($items as $item) {
- $result[] = $this->format($item);
- }
- return self::outsuccess(['blocks' => $result,'mobile_page' => mobile_page($pages)]);
- }
- private function format($item)
- {
- $result = [];
- $image_id = intval($item['image_id']);
- $act_id = intval($item['act_id']);
- $result['image_id'] = $image_id;
- $supporter = new festval_support($act_id,$image_id);
- $result['supported'] = $supporter->supported();
- $result['act_id'] = $item['act_id'];
- $result['member_id'] = $item['member_id'];
- $result['image'] = $this->img_url($item['image_path']);
- $result['likes'] = intval($item['likes']);
- $result['add_time'] = intval($item['add_time']);
- return $result;
- }
- private function img_url($path)
- {
- if(strncasecmp($path,"http://",strlen("http://")) == 0) {
- $url = $path;
- } else {
- $url = UPLOAD_SITE_URL . $path;
- }
- return $url;
- }
- private function topup()
- {
- if(session_helper::logined()) {
- $pred = new predeposit_helper($_SESSION['member_id'],true);
- $pred->topup_bonus($_SESSION['member_mobile']);
- }
- }
- }
- class festval_support extends storage
- {
- private $act_id;
- private $image_id;
- public function __construct($act_id, $image_id)
- {
- $this->act_id = intval($act_id);
- $this->image_id = intval($image_id);
- parent::__construct();
- }
- public function is_act() {
- return ($this->act_id > 0 && $this->image_id <= 0);
- }
- public function limit_type()
- {
- return storage::NORMAL_SUPPORT;
- }
- public function storage_tag()
- {
- if($this->is_act()) {
- return "festval_support";
- } else {
- return "festval_image_{$this->act_id}";
- }
- }
- public function supported()
- {
- if($this->is_act()) {
- return parent::base_supported($this->act_id);
- } else {
- return parent::base_supported($this->image_id);
- }
- }
- public function support()
- {
- if($this->is_act())
- {
- $ret = parent::base_support($this->act_id);
- if($ret) {
- $this->add_act_likes();
- }
- }
- else
- {
- $ret = parent::base_support($this->image_id);
- if($ret) {
- $this->add_image_likes();
- }
- }
- return $ret;
- }
- public function unsupport()
- {
- if($this->is_act())
- {
- $ret = parent::base_unsupport($this->act_id);
- if($ret) {
- $this->sub_act_likes();
- }
- }
- else
- {
- $ret = parent::base_unsupport($this->image_id);
- if($ret) {
- $this->sub_image_likes();
- }
- }
- return $ret;
- }
- private function add_act_likes()
- {
- }
- private function sub_act_likes()
- {
- }
- private function add_image_likes()
- {
- $mod_image = Model('activity_image');
- $mod_image->where(['image_id' => $this->image_id])->update([ 'likes' => ['exp', 'likes + 1'] ]);
- }
- private function sub_image_likes()
- {
- $mod_image = Model('activity_image');
- $mod_image->where(['image_id' => $this->image_id])->update([ 'likes' => ['exp', 'likes - 1'] ]);
- }
- }
|