Parcourir la source

add festval action

stanley-king il y a 7 ans
Parent
commit
1a6cc28278

+ 24 - 0
data/model/activity_image.model.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/9/26
+ * Time: 上午11:17
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+class activity_imageModel extends Model
+{
+    public function __construct()
+    {
+        parent::__construct('activity_image');
+    }
+    public function image_list($cond,$field='*',$page_size = 0,$total_count = 0,$lock = false)
+    {
+        return $this->field($field)->where($cond)->order('image_id desc')->page($page_size, $total_count)->lock($lock)->select();
+    }
+    public function likes($image_id)
+    {
+        return $this->field('likes')->find($image_id);
+    }
+}

+ 5 - 5
helper/ugc/answer.php

@@ -18,10 +18,10 @@ class special_support extends storage
     private $special_id;
     private $comment_id;
 
-    public function __construct($special_id,$comment_id)
+    public function __construct($act_id, $image_id)
     {
-        $this->special_id = intval($special_id);
-        $this->comment_id = intval($comment_id);
+        $this->special_id = intval($act_id);
+        $this->comment_id = intval($image_id);
 
         parent::__construct();
     }
@@ -113,9 +113,9 @@ class special_submitor extends storage
 {
     private $special_id;
     private $vote_single;
-    public function __construct($special_id,$vote_single)
+    public function __construct($act_id, $vote_single)
     {
-        $this->special_id = $special_id;
+        $this->special_id = $act_id;
         if($vote_single) {
             $this->vote_single = storage::NORMAL_SUPPORT;
         } else {

+ 66 - 0
helper/upload/uploader.php

@@ -0,0 +1,66 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/9/26
+ * Time: 上午11:06
+ */
+
+class uploader
+{
+    public function upfileOp()
+    {
+        $file_path = $this->file_path();
+        $member_id = $_SESSION['member_id'];
+        $file_name = $this->upfile($file_path,$err);
+        if($file_name == false) {
+            return self::outerr(errcode::ErrUploadFileFailed);
+        }
+        $file_path = DS.$member_id.DS.$file_name;
+        $ret = Model("member")->editMember(array('member_id' => $member_id),array('member_avatar' => $file_path));
+        if ($ret) {
+            $_SESSION['member_avatar'] = $file_path;
+            $url = UPLOAD_SITE_URL . "/shop/avatar{$file_path}";
+            return self::outsuccess(array('member_avatar' => $url));
+        } else {
+            return self::outerr(errcode::ErrDB);
+        }
+    }
+
+    private function upfile($img,&$err)
+    {
+        $member_id = $_SESSION['member_id'];
+
+        $upload = new FileUploader();
+        if($upload->init_files($img,$member_id,$err) == false) {
+            return false;
+        }
+
+        $upload_dir = ATTACH_AVATAR.DS.$member_id.DS;
+        $upload->set('default_dir',$upload_dir.$upload->getSysSetPath());
+        $thumb_width	= '480,1024';
+        $thumb_height	= '480,1024';
+
+        $upload->set('max_size',C('image_max_filesize'));
+        $upload->set('thumb_width', $thumb_width);
+        $upload->set('thumb_height',$thumb_height);
+        $upload->set('fprefix',$member_id);
+        $upload->set('thumb_ext', '_240,_1024');
+        $result = $upload->upfile('file');
+        if($result == true) {
+            return $upload->file_name;
+        } else {
+            $err = array('code' => errcode::ErrUpfile, 'msg' => $upload->error);
+            return false;
+        }
+    }
+
+    private function file_path()
+    {
+        $file_path = $_POST["file_path"];
+        if(file_exists($file_path) == false) {
+            $file_path = BASE_ROOT_PATH . '/data/upload/upfile' . $file_path;
+        }
+        return $file_path;
+    }
+}

+ 241 - 0
mobile/control/festival.php

@@ -0,0 +1,241 @@
+<?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');
+
+use user_session\storage;
+
+class festivalControl 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 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 submitOp()
+    {
+		$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 festival_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);
+        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 festival_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;
+    }
+}
+
+class festival_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 "festival_support";
+        } else {
+            return "festival_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'] ]);
+    }
+}

+ 0 - 169
mobile/control/h5_zhongqiu.php

@@ -1,169 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: songlintao
- * Date: 2017/9/25
- * Time: 下午3:30
- */
-defined( 'InShopNC' ) or exit( 'Access Invalid!' );
-
-class h5_zhongqiuControl extends mobileControl {
-	/**
-	 * @var null|ZhongqiuModel
-	 */
-	protected $model = null;
-
-	public function __construct() {
-		parent::__construct();
-		$this->model = new ZhongqiuModel();
-	}
-
-
-	function submitOp() {
-		$memberId             = session_helper::memberid();
-		$base64_image_content = $_POST['image_data'];
-		if ( ! isset( $base64_image_content ) ) {
-			return self::outerr( errcode::ErrParamter, "参数错误", "h5_zhongqiu/error" );
-		}
-		$filePath = $this->saveFile( $base64_image_content );
-		if ( $filePath ) {
-			$db_status = $this->saveDb( $memberId, $filePath );
-			if ( $db_status ) {
-				self::outsuccess( array( 'result' => '0' ) );
-			} else {
-				return self::outerr( errcode::ErrParamter, "数据库保存失败", "h5_zhongqiu/error" );
-			}
-		} else {
-			return self::outerr( errcode::ErrParamter, "保存文件失败", "h5_zhongqiu/error" );
-		}
-
-		return '';
-	}
-
-	function likeOp() {
-		$id = $_GET['id'];
-		if ( ! isset( $id ) ) {
-			return self::outerr( errcode::ErrParamter, "参数错误", "h5_zhongqiu/error" );
-		}
-		$status = $this->model->like( $id );
-		if ( $status ) {
-			self::outsuccess( array( 'result' => $status ) );
-		} else {
-			return self::outerr( errcode::ErrParamter, "保存文件失败", "h5_zhongqiu/error" );
-		}
-
-		return '';
-	}
-
-	function listOp() {
-		$page     = $_GET['page'];
-		$pageSize = $_GET['pageSize'];
-		if ( $page < 1 || $pageSize < 1 ) {
-			return self::outerr( errcode::ErrParamter, "page或者pageSize小于1", "h5_zhongqiu/error" );
-		}
-		$datas = $this->model->getList( $page, $pageSize );
-		if ( $datas ) {
-			$datas = array_map( function ( $item ) {
-				$likeList      = $_SESSION['likedList'];
-				$liked         = isset( $likeList ) && in_array( $item['id'], $likeList );
-				$item['liked'] = $liked;
-
-				return $item;
-			}, $datas );
-			self::outsuccess( $datas );
-		} else {
-			return self::outerr( errcode::ErrParamter, "未知错误", "h5_zhongqiu/error" );
-		}
-
-		return '';
-	}
-
-	private function saveFile( $upload_file ) {
-		if ( preg_match( '/^(data:\s*image\/(\w+);base64,)/', $upload_file, $result ) ) {
-			$type     = $result[2];
-			$new_file = BASE_DATA_PATH . "/upload/h5/zhongqiu/";
-			if ( ! file_exists( $new_file ) ) {
-				//检查是否有该文件夹,如果没有就创建,并给予最高权限
-				mkdir( $new_file, 0700 );
-			}
-			$new_file = $new_file . $this->getUUID() . ".{$type}";
-			if ( file_put_contents( $new_file, base64_decode( str_replace( $result[1], '', $upload_file ) ) ) ) {
-				return str_replace( BASE_ROOT_PATH, '', $new_file );
-			} else {
-				return false;
-			}
-		} else {
-			return false;
-		}
-	}
-
-	private function saveDb( $memberId, $filePath ) {
-		return $this->model->insertOne( $memberId, $filePath );
-	}
-
-
-	private function getUUID() {
-		if ( function_exists( 'com_create_guid' ) ) {
-			return com_create_guid();
-		} else {
-			mt_srand( (double) microtime() * 10000 );
-			$charid = strtoupper( md5( uniqid( rand(), true ) ) );
-			$hyphen = chr( 45 );
-			$uuid   = ""
-			          . substr( $charid, 0, 8 ) . $hyphen
-			          . substr( $charid, 8, 4 ) . $hyphen
-			          . substr( $charid, 12, 4 ) . $hyphen
-			          . substr( $charid, 16, 4 ) . $hyphen
-			          . substr( $charid, 20, 12 );
-
-			return $uuid;
-		}
-	}
-}
-
-class ZhongqiuModel extends Model {
-	public function __construct() {
-		parent::__construct( "h5_zhongqiu" );
-	}
-
-	function insertOne( $member_id, $image ) {
-		return $this->insert( array(
-			'member_id' => $member_id,
-			'image'     => str_replace( BASE_ROOT_PATH, '', $image ),
-		) );
-	}
-
-	function like( $id ) {
-		$data = $this->find( $id );
-		if ( $data ) {
-			$likeList  = $_SESSION['likedList'];
-			$likeCount = $data['like'];
-			if ( ! isset( $likeList ) || in_array( $id, $likeList ) ) {
-				//点赞
-				$likeCount ++;
-				if ( ! isset( $likeList ) ) {
-					$_SESSION['likedList'] = array($id);
-				} else {
-					array_push($_SESSION['likedList'], $id );
-				}
-			} else {
-				//取消点赞
-				$likeCount --;
-			}
-			$this->update( array( 'like' => $likeCount ) );
-
-			return $likeCount;
-		} else {
-			return false;
-		}
-	}
-
-	function getList( $page, $pageSize ) {
-		$start = ( $page - 1 ) * $pageSize;
-		$end   = $page * $pageSize - 1;
-
-		/** @noinspection PhpUndefinedMethodInspection */
-		return $this->limit( $start, $end )->select();
-	}
-
-}

+ 0 - 49
mobile/control/shop.php

@@ -1,49 +0,0 @@
-<?php
-/**
- * 所有店铺首页 好商城v3 33hao.com
- */
-
-//use shopnc\Tpl;
-
-defined('InShopNC') or exit('Access Invalid!');
-
-
-class shopControl extends mobileHomeControl {
-
-    public function __construct(){
-        parent::__construct();
-    }
-
-    /*
-     * 首页显示
-     */
-    public function indexOp(){
-        $this->_get_Own_Store_List();
-    }
-
-
-    private  function  _get_Own_Store_List(){
-
-        //获取自营店列表
-        $model_store = Model("store");
-	//如果只想显示自营店铺,把下面的//去掉即可
-        //$condition = array(
-         //   'is_own_shop' => 1,
-        //);
-
-        $own_store_list = $model_store->getStoreList($condition);
-
-        $simply_store_list = array();
-
-        foreach ($own_store_list as $key => $value) {
-
-            $simply_store_list[$key]['store_id'] = $own_store_list[$key]['store_id'];
-            $simply_store_list[$key]['store_name'] = $own_store_list[$key]['store_name'];
-            $simply_store_list[$key]['store_address'] = $own_store_list[$key]['store_address'];
-            $simply_store_list[$key]['store_area_info'] = $own_store_list[$key]['area_info'];
-
-        }
-
-        output_data(array('store_list' => $simply_store_list));
-    }
-}

+ 0 - 24
mobile/control/store.php

@@ -1,24 +0,0 @@
-<?php
-/**
- * 商品
- *
- *
- *
- */
-defined('InShopNC') or exit('Access Invalid!');
-
-class storeControl extends mobileHomeControl
-{
-	public function __construct() {
-        parent::__construct();
-    }
-
-    public function groupbuysOp()
-    {
-
-    }
-    public function fullsentsOp()
-    {
-
-    }
-}

+ 0 - 80
mobile/control/type.php

@@ -1,80 +0,0 @@
-<?php
-/**
- * 前台品牌分类
- *
- *
- *
- ***/
-
-
-defined('InShopNC') or exit('Access Invalid!');
-
-class typeControl extends mobileHomeControl
-{
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    /**
-     * 关键字获取类型
-     * 输入参数:
-     * id: 需要返回
-     * keyword: 关键字
-     */
-    public function searchOp()
-    {
-        $id = $_GET['id'];
-        if (!empty($_GET['keyword'])) {
-            $keyword = urldecode($_GET['keyword']);
-            $gc_1 = Model()->table('goods_class')->where(array('gc_name' => array('like', '%' . $keyword . '%')))->limit(1)->select();
-            $goods_class = array();
-            if (!empty($gc_1)) {
-                $gc_2 = Model()->table('goods_class')->where(array('gc_parent_id' => $gc_1[0]['gc_id']))->select();
-                foreach ($gc_2 as $value) {
-                    $gc_item_2['gc_id'] = $value['gc_id'];
-                    $gc_item_2['gc_name'] = $value['gc_name'];
-                    $gc_3 = Model()->table('goods_class')->where(array('gc_parent_id' => $value['gc_id']))->select();
-                    if (!empty($gc_3)) {
-                        $gc_3_array = array();
-                        foreach ($gc_3 as $item) {
-                            $gc_3_item['gc_id'] = $item['gc_id'];
-                            $gc_3_item['gc_name'] = $item['gc_name'];
-                            $gc_3_item['type_id'] = $item['type_id'];
-                            array_push($gc_3_array, $gc_3_item);
-                        }
-                        $gc_item_2['data'] = $gc_3_array;
-                        array_push($goods_class, $gc_item_2);
-                    }
-                }
-            }
-            joutput_data(array("data" => $goods_class, "id" => $id));
-        } else {
-            return joutput_error(1001, "keyword is must!");
-        }
-    }
-
-    /**
-     * 通过gc_id获取类型
-     * 输入参数:
-     * id: 需要传回参数
-     * gc_id: 用户组类型
-     */
-    public function typeBygcidOp()
-    {
-        $id = $_GET['id'];
-        $gc_id = $_GET['gc_id'];
-        if (!empty($gc_id)) {
-            $gc_2 = Model()->table('goods_class')->where(array('gc_parent_id' => $gc_id))->select();
-            $gc_2_array = array();
-            foreach ($gc_2 as $value) {
-                $gc_item_2['gc_id'] = $value['gc_id'];
-                $gc_item_2['gc_name'] = $value['gc_name'];
-                array_push($gc_2_array, $gc_item_2);
-            }
-            joutput_data(array("data" => $gc_2_array, "id" => $id));
-        } else {
-            return joutput_error(1001, "gc_id is must!");
-        }
-    }
-}

+ 0 - 23
mobile/control/ugc.php

@@ -1,23 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/7/20
- * Time: 下午7:02
- */
-
-defined('InShopNC') or exit('Access Invalid!');
-
-class ugcControl extends mobileHomeControl
-{
-    public function __construct()
-    {
-        parent::__construct();
-    }
-
-    public function openOp()
-    {
-        $special_id = intval($_GET['special_id']);
-
-    }
-}

+ 29 - 0
mobile/control/uploader.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/9/26
+ * Time: 上午11:19
+ */
+
+require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
+require_once (BASE_ROOT_PATH . '/helper/login_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/session_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/sms_helper.php');
+
+class uploaderControl extends mobileControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function __destruct()
+    {
+        parent::__destruct(); // TODO: Change the autogenerated stub
+    }
+    public function upfileOp()
+    {
+
+    }
+}

Fichier diff supprimé car celui-ci est trop grand
+ 19 - 1
test/TestUGC.php