diff --git a/application/index.html b/application/index.html
deleted file mode 100644
index e69de29b..00000000
diff --git a/application/routine/common.php b/application/routine/common.php
deleted file mode 100644
index c9ec2ab5..00000000
--- a/application/routine/common.php
+++ /dev/null
@@ -1,182 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-// 应用公共文件
-if(!function_exists('unThumb')){
- function unThumb($src){
- return str_replace('/s_','/',$src);
- }
-}
-/**
-*判断拼团是否结束*/
-function isPinkStatus($pink){
- if(!$pink) return false;
- return \app\wap\model\store\StorePink::isSetPinkOver($pink);
-}
-
-/**
- * 设置浏览信息
- * @param $uid
- * @param int $product_id
- * @param int $cate
- * @param string $type
- * @param string $content
- * @param int $min
- */
-function setView($uid,$product_id=0,$cate=0,$type='',$content='',$min=20){
- $Db=think\Db::name('store_visit');
- $view=$Db->where(['uid'=>$uid,'product_id'=>$product_id])->field('count,add_time,id')->find();
- if($view && $type!='search'){
- $time=time();
- if(($view['add_time']+$min)<$time){
- $Db->where(['id'=>$view['id']])->update(['count'=>$view['count']+1,'add_time'=>time()]);
- }
- }else{
- $cate = explode(',',$cate)[0];
- $Db->insert([
- 'add_time'=>time(),
- 'count'=>1,
- 'product_id'=>$product_id,
- 'cate_id'=>$cate,
- 'type'=>$type,
- 'uid'=>$uid,
- 'content'=>$content
- ]);
- }
-}
-
-/**
- * 创建海报图片
- * @param array $product
- * @return bool|string
- */
-function createPoster($product = array()){
- header("Content-type: image/jpg");
- $filePath = 'public/uploads/poster/'.time().'.jpg';
- $dir = iconv("UTF-8", "GBK", "public/uploads/poster");
- if(!file_exists($dir)) mkdir($dir,0775,true);
- $config = array(
- 'text'=>array(
- array(
- 'text'=>substr(iconv_substr($product['store_name'],0,mb_strlen($product['store_name']),'utf-8'),0,24).'...',
- 'left'=>50,
- 'top'=>500,
- 'fontPath'=>ROOT_PATH.'public/static/font/simsunb.ttf', //字体文件
- 'fontSize'=>16, //字号
- 'fontColor'=>'40,40,40', //字体颜色
- 'angle'=>0,
- ),
- array(
- 'text'=>'¥'.$product['price'],
- 'left'=>50,
- 'top'=>580,
- 'fontPath'=>ROOT_PATH.'public/static/font/simsunb.ttf', //字体文件
- 'fontSize'=>16, //字号
- 'fontColor'=>'40,40,40', //字体颜色
- 'angle'=>0,
- )
- ),
- 'image'=>array(
- array(
- 'url'=>$product['image'],
- 'left'=>50,
- 'top'=>70,
- 'right'=>0,
- 'stream'=>0,
- 'bottom'=>0,
- 'width'=>350,
- 'height'=>350,
- 'opacity'=>100,
- ),
- array(
- 'url'=>$product['code_path'],
- 'left'=>250,
- 'top'=>480,
- 'right'=>0,
- 'stream'=>0,
- 'bottom'=>0,
- 'width'=>160,
- 'height'=>180,
- 'opacity'=>100,
- ),
- ),
- 'background'=>ROOT_PATH.UPLOAD_PATH.'/poster/background.jpg' //背景图
- );
- $imageDefault = array(
- 'left'=>0,
- 'top'=>0,
- 'right'=>0,
- 'bottom'=>0,
- 'width'=>100,
- 'height'=>100,
- 'opacity'=>100
- );
- $textDefault = array(
- 'text'=>'2222222222',
- 'left'=>0,
- 'top'=>0,
- 'fontSize'=>32, //字号
- 'fontColor'=>'255,255,255', //字体颜色
- 'angle'=>0,
- );
- $background = $config['background'];//海报最底层得背景
- //背景方法
- $backgroundInfo = getimagesize($background);
- $backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
- $background = $backgroundFun($background);
- // $backgroundWidth = imagesx($background); //背景宽度
- // $backgroundHeight = imagesy($background); //背景高度
- $backgroundWidth = 460; //背景宽度
- $backgroundHeight = 700; //背景高度
- $imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);
- $color = imagecolorallocate($imageRes, 0, 0, 0);
- imagefill($imageRes, 0, 0, $color);
- // imageColorTransparent($imageRes, $color); //颜色透明
- imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background)); //处理了图片
- if(!empty($config['image'])){
- foreach ($config['image'] as $key => $val) {
- $val = array_merge($imageDefault,$val);
- $info = getimagesize($val['url']);
- $function = 'imagecreatefrom'.image_type_to_extension($info[2], false);
- if($val['stream']){ //如果传的是字符串图像流
- $info = getimagesizefromstring($val['url']);
- $function = 'imagecreatefromstring';
- }
- $res = $function($val['url']);
- $resWidth = $info[0];
- $resHeight = $info[1];
- //建立画板 ,缩放图片至指定尺寸
- $canvas=imagecreatetruecolor($val['width'], $val['height']);
- imagefill($canvas, 0, 0, $color);
- //关键函数,参数(目标资源,源,目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h)
- imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight);
- $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']) - $val['width']:$val['left'];
- $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']) - $val['height']:$val['top'];
- //放置图像
- imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);//左,上,右,下,宽度,高度,透明度
- } }
- //处理文字
- if(!empty($config['text'])){
- foreach ($config['text'] as $key => $val) {
- $val = array_merge($textDefault,$val);
- list($R,$G,$B) = explode(',', $val['fontColor']);
- $fontColor = imagecolorallocate($imageRes, $R, $G, $B);
- $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']):$val['left'];
- $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']):$val['top'];
- imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,$val['fontPath'],$val['text']);
- }
- }
- //生成图片
- $res = imagejpeg ($imageRes,$filePath,90); //保存到本地
- imagedestroy($imageRes);
- if(!$res) return false;
- return $filePath;
-}
\ No newline at end of file
diff --git a/application/routine/config.php b/application/routine/config.php
deleted file mode 100644
index 8e8af14a..00000000
--- a/application/routine/config.php
+++ /dev/null
@@ -1,22 +0,0 @@
-
-// +----------------------------------------------------------------------
-
-
-return [
- 'session' => [
- // SESSION 前缀
- 'prefix' => 'routine',
- // 驱动方式 支持redis memcache memcached
- 'type' => '',
- // 是否自动开启 SESSION
- 'auto_start' => true,
- ],
-];
diff --git a/application/routine/controller/AuthApi.php b/application/routine/controller/AuthApi.php
deleted file mode 100644
index 318d6305..00000000
--- a/application/routine/controller/AuthApi.php
+++ /dev/null
@@ -1,2032 +0,0 @@
-userInfo);
- }
-
- /**
- * 获取退款理由
- */
- public function get_refund_reason(){
- $reason = SystemConfig::getValue('stor_reason')?:[];//退款理由
- $reason = str_replace("\r\n","\n",$reason);//防止不兼容
- $reason = explode("\n",$reason);
- return JsonService::successful($reason);
- }
-
- /**
- * 获取提现银行
- */
- public function get_user_extract_bank(){
- $extractBank = SystemConfig::getValue('user_extract_bank')?:[];//提现银行
- $extractBank = explode('=',$extractBank);
- return JsonService::successful($extractBank);
- }
- /**
- * 首页
- */
- public function index(){
- $banner = GroupDataService::getData('routine_home_banner')?:[];//banner图
- $menus = GroupDataService::getData('routine_home_menus')?:[];//banner图
- $lovely = GroupDataService::getData('routine_lovely')?:[];//猜你喜欢图
- $best = StoreProduct::getBestProduct('id,image,store_name,cate_id,price,unit_name,sort',8);//精品推荐
- $new = StoreProduct::getNewProduct('id,image,store_name,cate_id,price,unit_name,sort',3);//今日上新
- $hot = StoreProduct::getHotProduct('id,image,store_name,cate_id,price,unit_name,sort',6);//猜你喜欢
- $data['banner'] = $banner;
- $data['lovely'] = $lovely[0];
- $data['menus'] = $menus;
- $data['best'] = $best;
- $data['new'] = $new;
- $data['hot'] = $hot;
- return JsonService::successful($data);
- }
-
- /**
- * 猜你喜欢 加载
- * @param Request $request
- */
- public function get_hot_product(Request $request){
- $data = UtilService::postMore([['offset',0],['limit',0]],$request);
- $hot = StoreProduct::getHotProductLoading('id,image,store_name,cate_id,price,unit_name,sort',$data['offset'],$data['limit']);//猜你喜欢
- return JsonService::successful($hot);
- }
- /**
- * 分类搜索页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function store(){
- $model = StoreProduct::validWhere();
- if($_GET){$data = $_GET['value'];
- if($data!=''){
- $model = $model->where('store_name','LIKE',"%$data%")->whereOr('keyword','LIKE',"%$data%");
- if((int)$data) $model = $model->whereOr('id',$data);
- }
- $list = $model->field('id,store_name,cate_id,image,sales,price,stock')->select()->toArray();
- return JsonService::successful($list);
- }
- }
- /**
- * 分类页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function store1(Request $request){
- $data = UtilService::postMore([['keyword',''],['cid',''],['sid','']],$request);
- $keyword = addslashes($data['keyword']);
- $cid = intval($data['cid']);
- $sid = intval($data['sid']);
- $category = null;
- if($sid) $category = StoreCategory::get($sid);
- if($cid && !$category) $category = StoreCategory::get($cid);
- $data['keyword'] = $keyword;
- $data['cid'] = $cid;
- $data['sid'] = $sid;
- return JsonService::successful($data);
- }
- /**
- * 一级分类
- * @return \think\response\Json
- */
- public function get_pid_cate(){
- $data = StoreCategory::pidByCategory(0,'id,cate_name');//一级分类
- return JsonService::successful($data);
- }
- /**
- * 最小提现金额
- * @return \think\response\Json
- */
- public function minmoney(){
- $data = SystemConfig::getValue('user_extract_min_price');//最小提现金额
- return JsonService::successful($data);
- }
- /**
- * 二级分类
- * @param Request $request
- * @return \think\response\Json
- */
- public function get_id_cate(Request $request){
- $data = UtilService::postMore([['id',0]],$request);
- $dataCateA = [];
- $dataCateA[0]['id'] = $data['id'];
- $dataCateA[0]['cate_name'] = '全部商品';
- $dataCateA[0]['pid'] = 0;
- $dataCateE = StoreCategory::pidBySidList($data['id']);//根据一级分类获取二级分类
- if($dataCateE) $dataCateE = $dataCateE->toArray();
- $dataCate = [];
- $dataCate = array_merge_recursive($dataCateA,$dataCateE);
- return JsonService::successful($dataCate);
- }
- /**
- * 分类页面产品
- * @param string $keyword
- * @param int $cId
- * @param int $sId
- * @param string $priceOrder
- * @param string $salesOrder
- * @param int $news
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_product_list(Request $request)
- {
- $data = UtilService::getMore([
- ['sid',0],
- ['cid',0],
- ['keyword',''],
- ['priceOrder',''],
- ['salesOrder',''],
- ['news',0],
- ['first',0],
- ['limit',0]
- ],$request);
- $sId = $data['sid'];
- $cId = $data['cid'];
- $keyword = $data['keyword'];
- $priceOrder = $data['priceOrder'];
- $salesOrder = $data['salesOrder'];
- $news = $data['news'];
- $first = $data['first'];
- $limit = $data['limit'];
- $model = StoreProduct::validWhere();
- if($sId){
- $model->where('cate_id',$sId);
- }elseif($cId){
- $sids = StoreCategory::pidBySidList($cId)?:[];
- if($sids){
- $sidsr = [];
- foreach($sids as $v){
- $sidsr[] = $v['id'];
- }
- $model->where('cate_id','IN',$sidsr);
- }
- }
- if(!empty($keyword)) $model->where('keyword|store_name','LIKE',htmlspecialchars("%$keyword%"));
- if($news!=0) $model->where('is_new',1);
- $baseOrder = '';
- if($priceOrder) $baseOrder = $priceOrder == 'desc' ? 'price DESC' : 'price ASC';
-// if($salesOrder) $baseOrder = $salesOrder == 'desc' ? 'sales DESC' : 'sales ASC';//真实销量
- if($salesOrder) $baseOrder = $salesOrder == 'desc' ? 'ficti DESC' : 'ficti ASC';//虚拟销量
- if($baseOrder) $baseOrder .= ', ';
- $model->order($baseOrder.'sort DESC, add_time DESC');
- $list = $model->limit($first,$limit)->field('id,store_name,cate_id,image,sales,ficti,price,stock')->select()->toArray();
- return JsonService::successful($list);
- }
- /**
- * 购物车
- * @return \think\response\Json
- */
- public function get_cart_list(){
- return JsonService::successful(StoreCart::getUserProductCartList($this->userInfo['uid']));
- }
- /**
- * 商品详情页
- * @param Request $request
- */
- public function details(Request $request){
- $data = UtilService::postMore(['id'],$request);
- $id = $data['id'];
- if(!$id || !($storeInfo = StoreProduct::getValidProduct($id))) return JsonService::fail('商品不存在或已下架');
- $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($id,$this->userInfo['uid'],'collect');
- list($productAttr,$productValue) = StoreProductAttr::getProductAttrDetail($id);
- setView($this->userInfo['uid'],$id,$storeInfo['cate_id'],'viwe');
- foreach ($productAttr as $k=>$v){
- $attr = $v['attr_values'];
-// unset($productAttr[$k]['attr_values']);
- foreach ($attr as $kk=>$vv){
- $productAttr[$k]['attr_value'][$kk]['attr'] = $vv;
- $productAttr[$k]['attr_value'][$kk]['check'] = false;
- }
- }
- $data['storeInfo'] = $storeInfo;
- $data['similarity'] = StoreProduct::cateIdBySimilarityProduct($storeInfo['cate_id'],'id,store_name,image,price,sales,ficti',4);
- $data['productAttr'] = $productAttr;
- $data['productValue'] = $productValue;
- $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$storeInfo['id'])->count();
- $data['mer_id'] = StoreProduct::where('id',$storeInfo['id'])->value('mer_id');
- return JsonService::successful($data);
- }
-
- /**
- * 获取产品评论
- * @param int $productId
- * @return \think\response\Json
- */
- public function get_product_reply($productId = 0){
- if(!$productId) return JsonService::fail('参数错误');
- $replyCount = StoreProductReply::productValidWhere()->where('product_id',$productId)->count();
- $reply = StoreProductReply::getRecProductReply($productId);
- return JsonService::successful(['replyCount'=>$replyCount,'reply'=>$reply]);
-}
- /**
- * 订单页面
- * @param Request $request
- * @return \think\response\Json
- */
- public function confirm_order(Request $request){
- $data = UtilService::postMore(['cartId'],$request);
- $cartId = $data['cartId'];
- if(!is_string($cartId) || !$cartId ) return JsonService::fail('请提交购买的商品');
- $cartGroup = StoreCart::getUserProductCartList($this->userInfo['uid'],$cartId,1);
- if(count($cartGroup['invalid'])) return JsonService::fail($cartGroup['invalid'][0]['productInfo']['store_name'].'已失效!');
- if(!$cartGroup['valid']) return JsonService::fail('请提交购买的商品');
- $cartInfo = $cartGroup['valid'];
- $priceGroup = StoreOrder::getOrderPriceGroup($cartInfo);
- $other = [
- 'offlinePostage'=>SystemConfigService::get('offline_postage'),
- 'integralRatio'=>SystemConfigService::get('integral_ratio')
- ];
- $usableCoupon = StoreCouponUser::beUsableCoupon($this->userInfo['uid'],$priceGroup['totalPrice']);
- $cartIdA = explode(',',$cartId);
- if(count($cartIdA) > 1) $seckill_id=0;
- else{
- $seckillinfo = StoreCart::where('id',$cartId)->find();
- if((int)$seckillinfo['seckill_id']>0) $seckill_id=$seckillinfo['seckill_id'];
- else $seckill_id=0;
- }
- $data['usableCoupon'] = $usableCoupon;
- $data['seckill_id'] = $seckill_id;
- $data['cartInfo'] = $cartInfo;
- $data['priceGroup'] = $priceGroup;
- $data['orderKey'] = StoreOrder::cacheOrderInfo($this->userInfo['uid'],$cartInfo,$priceGroup,$other);
- $data['offlinePostage'] = $other['offlinePostage'];
- $data['userInfo'] = User::getUserInfo($this->userInfo['uid']);
- $data['integralRatio'] = $other['integralRatio'];
- return JsonService::successful($data);
- }
-
- /**
- * 获取可以使用的优惠券
- * @param int $totalPrice
- * @return \think\response\Json
- */
- public function get_use_coupon_order($totalPrice = 0){
- return JsonService::successful(StoreCouponUser::beUsableCouponList($this->userInfo['uid'],$totalPrice));
- }
- /**
- * 秒杀列表页
- * @return \think\response\Json
- */
- public function seckill_index(){
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- $seckill = StoreSeckill::where('is_del',0)->where('status',1)->where('start_time','<',time())->where('stop_time','>',time())->order('sort desc')->select()->toArray();
- $data['seckill'] = $seckill;
- $data['lovely'] = $lovely[1];
- return JsonService::successful($data);
- }
- /**
- * 秒杀详情页
- * @param Request $request
- * @return \think\response\Json
- */
- public function seckill_detail(Request $request){
- $data = UtilService::postMore(['id'],$request);
- $id = $data['id'];
- if(!$id || !($storeInfo = StoreSeckill::getValidProduct($id))) return JsonService::fail('商品不存在或已下架!');
- $storeInfo['userLike'] = StoreProductRelation::isProductRelation($storeInfo['product_id'],$this->userInfo['uid'],'like','product_seckill');
- $storeInfo['like_num'] = StoreProductRelation::productRelationNum($storeInfo['product_id'],'like','product_seckill');
- $storeInfo['userCollect'] = StoreProductRelation::isProductRelation($storeInfo['product_id'],$this->userInfo['uid'],'collect','product_seckill');
- $data['storeInfo'] = $storeInfo;
- setView($this->userInfo['uid'],$id,$storeInfo['product_id'],'viwe');
- $data['reply'] = StoreProductReply::getRecProductReply($storeInfo['product_id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$storeInfo['id'])->count();
- return JsonService::successful($data);
- }
-
- /**
- * 个人中心
- * @return \think\response\Json
- */
- public function my(){
- $this->userInfo['couponCount'] = StoreCouponUser::getUserValidCouponCount($this->userInfo['uid']);
- $this->userInfo['like'] = StoreProductRelation::getUserIdCollect($this->userInfo['uid']);;
- $this->userInfo['orderStatusNum'] = StoreOrder::getOrderStatusNum($this->userInfo['uid']);
- $this->userInfo['notice'] = UserNotice::getNotice($this->userInfo['uid']);
- $this->userInfo['statu'] = (int)SystemConfig::getValue('store_brokerage_statu');
-// $this->userInfo['service_phone'] = SystemConfig::getValue('service_phone');
-// $this->userInfo['service_phone_str'] = SystemConfig::getValue('service_phone_str');
- return JsonService::successful($this->userInfo);
- }
-
-
- /**
- * 用户签到
- * @return \think\response\Json
- */
- public function user_sign()
- {
- $signed = UserSign::checkUserSigned($this->userInfo['uid']);
- if($signed) return JsonService::fail('已签到');
- if(false !== $integral = UserSign::sign($this->userInfo))
- return JsonService::successful('签到获得'.floatval($integral).'积分');
- else
- return JsonService::fail('签到失败!');
- }
- /**
- * 过度查$uniqueId
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @return \think\response\Json
- */
- public function unique(){
- $productId=$_GET['productId'];
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $uniqueId=StoreProductAttrValue::where('product_id',$productId)->value('unique');
- $data=$this->set_cart($productId,$cartNum = 1,$uniqueId);
- if($data==true){
- return JsonService::successful('ok');
- }
-
- }
- /**
- * 加入到购物车
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @return \think\response\Json
- */
- public function set_cart($productId = '',$cartNum = 1,$uniqueId = ''){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreCart::setCart($this->userInfo['uid'],$productId,$cartNum,$uniqueId,'product');
- if(!$res) return JsonService::fail(StoreCart::getErrorInfo());
- else{
-// HookService::afterListen('store_product_set_cart_after',$res,$this->userInfo,false,StoreProductBehavior::class);
- return JsonService::successful('ok',['cartId'=>$res->id]);
- }
- }
-
- /**
- * 拼团 秒杀 砍价 加入到购物车
- * @param string $productId
- * @param int $cartNum
- * @param string $uniqueId
- * @param int $combinationId
- * @param int $secKillId
- * @return \think\response\Json
- */
- public function now_buy($productId = '',$cartNum = 1,$uniqueId = '',$combinationId = 0,$secKillId = 0,$bargainId = 0){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- if($bargainId && StoreBargainUserHelp::getSurplusPrice($bargainId,$this->userInfo['uid'])) return JsonService::fail('请先砍价');
- $res = StoreCart::setCart($this->userInfo['uid'],$productId,$cartNum,$uniqueId,'product',1,$combinationId,$secKillId,$bargainId);
- if(!$res) return JsonService::fail(StoreCart::getErrorInfo());
- else return JsonService::successful('ok',['cartId'=>$res->id]);
- }
-
- /**
- * 添加点赞
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function like_product($productId = '',$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::productRelation($productId,$this->userInfo['uid'],'like',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
-
- /**
- * 取消点赞
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function unlike_product($productId = '',$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::unProductRelation($productId,$this->userInfo['uid'],'like',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
-
- /**
- * 添加收藏
- * @param $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function collect_product($productId,$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::productRelation($productId,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
-
- /**
- * 批量收藏
- * @param string $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function collect_product_all($productId = '',$category = 'product'){
- if($productId == '') return JsonService::fail('参数错误');
- $productIdS = explode(',',$productId);
- $res = StoreProductRelation::productRelationAll($productIdS,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
-
- /**
- * 取消收藏
- * @param $productId
- * @param string $category
- * @return \think\response\Json
- */
- public function uncollect_product($productId,$category = 'product'){
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误');
- $res = StoreProductRelation::unProductRelation($productId,$this->userInfo['uid'],'collect',$category);
- if(!$res) return JsonService::fail(StoreProductRelation::getErrorInfo());
- else return JsonService::successful();
- }
-
- /**
- * 获取购物车数量
- * @return \think\response\Json
- */
- public function get_cart_num(){
- return JsonService::successful('ok',StoreCart::getUserCartNum($this->userInfo['uid'],'product'));
- }
-
- /**
- * 修改购物车产品数量
- * @param string $cartId
- * @param string $cartNum
- * @return \think\response\Json
- */
- public function change_cart_num($cartId = '',$cartNum = ''){
- if(!$cartId || !$cartNum || !is_numeric($cartId) || !is_numeric($cartNum)) return JsonService::fail('参数错误!');
- StoreCart::changeUserCartNum($cartId,$cartNum,$this->userInfo['uid']);
- return JsonService::successful();
- }
-
- /**
- * 删除购物车产品
- * @param string $ids
- * @return \think\response\Json
- */
- public function remove_cart($ids=''){
- if(!$ids) return JsonService::fail('参数错误!');
- StoreCart::removeUserCart($this->userInfo['uid'],$ids);
- return JsonService::successful();
- }
-
-
- /**
- * 获取用户优惠券
- * @return \think\response\Json
- */
- public function get_use_coupons(){
-
- if($_GET){
- if($_GET['types']==0||$_GET['types']==''){
- $list= StoreCouponUser::getUserAllCoupon($this->userInfo['uid']);
- }elseif($_GET['types']==1){
- $list=StoreCouponUser::getUserValidCoupon($this->userInfo['uid']);
- }elseif($_GET['types']==2){
- $list=StoreCouponUser::getUserAlreadyUsedCoupon($this->userInfo['uid']);
- }else{
- $list=StoreCouponUser::getUserBeOverdueCoupon($this->userInfo['uid']);
- }
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d',$v['add_time']);
- $v['end_time'] = date('Y/m/d',$v['end_time']);
- }
- return JsonService::successful($list);
- }
-
- }
- /**
- * 获取用户优惠券
- * @return \think\response\Json
- */
- public function get_use_coupon(){
-
- return JsonService::successful('',StoreCouponUser::getUserAllCoupon($this->userInfo['uid']));
- }
-
- /**
- * 获取收藏产品
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_user_collect_product($first = 0,$limit = 8)
- {
- $list = StoreProductRelation::where('A.uid',$this->userInfo['uid'])
- ->field('B.id pid,B.store_name,B.price,B.ot_price,B.sales,B.image,B.is_del,B.is_show')->alias('A')
- ->where('A.type','collect')->where('A.category','product')
- ->order('A.add_time DESC')->join('__STORE_PRODUCT__ B','A.product_id = B.id')
- ->limit($first,$limit)->select()->toArray();
- foreach ($list as $k=>$product){
- if($product['pid']){
- $list[$k]['is_fail'] = $product['is_del'] && $product['is_show'];
- }else{
- unset($list[$k]);
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 获取收藏产品删除
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_user_collect_product_del()
- {
- if($_GET){
- $list = StoreProductRelation::where('uid',$this->userInfo['uid'])->where('product_id',$_GET['pid'])->delete();
- return JsonService::successful($list);
- }
-
- }
-
- /**
- * 设置为默认地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function set_user_default_address($addressId = '')
- {
- if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
- if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
- return JsonService::fail('地址不存在!');
- $res = UserAddress::setDefaultAddress($addressId,$this->userInfo['uid']);
- if(!$res)
- return JsonService::fail('地址不存在!');
- else
- return JsonService::successful();
- }
-
- /**
- * 修改收货地址
- * @return \think\response\Json
- */
- public function edit_user_address()
- {
- $request = Request::instance();
- if(!$request->isPost()) return JsonService::fail('参数错误!');
- $addressInfo = UtilService::postMore([
- ['address',[]],
- ['is_default',false],
- ['real_name',''],
- ['post_code',''],
- ['phone',''],
- ['detail',''],
- ['id',0]
- ],$request);
- $addressInfo['province'] = $addressInfo['address']['province'];
- $addressInfo['city'] = $addressInfo['address']['city'];
- $addressInfo['district'] = $addressInfo['address']['district'];
- $addressInfo['is_default'] = $addressInfo['is_default'] == true ? 1 : 0;
- $addressInfo['uid'] = $this->userInfo['uid'];
- unset($addressInfo['address']);
-
- if($addressInfo['id'] && UserAddress::be(['id'=>$addressInfo['id'],'uid'=>$this->userInfo['uid'],'is_del'=>0])){
- $id = $addressInfo['id'];
- unset($addressInfo['id']);
- if(UserAddress::edit($addressInfo,$id,'id')){
- if($addressInfo['is_default'])
- UserAddress::setDefaultAddress($id,$this->userInfo['uid']);
- return JsonService::successful();
- }else
- return JsonService::fail('编辑收货地址失败!');
- }else{
- if($address = UserAddress::set($addressInfo)){
- if($addressInfo['is_default'])
- UserAddress::setDefaultAddress($address->id,$this->userInfo['uid']);
- return JsonService::successful();
- }else
- return JsonService::fail('添加收货地址失败!');
- }
- }
-
- /**
- * 获取一条用户地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function get_user_address($addressId = ''){
- $addressInfo = [];
- if($addressId && is_numeric($addressId) && UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']])){
- $addressInfo = UserAddress::find($addressId);
- }
- return JsonService::successful($addressInfo);
- }
-
-
- /**
- * 获取默认地址
- * @return \think\response\Json
- */
- public function user_default_address()
- {
- $defaultAddress = UserAddress::getUserDefaultAddress($this->userInfo['uid'],'id,real_name,phone,province,city,district,detail,is_default');
- if($defaultAddress) return JsonService::successful('ok',$defaultAddress);
- else return JsonService::successful('empty',[]);
- }
-
- /**
- * 删除地址
- * @param string $addressId
- * @return \think\response\Json
- */
- public function remove_user_address($addressId = '')
- {
- if(!$addressId || !is_numeric($addressId)) return JsonService::fail('参数错误!');
- if(!UserAddress::be(['is_del'=>0,'id'=>$addressId,'uid'=>$this->userInfo['uid']]))
- return JsonService::fail('地址不存在!');
- if(UserAddress::edit(['is_del'=>'1'],$addressId,'id'))
- return JsonService::successful();
- else
- return JsonService::fail('删除地址失败!');
- }
-
- /**
- * 创建订单
- * @param string $key
- * @return \think\response\Json
- */
- public function create_order($key = '')
- {
- if(!$key) return JsonService::fail('参数错误!');
- if(StoreOrder::be(['order_id|unique'=>$key,'uid'=>$this->userInfo['uid'],'is_del'=>0]))
- return JsonService::status('extend_order','订单已生成',['orderId'=>$key,'key'=>$key]);
- list($addressId,$couponId,$payType,$useIntegral,$mark,$combinationId,$pinkId,$seckill_id,$formId,$bargainId) = UtilService::postMore([
- 'addressId','couponId','payType','useIntegral','mark',['combinationId',0],['pinkId',0],['seckill_id',0],['formId',''],['bargainId','']
- ],Request::instance(),true);
- $payType = strtolower($payType);
- if($bargainId) StoreBargainUser::setBargainUserStatus($bargainId,$this->userInfo['uid']);//修改砍价状态
- if($pinkId) if(StorePink::getIsPinkUid($pinkId,$this->userInfo['uid'])) return JsonService::status('ORDER_EXIST','订单生成失败,你已经在该团内不能再参加了',['orderId'=>StoreOrder::getStoreIdPink($pinkId,$this->userInfo['uid'])]);
- if($pinkId) if(StoreOrder::getIsOrderPink($pinkId,$this->userInfo['uid'])) return JsonService::status('ORDER_EXIST','订单生成失败,你已经参加该团了,请先支付订单',['orderId'=>StoreOrder::getStoreIdPink($pinkId,$this->userInfo['uid'])]);
- $order = StoreOrder::cacheKeyCreateOrder($this->userInfo['uid'],$key,$addressId,$payType,$useIntegral,$couponId,$mark,$combinationId,$pinkId,$seckill_id,$bargainId);
- $orderId = $order['order_id'];
- $info = compact('orderId','key');
- if($orderId){
- if($payType == 'weixin'){
- $orderInfo = StoreOrder::where('order_id',$orderId)->find();
- if(!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if($orderInfo['paid']) exception('支付已支付!');
- if(bcsub((float)$orderInfo['pay_price'],0,2) <= 0){
- if(StoreOrder::jsPayPrice($orderId,$this->userInfo['uid'],$formId))
- return JsonService::status('success','微信支付成功',$info);
- else
- return JsonService::status('pay_error',StoreOrder::getErrorInfo());
- }else{
- try{
- $jsConfig = StoreOrder::jsPay($orderId);
- }catch (\Exception $e){
- return JsonService::status('pay_error',$e->getMessage(),$info);
- }
- $info['jsConfig'] = $jsConfig;
- return JsonService::status('wechat_pay','订单创建成功',$info);
- }
- }else if($payType == 'yue'){
- if(StoreOrder::yuePay($orderId,$this->userInfo['uid'],$formId))
- return JsonService::status('success','余额支付成功',$info);
- else
- return JsonService::status('pay_error',StoreOrder::getErrorInfo());
- }else if($payType == 'offline'){
-// RoutineTemplate::sendOrderSuccess($formId,$orderId);//发送模板消息
- return JsonService::status('success','订单创建成功',$info);
- }
- }else{
- return JsonService::fail(StoreOrder::getErrorInfo('订单生成失败!'));
- }
- }
-
- /**
- * 获取订单列表
- * @param string $type
- * @param int $first
- * @param int $limit
- * @param string $search
- * @return \think\response\Json
- */
- public function get_user_order_list($type = '',$first = 0, $limit = 8,$search = '')
- {
-// StoreOrder::delCombination();//删除拼团未支付订单
- if($search){
- $order = StoreOrder::searchUserOrder($this->userInfo['uid'],$search)?:[];
- $list = $order == false ? [] : [$order];
- }else{
- $list = StoreOrder::getUserOrderList($this->userInfo['uid'],$type,$first,$limit);
- }
- foreach ($list as $k=>$order){
- $list[$k] = StoreOrder::tidyOrder($order,true);
- if($list[$k]['_status']['_type'] == 3){
- foreach ($order['cartInfo']?:[] as $key=>$product){
- $list[$k]['cartInfo'][$key]['is_reply'] = StoreProductReply::isReply($product['unique'],'product');
- }
- }
- }
- return JsonService::successful($list);
- }
-
- /**
- * 订单详情页
- * @param string $order_id
- * @return \think\response\Json
- */
- public function get_order($uni = ''){
- if($uni == '') return JsonService::fail('参数错误');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- $order = $order->toArray();
- $order['add_time'] = date('Y-m-d H:i:s',$order['add_time']);
- if(!$order) return JsonService::fail('订单不存在');
- return JsonService::successful(StoreOrder::tidyOrder($order,true));
- }
-
- /**
- * 获取订单内的某个产品信息
- * @param string $uni
- * @param string $productId
- * @return \think\response\Json
- */
- public function get_order_product($unique = ''){
- if(!$unique || !StoreOrderCartInfo::be(['unique'=>$unique]) || !($cartInfo = StoreOrderCartInfo::where('unique',$unique)->find())) return JsonService::fail('评价产品不存在!');
- return JsonService::successful($cartInfo);
- }
- /**
- * 删除订单
- * @param string $uni
- * @return \think\response\Json
- */
- public function user_remove_order($uni = '')
- {
- if(!$uni) return JsonService::fail('参数错误!');
- $res = StoreOrder::removeOrder($uni,$this->userInfo['uid']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
-
- /**
- * 支付订单
- * @param string $uni
- * @return \think\response\Json
- */
- public function pay_order($uni = '')
- {
- if(!$uni) return JsonService::fail('参数错误!');
- $order= StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- if(!$order) return JsonService::fail('订单不存在!');
- if($order['paid']) return JsonService::fail('该订单已支付!');
- if($order['pink_id']) if(StorePink::isPinkStatus($order['pink_id'])) return JsonService::fail('该订单已失效!');
- if($order['pay_type'] == 'weixin'){
- try{
- $jsConfig = StoreOrder::jsPay($order);
- }catch (\Exception $e){
- return JsonService::fail($e->getMessage());
- }
- return JsonService::status('wechat_pay',['jsConfig'=>$jsConfig,'order_id'=>$order['order_id']]);
- }else if($order['pay_type'] == 'yue'){
- if($res = StoreOrder::yuePay($order['order_id'],$this->userInfo['uid']))
- return JsonService::successful('余额支付成功');
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }else if($order['pay_type'] == 'offline'){
- StoreOrder::createOrderTemplate($order);
- return JsonService::successful('订单创建成功');
- }
- }
-
-
- /**
- * 申请退款
- * @param string $uni
- * @param string $text
- * @return \think\response\Json
- */
- public function apply_order_refund(Request $request,$uni = '')
- {
- $data = UtilService::postMore([
- ['text',''],
- ['refund_reason_wap_img',''],
- ['refund_reason_wap_explain',''],
- ],$request);
- if($data['refund_reason_wap_img']) $data['refund_reason_wap_img'] = explode(',',$data['refund_reason_wap_img']);
- if(!$uni || $data['text'] == '') return JsonService::fail('参数错误!');
- $res = StoreOrder::orderApplyRefund($uni,$this->userInfo['uid'],$data['text'],$data['refund_reason_wap_explain'],$data['refund_reason_wap_img']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
- /**
- * 用户确认收货
- * @param string $uni
- * @return \think\response\Json
- */
- public function user_take_order($uni = '')
- {
- if(!$uni) return JsonService::fail('参数错误!');
-
- $res = StoreOrder::takeOrder($uni,$this->userInfo['uid']);
- if($res)
- return JsonService::successful();
- else
- return JsonService::fail(StoreOrder::getErrorInfo());
- }
-
- /**
- * 充值
- * @param int $price
- * @return \think\response\Json
- */
- public function user_wechat_recharge($price = 0)
- {
- if(!$price || $price <=0) return JsonService::fail('参数错误');
- $storeMinRecharge = SystemConfigService::get('store_user_min_recharge');
- if($price < $storeMinRecharge) return JsonService::fail('充值金额不能低于'.$storeMinRecharge);
- $rechargeOrder = UserRecharge::addRecharge($this->userInfo['uid'],$price);
- if(!$rechargeOrder) return JsonService::fail('充值订单生成失败!');
- try{
- return JsonService::successful(UserRecharge::jsPay($rechargeOrder));
- }catch (\Exception $e){
- return JsonService::fail($e->getMessage());
- }
- }
-
- /**
- * 余额使用记录
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function user_balance_list($first = 0,$limit = 8)
- {
- $list = UserBill::where('uid',$this->userInfo['uid'])->where('category','now_money')
- ->field('mark,pm,number,add_time')
- ->where('status',1)->order('add_time DESC')->limit($first,$limit)->select()->toArray();
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d H:i',$v['add_time']);
- }
- return JsonService::successful($list);
- }
-
- /**
- * 积分使用记录
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function user_integral_list($first = 0,$limit = 8)
- {
- $list = UserBill::where('uid',$this->userInfo['uid'])->where('category','integral')
- ->field('mark,pm,number,add_time')
- ->where('status',1)->order('add_time DESC')->limit($first,$limit)->select()->toArray();
- foreach ($list as &$v){
- $v['add_time'] = date('Y/m/d H:i',$v['add_time']);
- $v['number'] = floatval($v['number']);
- }
- return JsonService::successful($list);
-
- }
-
- /**
- * 评价订单
- * @param string $unique
- * @return \think\response\Json
- */
- public function user_comment_product($unique = '')
- {
- if(!$unique) return JsonService::fail('参数错误!');
- $cartInfo = StoreOrderCartInfo::where('unique',$unique)->find();
- $uid = $this->userInfo['uid'];
- if(!$cartInfo || $uid != $cartInfo['cart_info']['uid']) return JsonService::fail('评价产品不存在!');
- if(StoreProductReply::be(['oid'=>$cartInfo['oid'],'unique'=>$unique]))
- return JsonService::fail('该产品已评价!');
- $group = UtilService::postMore([
- ['comment',''],['pics',[]],['product_score',5],['service_score',5]
- ],Request::instance());
- $group['comment'] = htmlspecialchars(trim($group['comment']));
- if($group['product_score'] < 1) return JsonService::fail('请为产品评分');
- else if($group['service_score'] < 1) return JsonService::fail('请为商家服务评分');
- if($cartInfo['cart_info']['combination_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if($cartInfo['cart_info']['seckill_id']) $productId = $cartInfo['cart_info']['product_id'];
- else if($cartInfo['cart_info']['bargain_id']) $productId = $cartInfo['cart_info']['product_id'];
- else $productId = $cartInfo['product_id'];
- $group = array_merge($group,[
- 'uid'=>$uid,
- 'oid'=>$cartInfo['oid'],
- 'unique'=>$unique,
- 'product_id'=>$productId,
- 'reply_type'=>'product'
- ]);
- StoreProductReply::beginTrans();
- $res = StoreProductReply::reply($group,'product');
- if(!$res) {
- StoreProductReply::rollbackTrans();
- return JsonService::fail('评价失败!');
- }
- try{
-// HookService::listen('store_product_order_reply',$group,$cartInfo,false,StoreProductBehavior::class);
- StoreOrder::checkOrderOver($cartInfo['oid']);
- }catch (\Exception $e){
- StoreProductReply::rollbackTrans();
- return JsonService::fail($e->getMessage());
- }
- StoreProductReply::commitTrans();
- return JsonService::successful();
- }
-
- /**
- * 上传图片
- * @param string $filename
- * @return \think\response\Json
- */
- public function upload(Request $request)
- {
- $data = UtilService::postMore([['filename','']],$request);
- $res = UploadService::image($data['filename'],'store/comment');
- if($res->status == 200)
- return JsonService::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>UploadService::pathToUrl($res->dir)]);
- else
- return JsonService::fail($res->error);
- }
-
- /**
- * 获取一级和二级分类
- * @return \think\response\Json
- */
- public function get_product_category()
- {
- $parentCategory = StoreCategory::pidByCategory(0,'id,cate_name')->toArray();
- foreach ($parentCategory as $k=>$category){
- $category['child'] = StoreCategory::pidByCategory($category['id'],'id,cate_name')->toArray();
- $parentCategory[$k] = $category;
- }
- return JsonService::successful($parentCategory);
- }
-
- /**
- * 获取一级推荐人
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_spread_list($first = 0,$limit = 20)
- {
- $list = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
- foreach ($list as $k=>$user){
- $list[$k]['add_time'] = date('Y/m/d',$user['add_time']);
- $list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
- }
- $count = User::where('spread_uid',$this->userInfo['uid'])->field('uid,nickname,avatar,add_time')->count();
- $data['count'] = $count;
- $data['list'] = $list;
- return JsonService::successful($data);
- }
-
- /**
- * 获取二级推荐人
- * @param int $first
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_spread_list_two($two_uid=0,$first = 0,$limit = 20)
- {
- $list = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->limit($first,$limit)->order('add_time DESC')->select()->toArray();
- foreach ($list as $k=>$user){
- $list[$k]['add_time'] = date('Y/m/d',$user['add_time']);
- $list[$k]['price'] = StoreOrder::getUserPrice($user['uid']);
- }
- $count = User::where('spread_uid',$two_uid)->field('uid,nickname,avatar,add_time')->count();
- $data['count'] = $count;
- $data['list'] = $list;
- return JsonService::successful($data);
- }
-
- /**
- * 领取优惠券
- * @param string $couponId
- * @return \think\response\Json
- */
- public function user_get_coupon($couponId = '')
- {
- if(!$couponId || !is_numeric($couponId)) return JsonService::fail('参数错误!');
- if(StoreCouponIssue::issueUserCoupon($couponId,$this->userInfo['uid'])){
- return JsonService::successful('领取成功');
- }else{
- return JsonService::fail(StoreCouponIssue::getErrorInfo('领取失败!'));
- }
- }
-
-
- /**
- * 获取产品评论
- * @param string $productId
- * @param int $first
- * @param int $limit
- * @param string $filter
- * @return \think\response\Json
- */
- public function product_reply_list($productId = '',$first = 0,$limit = 8, $filter = 'all')
- {
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!');
- $list = StoreProductReply::getProductReplyList($productId,$filter,$first,$limit);
- if($list){
- foreach ($list as $k=>$v){
- foreach ($v['pics'] as $kk=>$vv){
- $list[$k]['pics'] = explode(',',$vv);
- }
- }
- }
- return JsonService::successful($list);
- }
-
- /**
- * 获取商品属性数据
- * @param string $productId
- * @return \think\response\Json
- */
- public function product_attr_detail($productId = '')
- {
- if(!$productId || !is_numeric($productId)) return JsonService::fail('参数错误!');
- list($productAttr,$productValue) = StoreProductAttr::getProductAttrDetail($productId);
- return JsonService::successful(compact('productAttr','productValue'));
-
- }
-
- /**
- * 获取用户所有地址
- * @return \think\response\Json
- */
- public function user_address_list()
- {
- $list = UserAddress::getUserValidAddressList($this->userInfo['uid'],'id,real_name,phone,province,city,district,detail,is_default');
- return JsonService::successful($list);
- }
-
- /**
- * 用户通知
- * @param int $page
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_notice_list($page = 0, $limit = 8)
- {
- $list = UserNotice::getNoticeList($this->userInfo['uid'],$page,$limit);
- return JsonService::successful($list);
- }
-
- /**
- * 修改用户通知为已查看
- * @param $nid
- * @return \think\response\Json
- */
- public function see_notice($nid){
- UserNotice::seeNotice($this->userInfo['uid'],$nid);
- return JsonService::successful();
- }
-
- /**
- * 客服提醒
- * @param Request $request
- * @return \think\response\Json
- */
- public function refresh_msn(Request $request)
- {
- $params = $request->post();
- $remind_where = "mer_id = ".$params["mer_id"]." AND uid = ".$params["uid"]." AND to_uid = ".$params["to_uid"]." AND type = 0 AND remind = 0";
- $remind_list = StoreServiceLog::where($remind_where)->order("add_time asc")->select();
- foreach ($remind_list as $key => $value) {
- if(time() - $value["add_time"] > 3){
- StoreServiceLog::edit(array("remind"=>1),$value["id"]);
- $now_user = StoreService::field("uid,nickname")->where(array("uid"=>$params["uid"]))->find();
- if(!$now_user)$now_user = User::field("uid,nickname")->where(array("uid"=>$params["uid"]))->find();
- if($params["to_uid"]) {
- $head = '您有新的消息,请注意查收!';
- $head .= $params["mer_id"] > 0 ? "\n商户名称:".Merchant::where('id',$params["mer_id"])->value('mer_name') : '';
- WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($params["to_uid"]),WechatTemplateService::SERVICE_NOTICE,[
- 'first'=>$head,
- 'keyword1'=>$now_user["nickname"],
- 'keyword2'=>"客服提醒",
- 'keyword3'=> preg_replace('//','[图片]',$value["msn"]),
- 'keyword4'=>date('Y-m-d H:i:s',time()),
- 'remark'=>'点击立即查看消息'
- ],Url::build('service/service_ing',['to_uid'=>$now_user["uid"],'mer_id'=>$params["mer_id"]],true,true));
- }
- }
- }
- $where = "mer_id = ".$params["mer_id"]." AND uid = ".$params["to_uid"]." AND to_uid = ".$params["uid"]." AND type = 0";
- $list = StoreServiceLog::where($where)->order("add_time asc")->select()->toArray();
- $ids = [];
- foreach ($list as $key => $value) {
- //设置发送人与接收人区别
- if($value["uid"] == $params["uid"])
- $list[$key]['my'] = "my";
- else
- $list[$key]['my'] = "to";
-
- array_push($ids,$value["id"]);
- }
-
- //设置这些消息为已读
- StoreServiceLog::where(array("id"=>array("in",$ids)))->update(array("type"=>1,"remind"=>1));
- return JsonService::successful($list);
- }
-
- public function add_msn(Request $request){
- $params = $request->post();
- if($params["type"] == "html")
- $data["msn"] = htmlspecialchars_decode($params["msn"]);
- else
- $data["msn"] = $params["msn"];
- $data["uid"] = $params["uid"];
- $data["to_uid"] = $params["to_uid"];
- $data["mer_id"] = $params["mer_id"] > 0 ? $params["mer_id"] : 0;
- $data["add_time"] = time();
- StoreServiceLog::set($data);
- return JsonService::successful();
- }
-
- public function get_msn(Request $request){
- $params = $request->post();
- $size = 10;
- $page = $params["page"]>=0 ? $params["page"] : 1;
- $where = "(mer_id = ".$params["mer_id"]." AND uid = ".$params["uid"]." AND to_uid = ".$params["to_uid"].") OR (mer_id = ".$params["mer_id"]." AND uid = ".$params["to_uid"]." AND to_uid = ".$params["uid"].")";
- $list = StoreServiceLog::where($where)->limit(($page-1)*$size,$size)->order("add_time desc")->select()->toArray();
- foreach ($list as $key => $value) {
- //设置发送人与接收人区别
- if($value["uid"] == $params["uid"])
- $list[$key]['my'] = "my";
- else
- $list[$key]['my'] = "to";
-
- //设置这些消息为已读
- if($value["uid"] == $params["to_uid"] && $value["to_uid"] == $params["uid"])StoreServiceLog::edit(array("type"=>1,"remind"=>1),$value["id"]);
- }
- $list=array_reverse($list);
- return JsonService::successful($list);
- }
-
- public function refresh_msn_new(Request $request){
- $params = $request->post();
- $now_user = User::getUserInfo($this->userInfo['uid']);
- if($params["last_time"] > 0)
- $where = "(uid = ".$now_user["uid"]." OR to_uid = ".$now_user["uid"].") AND add_time>".$params["last_time"];
- else
- $where = "uid = ".$now_user["uid"]." OR to_uid = ".$now_user["uid"];
-
-
- $msn_list = StoreServiceLog::where($where)->order("add_time desc")->select()->toArray();
- $info_array = $list = [];
- foreach ($msn_list as $key => $value){
- $to_uid = $value["uid"] == $now_user["uid"] ? $value["to_uid"] : $value["uid"];
- if(!in_array(["to_uid"=>$to_uid,"mer_id"=>$value["mer_id"]],$info_array)){
- $info_array[count($info_array)] = ["to_uid"=>$to_uid,"mer_id"=>$value["mer_id"]];
-
- $to_user = StoreService::field("uid,nickname,avatar")->where(array("uid"=>$to_uid))->find();
- if(!$to_user)$to_user = User::field("uid,nickname,avatar")->where(array("uid"=>$to_uid))->find();
- $to_user["mer_id"] = $value["mer_id"];
- $to_user["mer_name"] = $value["mer_id"] > 0 ? "[".Merchant::where('id',$value["mer_id"])->value('mer_name')."]" : '';
- $value["to_info"] = $to_user;
- $value["count"] = StoreServiceLog::where(array("mer_id"=>$value["mer_id"],"uid"=>$to_uid,"to_uid"=>$now_user["uid"],"type"=>0))->count();
- $list[count($list)] = $value;
- }
- }
- return JsonService::successful($list);
- }
-
- public function get_user_brokerage_list($uid, $first = 0,$limit = 8)
- {
- if(!$uid)
- return $this->failed('用户不存在');
- $list = UserBill::field('A.mark,A.add_time,A.number,A.pm')->alias('A')->limit($first,$limit)
- ->where('A.category','now_money')->where('A.type','brokerage')
- ->where('A.uid',$this->userInfo['uid'])
- ->join('__STORE_ORDER__ B','A.link_id = B.id AND B.uid = '.$uid)->select()->toArray();
- return JsonService::successful($list);
- }
-
- public function user_extract()
- { $request = Request::instance();
- $list=$request->param();
- $data=$list['lists'];
- if(UserExtract::userExtract($this->userInfo,$data))
- return JsonService::successful('申请提现成功!');
- else
- return JsonService::fail(UserExtract::getErrorInfo());
- }
-
-/*
- * 提现列表
- */
- public function extract($first = 0,$limit = 8)
- {
- $list=UserExtract::where('uid',$this->userInfo['uid'])->order('add_time desc')->limit($first,$limit)->select()->toArray();
- foreach($list as &$v){
- $v['add_time']=date('Y/m/d',$v['add_time']);
- }
-
- return JsonService::successful($list);
-
- }
-
- /**
- * 用户下级的订单
- * @param int $first
- * @param int $limit
- */
- public function subordinateOrderlist($first = 0, $limit = 8){
- $request = Request::instance();
- $lists=$request->param();
- $xUid = $lists['uid'];
- $status = $lists['status'];
- if($status == 0) $type='';
- elseif($status == 1) $type=4;
- elseif($status == 2) $type=3;
- else return false;
- $list = [];
- if(!$xUid){
- $arr = User::where('spread_uid',$this->userInfo['uid'])->column('uid');
- foreach($arr as $v) $list = StoreOrder::getUserOrderList($v,$type,$first,$limit);
- }else $list = StoreOrder::getUserOrderList($xUid,$type,$first,$limit);
- foreach ($list as $k=>$order){
- $list[$k] = StoreOrder::tidyOrder($order,true);
- if($list[$k]['_status']['_type'] == 3){
- foreach ($order['cartInfo']?:[] as $key=>$product){
- $list[$k]['cartInfo'][$key]['is_reply'] = StoreProductReply::isReply($product['unique'],'product');
- }
- }
- }
- return JsonService::successful($list);
- }
- /**
- * 用户下级的订单
- * @param int $first
- * @param int $limit
- */
- public function subordinateOrderlistmoney()
- {
- $request = Request::instance();
- $lists=$request->param();
- $status = $lists['status'];
- $type = '';
- if($status == 1) $type = 4;
- elseif($status == 2) $type = 3;
- $arr = User::where('spread_uid',$this->userInfo['uid'])->column('uid');
- $list = StoreOrder::getUserOrderCount(implode(',',$arr),$type);
- $price = [];
- if(!empty($list)) foreach ($list as $k=>$v) $price[]=$v['pay_price'];
- $cont = count($list);
- $sum = array_sum($price);
- return JsonService::successful(['cont'=>$cont,'sum'=>$sum]);
- }
- /*
- * 昨日推广佣金
- */
- public function yesterdayCommission(){
- $money=UserBill::where('uid',$this->userInfo['uid'])->where('category','now_money')->where('type','brokerage')->where('pm',1)->where('status',1)->whereTime('add_time', 'yesterday')->column('number');
- $sum= array_sum($money);
- return JsonService::successful($sum);
- }
- /*
- * 累计已提金额
- */
- public function extractsum(){
- $money=UserExtract::where('uid',$this->userInfo['uid'])->where('status',1)->column('extract_price');
- $sum= array_sum($money);
- return JsonService::successful($sum);
- }
- /**
- * 获取一条优惠券
- * @param int $couponId
- * @return \think\response\Json
- */
- public function get_coupon_rope($couponId = 0){
- if(!$couponId) return JsonService::fail('参数错误');
- $couponUser = StoreCouponUser::validAddressWhere()->where('id',$couponId)->where('uid',$this->userInfo['uid'])->find();
- return JsonService::successful($couponUser);
- }
- /**
- * 获取 可以领取的优惠券
- * @param int $limit
- * @return \think\response\Json
- */
- public function get_issue_coupon_list($limit = 2)
- {
- $list = StoreCouponIssue::validWhere('A')->join('__STORE_COUPON__ B','A.cid = B.id')
- ->field('A.*,B.coupon_price,B.use_min_price')->order('B.sort DESC,A.id DESC')->limit($limit)->select()->toArray()?:[];
- foreach ($list as $k=>$v){
- $list[$k]['is_use'] = StoreCouponIssueUser::be(['uid'=>$this->userInfo['uid'],'issue_coupon_id'=>$v['id']]);
- }
- return JsonService::successful($list);
- }
-
- public function clear_cache($uni = '')
- {
- if($uni)CacheService::clear();
- }
-
- /**
- * 获取今天正在拼团的人的头像和名称
- * @return \think\response\Json
- */
- public function get_pink_second_one(){
- $addTime = mt_rand(time()-30000,time());
- $storePink = StorePink::where('p.add_time','GT',$addTime)->alias('p')->where('p.status',1)->join('User u','u.uid=p.uid')->field('u.nickname,u.avatar as src')->find();
- return JsonService::successful($storePink);
- }
-
- /**
- * 再来一单
- * @param string $uni
- */
- public function order_details($uni = ''){
-
- if(!$uni) return JsonService::fail('参数错误!');
- $order = StoreOrder::getUserOrderDetail($this->userInfo['uid'],$uni);
- if(!$order) return JsonService::fail('订单不存在!');
- $order = StoreOrder::tidyOrder($order,true);
- $res = array();
- foreach ($order['cartInfo'] as $v) {
- if($v['combination_id']) return JsonService::fail('拼团产品不能再来一单,请在拼团产品内自行下单!');
- else $res[] = StoreCart::setCart($this->userInfo['uid'], $v['product_id'], $v['cart_num'], isset($v['productInfo']['attrInfo']['unique']) ? $v['productInfo']['attrInfo']['unique'] : '', 'product', 0, 0);
- }
- $cateId = [];
- foreach ($res as $v){
- if(!$v) return JsonService::fail('再来一单失败,请重新下单!');
- $cateId[] = $v['id'];
- }
- return JsonService::successful('ok',implode(',',$cateId));
-
- }
- /**
- * 获取分销二维码
- * @return \think\response\Json
- */
- public function get_code(){
- header('content-type:image/jpg');
- if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
- $path = makePathToUrl('routine/code');
- if($path == '')
- return JsonService::fail('生成上传目录失败,请检查权限!');
- $picname = $path.DS.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- $domainTop = substr($domain,0,5);
- if($domainTop != 'https') $domain = 'https:'.substr($domain,5,strlen($domain));
- if(file_exists($picname)) return JsonService::successful($domain.$picname);
- else{
- $res = RoutineCode::getCode($this->userInfo['uid'],$picname);
- if($res) file_put_contents($picname,$res);
- else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$picname);
- }
-
- /**
- * 绑定推荐人
- * @param Request $request
- * @return \think\response\Json
- */
- public function spread_uid(Request $request){
- $data = UtilService::postMore(['spread_uid',0],$request);
- if($data['spread_uid']){
- if(!$this->userInfo['spread_uid']){
- $res = User::edit(['spread_uid'=>$data['spread_uid']],$this->userInfo['uid']);
- if($res) return JsonService::successful('绑定成功');
- else return JsonService::successful('绑定失败');
- }else return JsonService::fail('已存在被推荐人');
- }else return JsonService::fail('没有推荐人');
- }
-
- /**
- * 获取砍价列表
- * @return \think\response\Json
- */
- public function get_bargain_list($limit = 10){
- $bargain = StoreBargain::getList();
- $bargain = StoreBargainUser::getUserList($bargain,$limit);
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- $banner = GroupDataService::getData('bargain_banner')?:[];//banner图
- $banner = $banner[0];
- $bargainUser = StoreBargainUser::getBargainUserStatusSuccess();
- $data['bargain'] = $bargain;
- $data['lovely'] = $lovely[2];
- $data['banner'] = $banner;
- $data['bargainUser'] = $bargainUser;
- return JsonService::successful($data);
- }
-
- /**
- * 砍价详情
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function get_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $bargain = StoreBargain::getBargainTerm($bargainId);
- if(empty($bargain)) return JsonService::fail('砍价已结束');
- $bargain['time'] = time();
- return JsonService::successful($bargain);
- }
-
- /**
- * 获取人数
- * @param int $count
- * @return \think\response\Json
- */
- public function get_bargain_count($count = 0){
- $data['lookCount'] = StoreBargain::getBargainLook()['look'];//观看人数
- $data['shareCount'] = StoreBargain::getBargainShare()['share'];//观看人数
- $data['userCount'] = StoreBargainUser::count();//参与人数
- return JsonService::successful($data);
- }
-
- /**
- * 添加砍价分享次数
- * @param int $bargainId
- */
- public function add_share_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::successful();
- StoreBargain::addBargainShare($bargainId);
- return JsonService::successful();
- }
-
- /**
- * 添加砍价浏览次数
- * @param int $bargainId
- */
- public function add_look_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::successful();
- StoreBargain::addBargainLook($bargainId);
- return JsonService::successful();
- }
-
- /**
- * 获取砍价帮
- * @param int $bargainId
- * @param int $uid
- * @return \think\response\Json
- */
- public function get_bargain_user($bargainId = 0,$bargainUid = 0,$limit = 15){
- if(!$bargainId || !$bargainUid) return JsonService::fail('参数错误');
- $bargainUserTableId = StoreBargainUser::setUserBargain($bargainId,$bargainUid);
- $storeBargainUserHelp = StoreBargainUserHelp::getList($bargainUserTableId,$limit);
- return JsonService::successful($storeBargainUserHelp);
- }
- /**
- * 我的砍价
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function mycut($bargainId = 0){
- if(!$bargainId ) return JsonService::fail('参数错误');
- $data= StoreBargainUser::where('bargain_id',$bargainId)->where('uid',$this->userInfo['uid'])->where('status',1)->find();
- return JsonService::successful($data);
- }
- /**
- * 参与砍价产品
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function set_bargain($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $res = StoreBargainUser::setBargain($bargainId,$this->userInfo['uid']);
- if($res) {
- $data['id'] = $res->id;
- return JsonService::successful('参与成功',$data);
- }
- else return JsonService::fail('参与失败');
- }
-
- /**
- * 判断当前登录人是否参与砍价
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function is_bargain_user($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $data=StoreBargainUser::isBargainUser($bargainId,$this->userInfo['uid']);
- if($data) return JsonService::successful($data);
- else return JsonService::fail('没有参与砍价');
- }
- /*
- * 已砍掉的金额
- */
- public function speed_of_progress($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- $price= StoreBargainUser::where('bargain_id',$bargainId)->where('status',1)->where('uid',$this->userInfo['uid'])->value('price');
- return JsonService::successful($price);
- }
- /**
- * 帮好友砍价
- * @param int $bargainId
- * @param int $bargainUserId
- * @return \think\response\Json
- */
- public function set_bargain_help($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- $res = StoreBargainUserHelp::setBargainUserHelp($bargainId,$bargainUserId,$this->userInfo['uid']);
- if($res) {
- if(!StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId)){
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- $bargain = StoreBargain::where('id',$bargainId)->find()->toArray();
- $bargainUser = StoreBargainUser::where('id',$bargainUserTableId)->find()->toArray();
- RoutineTemplate::sendBargainSuccess($bargain,$bargainUser,$bargainUserId);//发送模板消息
- }
- return JsonService::successful('砍价成功',$res);
- }
- else return JsonService::fail('砍价失败');
- }
-
-
- /**
- * 获取砍价帮总人数、剩余金额、进度条
- * @param int $bargainId
- * @param int $bargainUserId
- * @return \think\response\Json
- */
- public function get_bargain_help_count($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- $count = StoreBargainUserHelp::getBargainUserHelpPeopleCount($bargainId,$bargainUserId);
- $price = StoreBargainUserHelp::getSurplusPrice($bargainId,$bargainUserId);
- $pricePercent = StoreBargainUserHelp::getSurplusPricePercent($bargainId,$bargainUserId);
- $data['count'] = $count;
- $data['price'] = $price;
- $data['pricePercent'] = $pricePercent;
- return JsonService::successful($data);
- }
-
- /**
- * 判断当前砍价是否开启
- * @param int $bargainId
- * @return \think\response\Json
- */
- public function is_bargain_status($bargainId = 0){
- if(!$bargainId) return JsonService::fail('参数错误');
- if(!StoreBargain::setBargainStatus($bargainId)) return JsonService::successful();
- else return JsonService::fail();
- }
-
-
- /**
- * 判断用户是否可以砍价
- * @param int $bargainId
- * @param int $bargainUserId
- */
- public function is_bargain_user_help($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return JsonService::fail('参数错误');
- if(StoreBargainUserHelp::isBargainUserHelpCount($bargainId,$bargainUserId,$this->userInfo['uid'])) return JsonService::successful('请稍后在帮助好友砍价');
- else return JsonService::fail('您不能再帮忙砍价了');
- }
-
- /**
- * 修改砍价状态为失败
- * @param int $bargainUserTableId
- */
- public function set_user_bargain_status($bargainUserTableId = 0){
- if(!$bargainUserTableId) return JsonService::fail('参数错误');
- if(StoreBargainUser::editBargainUserStatus($bargainUserTableId)) return JsonService::successful('ok');
- else return JsonService::fail('no');
- }
-
-
-
- /**
- * 获取用户信息
- * @param int $uid
- * @return \think\response\Json
- */
- public function get_user_info_uid($userId = 0){
- if(!$userId) return JsonService::fail('参数错误');
- $res = User::getUserInfo($userId);
- if($res) return JsonService::successful($res);
- else return JsonService::fail(User::getErrorInfo());
- }
-
- /**
- * 获取砍价产品 个人中心 我的砍价
- */
- public function get_user_bargain_all(){
- $list = StoreBargainUser::getBargainUserAll($this->userInfo['uid']);
- if($list){
- foreach ($list as $k=>$v){
- $list[$k]['helpCount'] = StoreBargainUserHelp::getBargainUserHelpPeopleCount($v['bargain_id'],$this->userInfo['uid']);
- }
- return JsonService::successful($list);
- }else return JsonService::fail('暂无参与砍价');
- }
- /*
- * 查物流
- */
- public function express($uid,$uni = '')
- {
- if(!$uni || !($order = StoreOrder::getUserOrderDetail($uid,$uni))) return JsonService::fail('查询订单不存在!');
- if($order['delivery_type'] != 'express' || !$order['delivery_id']) return JsonService::fail('该订单不存在快递单号!');
- $cacheName = $uni.$order['delivery_id'];
- CacheService::rm($cacheName);
- $result = CacheService::get($cacheName,null);
- if($result === NULL){
- $result = Express::query($order['delivery_id']);
- if(is_array($result) &&
- isset($result['result']) &&
- isset($result['result']['deliverystatus']) &&
- $result['result']['deliverystatus'] >= 3)
- $cacheTime = 0;
- else
- $cacheTime = 1800;
- CacheService::set($cacheName,$result,$cacheTime);
- }
-
- if($result) return JsonService::successful([ 'order'=>$order, 'express'=>$result]);
- }
-
- /**
- * 收集发送模板信息的formID
- * @param string $formId
- */
- public function get_form_id($formId = ''){
- if((int)$formId == '' || $formId == 'the formId is a mock one') return JsonService::fail('no');
- $data['form_id'] = $formId;
- $data['uid'] = $this->userInfo['uid'];
- $data['status'] = 1;
- $data['stop_time'] = bcadd(time(),bcmul(6,86400,0),0);
- RoutineFormId::set($data);
- return JsonService::successful();
- }
-
- /**
- * 获取拼团列表
- * @param int $offset
- * @param int $limit
- */
- public function get_combination_list($offset=0,$limit=20){
- $store_combination = StoreCombination::getAll($offset,$limit);
- return JsonService::successful($store_combination);
- }
-
- /**
- * 获取拼团列表顶部图
- * @param int $offset
- * @param int $limit
- */
- public function get_combination_list_banner(){
- $lovely = GroupDataService::getData('routine_lovely')?:[];//banner图
- return JsonService::successful($lovely[3]);
- }
-
- /**
- * 获取拼团产品详情
- * @param int $id
- */
- public function combination_detail($id = 0){
- if(!$id) return JsonService::fail('拼团不存在或已下架');
- $combinationOne = StoreCombination::getCombinationOne($id);
- if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
- $combinationOne['images'] = json_decode($combinationOne['images'],true);
-// $combinationOne['userLike'] = StoreProductRelation::isProductRelation($combinationOne['product_id'],$this->userInfo['uid'],'like');
-// $combinationOne['like_num'] = StoreProductRelation::productRelationNum($combinationOne['product_id'],'like');
- $combinationOne['userCollect'] = StoreProductRelation::isProductRelation($id,$this->userInfo['uid'],'collect','pink_product');
- $pink = StorePink::getPinkAll($id);//拼团列表
- $pindAll = array();
- foreach ($pink as $k=>$v){
- $pink[$k]['count'] = StorePink::getPinkPeople($v['id'],$v['people']);
- $pink[$k]['h'] = date('H',$v['stop_time']);
- $pink[$k]['i'] = date('i',$v['stop_time']);
- $pink[$k]['s'] = date('s',$v['stop_time']);
- $pindAll[] = $v['id'];//开团团长ID
- }
- $user = WechatUser::get($this->userInfo['uid'])->toArray();//用户信息
- $data['pink'] = $pink;
- $data['user'] = $user;
- $data['pindAll'] = $pindAll;
- $data['storeInfo'] = $combinationOne;
- $data['reply'] = StoreProductReply::getRecProductReply($combinationOne['product_id']);
- $data['replyCount'] = StoreProductReply::productValidWhere()->where('product_id',$combinationOne['product_id'])->count();
-// $data['mer_id'] = StoreProduct::where('id',$combinationOne['product_id'])->value('mer_id');
- return JsonService::successful($data);
- }
-
- /**
- * 开团页面
- * @param int $id
- * @return mixed
- */
- public function get_pink($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $pink = StorePink::getPinkUserOne($id);
- if(isset($pink['is_refund']) && $pink['is_refund']) {
- if($pink['is_refund'] != $pink['id']){
- $id = $pink['is_refund'];
- return $this->get_pink($id);
- }else{
- return JsonService::fail('订单已退款');
- }
- }
- if(!$pink) return JsonService::fail('参数错误');
- $pinkAll = array();//参团人 不包括团长
- $pinkT = array();//团长
- if($pink['k_id']){
- $pinkAll = StorePink::getPinkMember($pink['k_id']);
- $pinkT = StorePink::getPinkUserOne($pink['k_id']);
- }else{
- $pinkAll = StorePink::getPinkMember($pink['id']);
- $pinkT = $pink;
- }
- $store_combination = StoreCombination::getCombinationOne($pink['cid']);//拼团产品
- $count = count($pinkAll)+1;
- $count = (int)$pinkT['people']-$count;//剩余多少人
- $is_ok = 0;//判断拼团是否完成
- $idAll = array();
- $uidAll = array();
- if(!empty($pinkAll)){
- foreach ($pinkAll as $k=>$v){
- $idAll[$k] = $v['id'];
- $uidAll[$k] = $v['uid'];
- }
- }
-
- $userBool = 0;//判断当前用户是否在团内 0未在 1在
- $pinkBool = 0;//判断当前用户是否在团内 0未在 1在
- $idAll[] = $pinkT['id'];
- $uidAll[] = $pinkT['uid'];
- if($pinkT['status'] == 2){
- $pinkBool = 1;
- $is_ok = 1;
- }else{
- if(!$count){//组团完成
- $is_ok = 1;
- $idAll = implode(',',$idAll);
- $orderPinkStatus = StorePink::setPinkStatus($idAll);
- if($orderPinkStatus){
- if(in_array($this->userInfo['uid'],$uidAll)){
- StorePink::setPinkStopTime($idAll);
- if(StorePink::isTpl($uidAll,$pinkT['id'])) StorePink::orderPinkAfter($uidAll,$pinkT['id']);
- $pinkBool = 1;
- }else $pinkBool = 3;
- }else $pinkBool = 6;
- }
- else{
- if($pinkT['stop_time'] < time()){//拼团时间超时 退款
- if($pinkAll){
- foreach ($pinkAll as $v){
- if($v['uid'] == $this->userInfo['uid']){
- $res = StoreOrder::orderApplyRefund(StoreOrder::where('id',$v['order_id_key'])->value('order_id'),$this->userInfo['uid'],'拼团时间超时');
- if($res){
- if(StorePink::isTpl($v['uid'],$pinkT['id'])) StorePink::orderPinkAfterNo($v['uid'],$v['k_id']);
- $pinkBool = 2;
- }else return JsonService::fail(StoreOrder::getErrorInfo());
- }
- }
- }
- if($pinkT['uid'] == $this->userInfo['uid']){
- $res = StoreOrder::orderApplyRefund(StoreOrder::where('id',$pinkT['order_id_key'])->value('order_id'),$this->userInfo['uid'],'拼团时间超时');
- if($res){
- if(StorePink::isTpl($pinkT['uid'],$pinkT['id'])) StorePink::orderPinkAfterNo($pinkT['uid'],$pinkT['id']);
- $pinkBool = 2;
- }else return JsonService::fail(StoreOrder::getErrorInfo());
- }
- if(!$pinkBool) $pinkBool = 3;
- }
- }
- }
- $store_combination_host = StoreCombination::getCombinationHost();//获取推荐的拼团产品
- if(!empty($pinkAll)){
- foreach ($pinkAll as $v){
- if($v['uid'] == $this->userInfo['uid']) $userBool = 1;
- }
- }
- if($pinkT['uid'] == $this->userInfo['uid']) $userBool = 1;
- $combinationOne = StoreCombination::getCombinationOne($pink['cid']);
- if(!$combinationOne) return JsonService::fail('拼团不存在或已下架');
- $store_combination['userInfo'] = $this->userInfo;
- $data['pinkBool'] = $pinkBool;
- $data['is_ok'] = $is_ok;
- $data['userBool'] = $userBool;
- $data['store_combination'] = $store_combination;
- $data['pinkT'] = $pinkT;
- $data['pinkAll'] = $pinkAll;
- $data['count'] = $count;
- $data['store_combination_host'] = $store_combination_host;
- $data['current_pink_order'] = StorePink::getCurrentPink($id);
- return JsonService::successful($data);
- }
-
- /**
- * 购物车库存修改
- * @param int $cartId
- * @param int $cartNum
- */
- public function set_buy_cart_num($cartId = 0,$cartNum = 0){
- if(!$cartId) return JsonService::fail('参数错误');
- $res = StoreCart::edit(['cart_num'=>$cartNum],$cartId);
- if($res) return JsonService::successful();
- else return JsonService::fail('修改失败');
- }
-
- /**
- * 获取后台联系方式
- */
- public function get_site_phone(){
- $data = SystemConfig::getValue('site_service_phone');
- return JsonService::successful($data);
- }
-
- /**
- * 获取产品链接的二维码
- * @param string $path
- * @param int $width
- */
-// public function get_pages($path = '',$productId = 0,$width = 430){
-// if($path == '' || !$productId) return JsonService::fail('参数错误'); header('content-type:image/jpg');
-// if(!$this->userInfo['uid']) return JsonService::fail('授权失败,请重新授权');
-// $path = 'public/uploads/routinepage/'.$productId.'.jpg';
-// if(file_exists($path)) return JsonService::successful($path);
-// else file_put_contents($path,RoutineCode::getCode($this->userInfo['uid']));
-// return JsonService::successful($path);
-// }
-
- /**
- * 文章列表
- * @param int $cid
- * @param int $first
- * @param int $limit
- */
- public function get_cid_article($cid = 0,$first = 0,$limit = 8){
- $list = ArticleModel::cidByArticleList($cid,$first,$limit,'id,title,image_input,visit,add_time,synopsis,url')?:[];
- foreach ($list as &$article){
- $article['add_time'] = date('Y-m-d H:i',$article['add_time']);
- }
- $data['list'] = $list;
- return JsonService::successful($list);
- }
-
- /**
- * 获取热门文章
- */
- public function get_article_hot(){
- $hot = ArticleModel::getArticleListHot('id,title');
- return JsonService::successful($hot);
- }
-
- /**
- * 获取热门banner文章
- */
- public function get_article_banner(){
- $banner = ArticleModel::getArticleListBanner('id,title,image_input');
- return JsonService::successful($banner);
- }
-
- /**
- * 获取文章详情
- * @param int $id
- */
- public function visit($id = 0)
- {
- $content = ArticleModel::getArticleOne($id);
- if(!$content || !$content["status"]) return JsonService::fail('此文章已经不存在!');
- $content["visit"] = $content["visit"] + 1;
- $content['add_time'] = date('Y-m-d H:i:s',$content['add_time']);
- ArticleModel::edit(['visit'=>$content["visit"]],$id);//增加浏览次数
- return JsonService::successful($content);
- }
-
- /**
- * 产品海报二维码
- * @param int $id
- */
- public function product_promotion_code($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $count = StoreProduct::validWhere()->count();
- if(!$count) return JsonService::fail('参数错误');
- $path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
- $codePath = $path.DS.$id.'_'.$this->userInfo['uid'].'.jpg';
- $domain = SystemConfigService::get('site_url').'/';
- if(!file_exists($codePath)){
- if(!is_dir($path)) mkdir($path,0777,true);
- $res = RoutineCode::getCode($this->userInfo['uid'],$codePath,[],'/pages/product-con/index?id='.$id,'product_spread');
- if($res) file_put_contents($codePath,$res);
- else return JsonService::fail('二维码生成失败');
- }
- return JsonService::successful($domain.$codePath);
- }
-
-
- public function poster($id = 0){
- if(!$id) return JsonService::fail('参数错误');
- $productInfo = StoreProduct::getValidProduct($id,'store_name,id,price,image,code_path');
- if(empty($productInfo)) return JsonService::fail('参数错误');
- if(strlen($productInfo['code_path'])< 10) {
- $path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
- $codePath = $path.DS.$productInfo['id'].'.jpg';
- if(!file_exists($codePath)){
- if(!is_dir($path)) mkdir($path,0777,true);
- $res = file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
- }
- $res = StoreProduct::edit(['code_path'=>$codePath],$id);
- if($res) $productInfo['code_path'] = $codePath;
- else return JsonService::fail('没有查看权限');
- }
- $posterPath = createPoster($productInfo);
- return JsonService::successful($posterPath);
-
-// if(!$id) return JsonService::fail('参数错误');
-// $productInfo = StoreProduct::getValidProduct($id,'store_name,id,price,image,code_path');
-// if(empty($productInfo)) return JsonService::fail('参数错误');
-// if($productInfo['code_path'] == '') {
-// $path = 'public'.DS.'uploads'.DS.'codepath'.DS.'product';
-// $codePath = $path.DS.$productInfo['id'].'.jpg';
-// if(!file_exists($codePath)){
-// //$dir = iconv("UTF-8", "GBK", "public".DS."uploads".DS."codepath".DS."product");
-// if(!is_dir($path))
-// mkdir($path,0777,true);
-// file_put_contents($codePath,RoutineCode::getPages('pages/product-con/index?id='.$productInfo['id']));
-// }
-// $res = StoreProduct::edit(['code_path'=>$codePath],$id);
-// if($res) $productInfo['code_path'] = $codePath;
-// else return JsonService::fail('没有查看权限');
-// }
-// $posterPath = createPoster($productInfo);
-// return JsonService::successful($posterPath);
- }
-
-
- /**
- * 刷新数据缓存
- */
- public function refresh_cache(){
- `php think optimize:schema`;
- `php think optimize:autoload`;
- `php think optimize:route`;
- `php think optimize:config`;
- }
-
-
-
-}
\ No newline at end of file
diff --git a/application/routine/controller/AuthController.php b/application/routine/controller/AuthController.php
deleted file mode 100644
index c6e22d67..00000000
--- a/application/routine/controller/AuthController.php
+++ /dev/null
@@ -1,28 +0,0 @@
-
- * @day: 2017/12/11
- */
-
-namespace app\routine\controller;
-
-use app\routine\model\user\User;
-use service\JsonService;
-use think\Controller;
-use think\Request;
-use think\Session;
-
-class AuthController extends Controller
-{
- public $userInfo = [];
- protected function _initialize()
- {
- parent::_initialize();
- $uid = Request::instance()->get('uid',0);
- $userInfo = User::get($uid);
- if($userInfo) $userInfo->toArray();
- else return JsonService::fail('没有获取用户UID');
- $this->userInfo = $userInfo;//根据uid获取用户信息
- }
-}
\ No newline at end of file
diff --git a/application/routine/controller/Login.php b/application/routine/controller/Login.php
deleted file mode 100644
index 249cb3ba..00000000
--- a/application/routine/controller/Login.php
+++ /dev/null
@@ -1,81 +0,0 @@
-setCode($data['code']);
- if(!isset($res['openid'])) return JsonService::fail('openid获取失败');
- if(isset($res['unionid'])) $data['unionid'] = $res['unionid'];
- else $data['unionid'] = '';
- $data['routine_openid'] = $res['openid'];
- $data['session_key'] = $res['session_key'];
- $dataOauthInfo = RoutineUser::routineOauth($data);
- $data['uid'] = $dataOauthInfo['uid'];
- $data['page'] = $dataOauthInfo['page'];
- $data['status'] = RoutineUser::isUserStatus($data['uid']);
- return JsonService::successful($data);
- }
-
- /**
- * 根据前台传code 获取 openid 和 session_key //会话密匙
- * @param string $code
- * @return array|mixed
- */
- public function setCode($code = ''){
- if($code == '') return [];
- $routineAppId = SystemConfig::getValue('routine_appId');//小程序appID
- $routineAppSecret = SystemConfig::getValue('routine_appsecret');//小程序AppSecret
- $url = 'https://api.weixin.qq.com/sns/jscode2session?appid='.$routineAppId.'&secret='.$routineAppSecret.'&js_code='.$code.'&grant_type=authorization_code';
- return json_decode(RoutineServer::curlGet($url),true);
- }
-
- /**
- * 获取网站logo
- */
- public function get_enter_logo(){
- $siteLogo = SystemConfig::getValue('routine_logo');
- $siteName = SystemConfig::getValue('routine_name');
- $data['site_logo'] = $siteLogo;
- $data['site_name'] = $siteName;
- return JsonService::successful($data);
- }
-
- /**
- * 获取网站顶部颜色
- */
- public function get_routine_style(){
- $routineStyle = SystemConfig::getValue('routine_style');
- $data['routine_style'] = $routineStyle;
- return JsonService::successful($data);
- }
-
- /**
- * 获取客服电话
- */
- public function get_site_service_phone(){
- $siteServicePhone = SystemConfig::getValue('site_service_phone');
- $data['site_service_phone'] = $siteServicePhone;
- return JsonService::successful($data);
- }
-}
\ No newline at end of file
diff --git a/application/routine/controller/Routine.php b/application/routine/controller/Routine.php
deleted file mode 100644
index c0c360b8..00000000
--- a/application/routine/controller/Routine.php
+++ /dev/null
@@ -1,25 +0,0 @@
-where('hide',0)->where('id',$id)->order('id desc')->find();
if($list){
$list = $list->toArray();
$list["content"] = Db::name('articleContent')->where('nid',$id)->value('content');
return $list;
}
else return [];
}
/**
* 获取某个分类底下的文章
* @param $cid
* @param $first
* @param $limit
* @param string $field
* @return mixed
*/
public static function cidByArticleList($cid, $first, $limit, $field = 'id,title,image_input,visit,add_time,synopsis,url')
{
$model = new self();
if ($cid) $model->where("CONCAT(',',cid,',')" ,'LIKE'," '%,$cid,%'");
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->order('sort DESC,add_time DESC');
if($limit) $model = $model->limit($first, $limit);
return $model->select();
}
/**
* 获取热门文章
* @param string $field
* @return mixed
*/
public static function getArticleListHot($field = 'id,title,image_input,visit,add_time,synopsis,url'){
$model = new self();
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->where('is_hot', 1);
$model = $model->order('sort DESC,add_time DESC');
return $model->select();
}
/**
* 获取轮播文章
* @param string $field
* @return mixed
*/
public static function getArticleListBanner($field = 'id,title,image_input,visit,add_time,synopsis,url'){
$model = new self();
$model = $model->field($field);
$model = $model->where('status', 1);
$model = $model->where('hide', 0);
$model = $model->where('is_banner', 1);
$model = $model->order('sort DESC,add_time DESC');
return $model->select();
}
}
\ No newline at end of file
diff --git a/application/routine/model/article/ArticleCategory.php b/application/routine/model/article/ArticleCategory.php
deleted file mode 100644
index 3d74c93a..00000000
--- a/application/routine/model/article/ArticleCategory.php
+++ /dev/null
@@ -1,16 +0,0 @@
- * @day: 2017/11/02 */
-namespace app\routine\model\article;
-
-use traits\ModelTrait;
-use basic\ModelBasic;
-
-
-/**
- * Class ArticleCategory
- * @package app\routine\model\article
- */
-class ArticleCategory extends ModelBasic
-{
- use ModelTrait;
-
-}
\ No newline at end of file
diff --git a/application/routine/model/routine/RoutineCode.php b/application/routine/model/routine/RoutineCode.php
deleted file mode 100644
index a34ce35d..00000000
--- a/application/routine/model/routine/RoutineCode.php
+++ /dev/null
@@ -1,54 +0,0 @@
-id;
- else $data['scene'] = 0;
- if(empty($color)){
- $color['r'] = 0;
- $color['g'] = 0;
- $color['b'] = 0;
- }
- $data['page'] = '';
- $data['width'] = 430;
- $data['auto_color'] = false;
- $data['line_color'] = $color;
- $data['is_hyaline'] = false;
- $resCode = RoutineServer::curlPost($url,json_encode($data));
- if($resCode){
- $dataQrcode['status'] = 1;
- $dataQrcode['url_time'] = time();
- $res = RoutineQrcode::setRoutineQrcodeFind($res->id,$dataQrcode);
- if($res) return $resCode;
- else return false;
- }else return false;
- }else return false;
- }
-
- /**
- * 获取小程序内访问页面的二维码
- * @param string $path
- * @param int $width
- * @return mixed
- */
- public static function getPages($path = '',$width = 430){
- $accessToken = RoutineServer::get_access_token();
- $url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=".$accessToken;
- $data['path'] = $path;
- $data['width'] = $width;
- return RoutineServer::curlPost($url,json_encode($data));
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/routine/RoutineFormId.php b/application/routine/model/routine/RoutineFormId.php
deleted file mode 100644
index e796fefa..00000000
--- a/application/routine/model/routine/RoutineFormId.php
+++ /dev/null
@@ -1,43 +0,0 @@
-where('stop_time','LT',time())->delete();
- }
-
- /**
- * 获取一个可以使用的formId
- * @return bool|mixed
- */
- public static function getFormIdOne($uid = 0){
- $formId = self::where('status',1)->where('stop_time','GT',time())->where('uid',$uid)->order('id asc')->find();
- if($formId) return $formId['form_id'];
- else return false;
- }
-
- /**
- * 修改一个FormID为已使用
- * @param string $formId
- * @return $this|bool
- */
- public static function delFormIdOne($formId = ''){
- if($formId == '') return true;
- return self::where('form_id',$formId)->update(['status'=>2]);
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/routine/RoutineQrcode.php b/application/routine/model/routine/RoutineQrcode.php
deleted file mode 100644
index c7ce2330..00000000
--- a/application/routine/model/routine/RoutineQrcode.php
+++ /dev/null
@@ -1,74 +0,0 @@
-count();
- }
-
- /**
- * 获取小程序二维码信息
- * @param int $id
- * @param string $field
- * @return array|bool|false|\PDOStatement|string|\think\Model
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getRoutineQrcodeFindType($id = 0,$field = 'third_type,third_id,page'){
- if(!$id) return false;
- $count = self::getRoutineQrcodeFind($id);
- if(!$count) return false;
- return self::where('id',$id)->where('status',1)->field($field)->find();
- }
-
-
-}
\ No newline at end of file
diff --git a/application/routine/model/routine/RoutineServer.php b/application/routine/model/routine/RoutineServer.php
deleted file mode 100644
index f0d6a037..00000000
--- a/application/routine/model/routine/RoutineServer.php
+++ /dev/null
@@ -1,88 +0,0 @@
-where('id',1)->find();
- if($accessToken['stop_time'] > time()) return $accessToken['access_token'];
- else{
- $accessToken = self::getAccessToken();
- if(isset($accessToken['access_token'])){
- $data['access_token'] = $accessToken['access_token'];
- $data['stop_time'] = bcadd($accessToken['expires_in'],time(),0);
- Db::name('routine_access_token')->where('id',1)->update($data);
- }
- return $accessToken['access_token'];
- }
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/routine/RoutineTemplate.php b/application/routine/model/routine/RoutineTemplate.php
deleted file mode 100644
index d62a76fb..00000000
--- a/application/routine/model/routine/RoutineTemplate.php
+++ /dev/null
@@ -1,90 +0,0 @@
-find();
- if($formId == '') $formId = RoutineFormId::getFormIdOne($order['uid']);
- $data['keyword1']['value'] = $orderId;
- $data['keyword2']['value'] = date('Y-m-d H:i:s',time());
- $data['keyword3']['value'] = '已支付';
- $data['keyword4']['value'] = $order['pay_price'];
- if($order['pay_type'] == 'yue') $data['keyword5']['value'] = '余额支付';
- else if($order['pay_type'] == 'weixin') $data['keyword5']['value'] = '微信支付';
-// else if($order['pay_type'] == 'offline') $data['keyword5']['value'] = '线下支付';
- RoutineFormId::delFormIdOne($formId);
- RoutineTemplateService::sendTemplate(WechatUser::getOpenId($order['uid']),RoutineTemplateService::setTemplateId(RoutineTemplateService::ORDER_PAY_SUCCESS),'',$data,$formId);
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreBargain.php b/application/routine/model/store/StoreBargain.php
deleted file mode 100644
index 171befab..00000000
--- a/application/routine/model/store/StoreBargain.php
+++ /dev/null
@@ -1,159 +0,0 @@
-
- * @day: 2017/12/18
- */
-
-namespace app\routine\model\store;
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreBargain extends ModelBasic
-{
- use ModelTrait;
-
- /**
- * 正在开启的砍价活动
- * @return $this
- */
- public static function validWhere($status = 1){
- return self::where('is_del',0)->where('status',$status)->where('start_time','LT',time())->where('stop_time','GT',time());
- }
-
- /**
- * 判断砍价产品是否开启
- * @param int $bargainId
- * @return int|string
- */
- public static function validBargain($bargainId = 0){
- $model = self::validWhere();
- return $model->where('id',$bargainId)->count();
- }
- /**
- * 获取正在进行中的砍价产品
- * @param string $field
- */
- public static function getList($field = 'id,product_id,title,price,min_price,image'){
- $model = self::validWhere();
- $list = $model->field($field)->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取一条正在进行中的砍价产品
- * @param int $bargainId
- * @param string $field
- * @return array
- */
- public static function getBargainTerm($bargainId = 0,$field = 'id,product_id,bargain_num,num,unit_name,image,title,price,min_price,image,description,start_time,stop_time,rule'){
- if(!$bargainId) return [];
- $model = self::validWhere();
- $bargain = $model->field($field)->where('id',$bargainId)->find();
- if($bargain) return $bargain->toArray();
- else return [];
- }
-
- /**
- * 获取一条砍价产品
- * @param int $bargainId
- * @param string $field
- * @return array
- */
- public static function getBargain($bargainId = 0,$field = 'id,product_id,title,price,min_price,image'){
- if(!$bargainId) return [];
- $model = new self();
- $bargain = $model->field($field)->where('id',$bargainId)->find();
- if($bargain) return $bargain->toArray();
- else return [];
- }
-
- /**
- * 获取最高价和最低价
- * @param int $bargainId
- * @return array
- */
- public static function getBargainMaxMinPrice($bargainId = 0){
- if(!$bargainId) return [];
- return self::where('id',$bargainId)->field('bargain_min_price,bargain_max_price')->find()->toArray();
- }
-
- /**
- * 获取砍价次数
- * @param int $bargainId
- * @return mixed
- */
- public static function getBargainNum($bargainId = 0){
- return self::where('id',$bargainId)->value('bargain_num');
- }
-
- /**
- * 判断当前砍价是否活动进行中
- * @param int $bargainId
- * @return bool
- */
- public static function setBargainStatus($bargainId = 0){
- $model = self::validWhere();
- $count = $model->where('id',$bargainId)->count();
- if($count) return true;
- else return false;
- }
-
- /**
- * 获取库存
- * @param int $bargainId
- * @return mixed
- */
- public static function getBargainStock($bargainId = 0){
- return self::where('id',$bargainId)->value('stock');
- }
- /**
- * 修改销量和库存
- * @param $num
- * @param $CombinationId
- * @return bool
- */
- public static function decBargainStock($num,$bargainId)
- {
- $res = false !== self::where('id',$bargainId)->dec('stock',$num)->inc('sales',$num)->update();
- return $res;
- }
-
- /**
- * 获取所有砍价产品的浏览量
- * @return array|false|\PDOStatement|string|\think\Model
- */
- public static function getBargainLook(){
- return self::field('sum(look) as look')->find();
- }
-
- /**
- * 获取所有砍价产品的分享量
- * @return array|false|\PDOStatement|string|\think\Model
- */
- public static function getBargainShare(){
- return self::field('sum(share) as share')->find();
- }
-
- /**
- * 添加砍价产品分享次数
- * @param int $id
- * @return bool
- */
- public static function addBargainShare($id = 0){
- if(!$id) return false;
- return self::where('id',$id)->inc('share',1)->update();
- }
-
- /**
- * 添加砍价产品浏览次数
- * @param int $id
- * @return bool
- */
- public static function addBargainLook($id = 0){
- if(!$id) return false;
- return self::where('id',$id)->inc('look',1)->update();
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreBargainUser.php b/application/routine/model/store/StoreBargainUser.php
deleted file mode 100644
index a509ab56..00000000
--- a/application/routine/model/store/StoreBargainUser.php
+++ /dev/null
@@ -1,202 +0,0 @@
-$v){
- if(is_array($v)){
- $uid = self::getUserIdList($v['id']);
- if(count($uid) > 0) {
- $userInfo = User::where('uid','IN',implode(',',$uid))->limit($limit)->column('avatar','uid');
- $bargain[$k]['userInfo'] = $userInfo;
- $bargain[$k]['userInfoCount'] = count($userInfo);
- }
- else {
- $bargain[$k]['userInfo'] = [];
- $bargain[$k]['userInfoCount'] = 0;
- }
- }else{
- $uid = self::getUserIdList($bargain['id']);
- if(count($uid) > 0) $bargain['userInfo'] = User::where('uid','IN',implode(',',$uid))->column('avatar','uid');
- else $bargain['userInfo'] = [];
- }
- }
- return $bargain;
- }
-
- /**
- * 根据砍价产品ID获取正在参与人的uid
- * @param int $bargainId $bargainId 砍价产品ID
- * @param int $status $status 状态 1 进行中 2 结束失败 3结束成功
- * @return array
- */
- public static function getUserIdList($bargainId = 0,$status = 1){
- if(!$bargainId) return [];
- return self::where('bargain_id',$bargainId)->where('status',$status)->column('uid','id');
- }
-
- /**
- * 获取参与的ID
- * @param int $bargainId
- * @param int $uid
- * @param int $status
- * @return array|mixed
- */
- public static function setUserBargain($bargainId = 0,$uid = 0,$status = 1){
- if(!$bargainId || !$uid) return [];
- $bargainIdUserTableId = self::where('bargain_id',$bargainId)->where('uid',$uid)->where('status',$status)->value('id');
- return $bargainIdUserTableId;
- }
-
-
-
- /**
- * 添加一条砍价记录
- * @param int $bargainId
- * @param int $uid
- * @return bool|object
- */
- public static function setBargain($bargainId = 0,$uid = 0){
- if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId) || self::be(['bargain_id'=>$bargainId,'uid'=>$uid,'status'=>1])) return false;
- $data['bargain_id'] = $bargainId;
- $data['uid'] = $uid;
- $data['bargain_price_min'] = StoreBargain::where('id',$bargainId)->value('min_price');
- $data['bargain_price'] = StoreBargain::where('id',$bargainId)->value('price');
- $data['price'] = 0;
- $data['status'] = 1;
- $data['add_time'] = time();
- return self::set($data);
- }
-
-
- /**
- * 判断当前人是否已经参与砍价
- * @param int $bargainId
- * @param int $uid
- * @return bool|mixed
- */
- public static function isBargainUser($bargainId = 0,$uid = 0){
- if(!$bargainId || !$uid || !StoreBargain::validBargain($bargainId)) return false;
- return self::where('bargain_id',$bargainId)->where('uid',$uid)->value('uid');
- }
-
- /**
- * 获取用户砍掉的价格
- * @param int $bargainUserId
- * @return mixed
- */
- public static function getBargainUserPrice($bargainUserId = 0){
- return (float)self::where('id',$bargainUserId)->value('price');
- }
-
-
- /**
- * 获取用户可以砍掉的价格
- * @param int $bargainUserId
- * @return string
- */
- public static function getBargainUserDiffPrice($bargainId = 0,$bargainUserId = 0){
- $price = self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->field('bargain_price,bargain_price_min')->find()->toArray();
- return (float)bcsub($price['bargain_price'],$price['bargain_price_min'],0);
- }
-
- /**
- * 获取砍价表ID
- * @param int $bargainId
- * @param int $bargainUserId
- * @return mixed
- */
- public static function getBargainUserTableId($bargainId = 0,$bargainUserId = 0,$status = 1){
- return self::where('bargain_id',$bargainId)->where('uid',$bargainUserId)->where('status',$status)->value('id');
- }
-
- /**
- * 修改砍价价格
- * @param int $bargainUserTableId
- * @param array $price
- * @return $this|bool
- */
- public static function setBargainUserPrice($bargainUserTableId = 0, $price = array()){
- if(!$bargainUserTableId) return false;
- return self::where('id',$bargainUserTableId)->update($price);
- }
-
- /**
- * 获取用户的砍价产品
- * @param $uid
- * @return array
- */
- public static function getBargainUserAll($uid = 0){
- if(!$uid) return [];
- $model = new self;
- $model = $model->alias('u');
- $model = $model->field('u.id,u.bargain_id,u.bargain_price,u.bargain_price_min,u.price,u.status,b.title,b.image,b.stop_time');
- $model = $model->join('StoreBargain b','b.id=u.bargain_id');
- $model = $model->where('u.uid',$uid);
- $model = $model->order('u.id desc');
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 修改用户砍价状态 支付订单
- * @param int $bargainId
- * @param int $uid
- * @return $this|bool
- */
- public static function setBargainUserStatus($bargainId = 0, $uid = 0){
- $count = self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->count();
- if(!$count) return false;
- $userPrice = (float)self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->value('price');
- $price = self::getBargainUserDiffPrice($bargainId,$uid);
- if(bcsub($price,$userPrice,0) > 0) return false;
- return self::where('uid',$uid)->where('bargain_id',$bargainId)->where('status',1)->update(['status'=>3]);
- }
-
- /**
- * 修改砍价状态为 砍价失败
- * @param int $bargainUserTableId
- * @return $this|bool
- */
- public static function editBargainUserStatus($bargainUserTableId = 0){
- if(!$bargainUserTableId) return false;
- return self::where('id',$bargainUserTableId)->update(['status'=>2]);
- }
-
- /**
- * 获取砍价成功的用户信息
- * @return array|false|\PDOStatement|string|\think\Collection
- */
- public static function getBargainUserStatusSuccess(){
- $bargainUser = self::where('status',3)->order('id desc')->field('uid,bargain_price_min,bargain_id')->select();
- if($bargainUser) {
- $bargainUser = $bargainUser->toArray();
- foreach ($bargainUser as $k=>$v){
- $bargainUser[$k]['info'] = User::where('uid',$v['uid'])->value('nickname').'砍价成功了'.$v['bargain_price_min'].'砍到了'.StoreBargain::where('id',$v['bargain_id'])->value('title');
- }
- }
- else{
- $bargainUser[]['info'] = '砍价上线了,快邀请您的好友来砍价';
- }
- return $bargainUser;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreBargainUserHelp.php b/application/routine/model/store/StoreBargainUserHelp.php
deleted file mode 100644
index 719079e3..00000000
--- a/application/routine/model/store/StoreBargainUserHelp.php
+++ /dev/null
@@ -1,142 +0,0 @@
-limit($limit)->column('uid,price','id');
- if($list){
- foreach ($list as $k=>$v){
- $userInfo = self::getBargainUserHelpUserInfo($v['uid']);
- $list[$k]['nickname'] = $userInfo[$v['uid']]['nickname'];
- $list[$k]['avatar'] = $userInfo[$v['uid']]['avatar'];
- }
- }
- return $list;
- }
-
- /**
- * 获取用的昵称和头像
- * @param int $uid
- * @return array
- */
- public static function getBargainUserHelpUserInfo($uid = 0){
- if(!$uid) return [];
- $userInfo = User::where('uid',$uid)->column('nickname,avatar','uid');
- return $userInfo;
- }
-
- /**
- * 帮忙砍价
- * @param int $bargainId
- * @param int $bargainUserId
- * @param int $uid
- * @return bool|object
- */
- public static function setBargainUserHelp($bargainId = 0,$bargainUserId = 0,$uid = 0){
- if(!self::isBargainUserHelpCount($bargainId,$bargainUserId,$uid) || !$bargainId || !$bargainUserId || !$uid || !StoreBargain::validBargain($bargainId) || !StoreBargainUser::be(['bargain_id'=>$bargainId,'uid'=>$bargainUserId,'status'=>1])) return false;
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- $priceSection = StoreBargain::getBargainMaxMinPrice($bargainId); //获取砍价的价格区间
- $coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
- $alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
- $surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
- $data['uid'] = $uid;
- $data['bargain_id'] = $bargainId;
- $data['bargain_user_id'] = $bargainUserTableId;
- $data['price'] = self::randomFloat($priceSection['bargain_min_price'],$priceSection['bargain_max_price']);
- $data['add_time'] = time();
- if($data['price'] > $surplusPrice) $data['price'] = $surplusPrice;
- $price = bcadd($alreadyPrice,$data['price'],2);
- $bargainUserData['price'] = $price;
- self::beginTrans();
- $res1 = StoreBargainUser::setBargainUserPrice($bargainUserTableId,$bargainUserData);
- $res2 = self::set($data);
- $res = $res1 && $res2;
- self::checkTrans($res);
- if($res) return $data;
- else return $res;
- }
-
- /**
- * 获取俩个数之间的随机数
- * @param int $min
- * @param int $max
- * @return string
- */
- public static function randomFloat($min = 0,$max = 1){
- $num = $min + mt_rand() / mt_getrandmax() * ($max - $min);
- return sprintf("%.2f",$num);
- }
-
- /**
- * 判断用户是否还可以砍价
- * @param int $bargainId
- * @param int $bargainUserUid
- * @param int $bargainUserHelpUid
- * @return bool
- */
- public static function isBargainUserHelpCount($bargainId = 0,$bargainUserUid = 0,$bargainUserHelpUid = 0){
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserUid);
- $bargainNum = StoreBargain::getBargainNum($bargainId);
- $count = self::where('bargain_id',$bargainId)->where('bargain_user_id',$bargainUserTableId)->where('uid',$bargainUserHelpUid)->count();
- if($count < $bargainNum) return true;
- else return false;
- }
-
- /**
- * 获取砍价帮总人数
- * @param int $bargainId
- * @param int $bargainUserId
- * @return int|string
- */
- public static function getBargainUserHelpPeopleCount($bargainId = 0,$bargainUserId = 0){
- if(!$bargainId || !$bargainUserId) return 0;
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- if($bargainUserTableId) return self::where('bargain_user_id',$bargainUserTableId)->where('bargain_id',$bargainId)->count();
- else return 0;
- }
-
- /**
- * 获取用户还剩余的砍价金额
- * @param int $bargainId
- * @param int $bargainUserId
- * @return float
- */
- public static function getSurplusPrice($bargainId = 0,$bargainUserId = 0){
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- $coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
- $alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
- $surplusPrice = (float)bcsub($coverPrice,$alreadyPrice,2);//用户剩余要砍掉的价格
- return $surplusPrice;
- }
-
- /**
- * 获取砍价进度条
- * @param int $bargainId
- * @param int $bargainUserId
- * @return string
- */
- public static function getSurplusPricePercent($bargainId = 0,$bargainUserId = 0){
- $coverPrice = StoreBargainUser::getBargainUserDiffPrice($bargainId,$bargainUserId);//用户可以砍掉的金额
- $bargainUserTableId = StoreBargainUser::getBargainUserTableId($bargainId,$bargainUserId);
- $alreadyPrice= StoreBargainUser::getBargainUserPrice($bargainUserTableId);//用户已经砍掉的价格
- return bcmul(bcdiv($alreadyPrice,$coverPrice,2),100,0);
- }
-}
-
diff --git a/application/routine/model/store/StoreCart.php b/application/routine/model/store/StoreCart.php
deleted file mode 100644
index 14977227..00000000
--- a/application/routine/model/store/StoreCart.php
+++ /dev/null
@@ -1,224 +0,0 @@
-
- * @day: 2017/12/18
- */
-
-namespace app\routine\model\store;
-
-
-use app\routine\model\store\StoreCombination;
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreCart extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- public static function setCart($uid,$product_id,$cart_num = 1,$product_attr_unique = '',$type='product',$is_new = 0,$combination_id=0,$seckill_id = 0,$bargain_id = 0)
- {
- if($cart_num < 1) $cart_num = 1;
- if($seckill_id){
- $StoreSeckillinfo = StoreSeckill::getValidProduct($seckill_id);
- if(!$StoreSeckillinfo)
- return self::setErrorInfo('该产品已下架或删除');
- $userbuycount = StoreOrder::where(['uid'=>$uid,'paid'=>1,'seckill_id'=>$seckill_id])->count();
- if($StoreSeckillinfo['num'] <= $userbuycount)
- return self::setErrorInfo('每人限购'.$StoreSeckillinfo['num'].'一件');
- if(StoreSeckill::getProductStock($seckill_id) < $cart_num)
- return self::setErrorInfo('该产品库存不足'.$cart_num);
- $where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'seckill_id'=>$seckill_id];
- if($cart = self::where($where)->find()){
- $cart->cart_num = $cart_num;
- $cart->add_time = time();
- $cart->save();
- return $cart;
- }else{
- return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','seckill_id'));
- }
- }elseif($bargain_id){
- if(!StoreBargain::validBargain($bargain_id))
- return self::setErrorInfo('该产品已下架或删除');
- if(StoreBargain::getBargainStock($bargain_id) < $cart_num)
- return self::setErrorInfo('该产品库存不足'.$cart_num);
- $where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'bargain_id'=>$bargain_id];
- if($cart = self::where($where)->find()){
- $cart->cart_num = $cart_num;
- $cart->add_time = time();
- $cart->save();
- return $cart;
- }else{
- return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','bargain_id'));
- }
- }elseif($combination_id){//拼团
- if(!StoreCombination::getCombinationStock($combination_id,$cart_num))
- return self::setErrorInfo('该产品库存不足'.$cart_num);
- if(!StoreCombination::isValidCombination($combination_id))
- return self::setErrorInfo('该产品已下架或删除');
- }else{
- if(!StoreProduct::isValidProduct($product_id))
- return self::setErrorInfo('该产品已下架或删除');
- if(!StoreProductAttr::issetProductUnique($product_id,$product_attr_unique))
- return self::setErrorInfo('请选择有效的产品属性');
- if(StoreProduct::getProductStock($product_id,$product_attr_unique) < $cart_num)
- return self::setErrorInfo('该产品库存不足'.$cart_num);
- }
- $where = ['type'=>$type,'uid'=>$uid,'product_id'=>$product_id,'product_attr_unique'=>$product_attr_unique,'is_new'=>$is_new,'is_pay'=>0,'is_del'=>0,'combination_id'=>$combination_id];
- if($cart = self::where($where)->find()){
- $cart->cart_num = $cart_num;
- $cart->add_time = time();
- $cart->save();
- return $cart;
- }else{
- return self::set(compact('uid','product_id','cart_num','product_attr_unique','is_new','type','combination_id'));
- }
-
- }
-
- public static function removeUserCart($uid,$ids)
- {
- return self::where('uid',$uid)->where('id','IN',$ids)->update(['is_del'=>1]);
- }
-
- public static function getUserCartNum($uid,$type)
- {
- return self::where('uid',$uid)->where('type',$type)->where('is_pay',0)->where('is_del',0)->where('is_new',0)->count();
- }
-
- public static function changeUserCartNum($cartId,$cartNum,$uid)
- {
- return self::where('uid',$uid)->where('id',$cartId)->update(['cart_num'=>$cartNum]);
- }
-
- public static function getUserProductCartList($uid,$cartIds='',$status=0)
- {
- $productInfoField = 'id,image,slider_image,price,ot_price,vip_price,postage,mer_id,give_integral,cate_id,sales,stock,store_name,store_info,unit_name,is_show,is_del,is_postage,cost';
- $seckillInfoField = 'id,image,price,ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,is_show,is_del,is_postage,cost';
- $bargainInfoField = 'id,image,min_price as price,price as ot_price,postage,give_integral,sales,stock,title as store_name,unit_name,status as is_show,is_del,is_postage,cost';
- $combinationInfoField = 'id,image,price,postage,sales,stock,title as store_name,is_show,is_del,is_postage,cost';
- $model = new self();
- $valid = $invalid = [];
- $model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
- ->where('is_del',0);
- if(!$status) $model->where('is_new',0);
- if($cartIds) $model->where('id','IN',$cartIds);
- $list = $model->select()->toArray();
- if(!count($list)) return compact('valid','invalid');
- foreach ($list as $k=>$cart){
- if($cart['seckill_id']){
- $product = StoreSeckill::field($seckillInfoField)
- ->find($cart['seckill_id'])->toArray();
- }elseif($cart['bargain_id']){
- $product = StoreBargain::field($bargainInfoField)
- ->find($cart['bargain_id'])->toArray();
- }elseif($cart['combination_id']){
- $product = StoreCombination::field($combinationInfoField)
- ->find($cart['combination_id'])->toArray();
- }else{
- $product = StoreProduct::field($productInfoField)
- ->find($cart['product_id'])->toArray();
- }
- $cart['productInfo'] = $product;
- //商品不存在
- if(!$product){
- $model->where('id',$cart['id'])->update(['is_del'=>1]);
- //商品删除或无库存
- }else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
- $invalid[] = $cart;
- //商品属性不对应
- }else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique']) && !$cart['combination_id'] && !$cart['seckill_id']){
- $invalid[] = $cart;
- //正常商品
- }else{
- if($cart['product_attr_unique']){
- $attrInfo = StoreProductAttr::uniqueByAttrInfo($cart['product_attr_unique']);
- //商品没有对应的属性
- if(!$attrInfo || !$attrInfo['stock'])
- $invalid[] = $cart;
- else{
- $cart['productInfo']['attrInfo'] = $attrInfo;
- $cart['truePrice'] = (float)$attrInfo['price'];
- $cart['trueStock'] = $attrInfo['stock'];
- $cart['costPrice'] = $cart['productInfo']['cost'];
- $cart['productInfo']['image'] = empty($attrInfo['image']) ? $cart['productInfo']['image'] : $attrInfo['image'];
- $valid[] = $cart;
- }
- }else{
- $cart['truePrice'] = (float)$cart['productInfo']['price'];
- $cart['trueStock'] = $cart['productInfo']['stock'];
- $cart['costPrice'] = $cart['productInfo']['cost'];
- $valid[] = $cart;
- }
- }
- }
-
- foreach ($valid as $k=>$cart){
- if($cart['trueStock'] < $cart['cart_num']){
- $cart['cart_num'] = $cart['trueStock'];
- $model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
- $valid[$k] = $cart;
- }
- }
-
- return compact('valid','invalid');
- }
-
- /**
- * 拼团
- * @param $uid
- * @param string $cartIds
- * @return array
- */
- public static function getUserCombinationProductCartList($uid,$cartIds='')
- {
- $productInfoField = 'id,image,slider_image,price,cost,ot_price,vip_price,postage,mer_id,give_integral,cate_id,sales,stock,store_name,unit_name,is_show,is_del,is_postage';
- $model = new self();
- $valid = $invalid = [];
- $model = $model->where('uid',$uid)->where('type','product')->where('is_pay',0)
- ->where('is_del',0);
- if($cartIds) $model->where('id','IN',$cartIds);
- $list = $model->select()->toArray();
- if(!count($list)) return compact('valid','invalid');
- foreach ($list as $k=>$cart){
- $product = StoreProduct::field($productInfoField)
- ->find($cart['product_id'])->toArray();
- $cart['productInfo'] = $product;
- //商品不存在
- if(!$product){
- $model->where('id',$cart['id'])->update(['is_del'=>1]);
- //商品删除或无库存
- }else if(!$product['is_show'] || $product['is_del'] || !$product['stock']){
- $invalid[] = $cart;
- //商品属性不对应
-// }else if(!StoreProductAttr::issetProductUnique($cart['product_id'],$cart['product_attr_unique'])){
-// $invalid[] = $cart;
- //正常商品
- }else{
- $cart['truePrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('price');
- $cart['costPrice'] = (float)StoreCombination::where('id',$cart['combination_id'])->value('cost');
- $cart['trueStock'] = StoreCombination::where('id',$cart['combination_id'])->value('stock');
- $valid[] = $cart;
- }
- }
-
- foreach ($valid as $k=>$cart){
- if($cart['trueStock'] < $cart['cart_num']){
- $cart['cart_num'] = $cart['trueStock'];
- $model->where('id',$cart['id'])->update(['cart_num'=>$cart['cart_num']]);
- $valid[$k] = $cart;
- }
- }
-
- return compact('valid','invalid');
- }
-
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCategory.php b/application/routine/model/store/StoreCategory.php
deleted file mode 100644
index 8a2968f7..00000000
--- a/application/routine/model/store/StoreCategory.php
+++ /dev/null
@@ -1,32 +0,0 @@
-
- * @day: 2017/12/12
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-
-class StoreCategory extends ModelBasic
-{
- public static function pidByCategory($pid,$field = '*',$limit = 0)
- {
- $model = self::where('pid',$pid)->where('is_show',1)->field($field);
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
- public static function pidBySidList($pid)
- {
- return self::where('pid',$pid)->field('id,cate_name,pid')->select();
- }
-
- public static function cateIdByPid($cateId)
- {
- return self::where('id',$cateId)->value('pid');
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCombination.php b/application/routine/model/store/StoreCombination.php
deleted file mode 100644
index 2ba1f316..00000000
--- a/application/routine/model/store/StoreCombination.php
+++ /dev/null
@@ -1,160 +0,0 @@
-
- * @day: 2017/11/11
- */
-
-namespace app\routine\model\store;
-
-
-use traits\ModelTrait;
-use basic\ModelBasic;
-
-/**
- * 拼团model
- * Class StoreCombination
- * @package app\routine\model\store
- */
-class StoreCombination extends ModelBasic
-{
- use ModelTrait;
-
- /**
- * @param $where
- * @return array
- */
- public static function get_list($length=10){
- if($post=input('post.')){
- $where=$post['where'];
- $model = new self();
- $model = $model->alias('c');
- $model = $model->join('StoreProduct s','s.id=c.product_id');
- $model = $model->where('c.is_show',1)->where('c.is_del',0)->where('c.start_time','LT',time())->where('c.stop_time','GT',time());
- if(!empty($where['search'])){
- $model = $model->where('c.title','like',"%{$where['search']}%");
- $model = $model->whereOr('s.keyword','like',"{$where['search']}%");
- }
- $model = $model->field('c.*,s.price as product_price');
- if($where['key']){
- if($where['sales']==1){
- $model = $model->order('c.sales desc');
- }else if($where['sales']==2){
- $model = $model->order('c.sales asc');
- }
- if($where['price']==1){
- $model = $model->order('c.price desc');
- }else if($where['price']==2){
- $model = $model->order('c.price asc');
- }
- if($where['people']==1){
- $model = $model->order('c.people asc');
- }
- if($where['default']==1){
- $model = $model->order('c.sort desc,c.id desc');
- }
- }else{
- $model = $model->order('c.sort desc,c.id desc');
- }
- $page=is_string($where['page'])?(int)$where['page']+1:$where['page']+1;
- $list = $model->page($page,$length)->select()->toArray();
- return ['list'=>$list,'page'=>$page];
- }
- }
-
- /**
- * 获取所有拼团数据
- * @param int $limit
- * @param int $length
- * @return mixed
- */
- public static function getAll($limit = 0,$length = 0){
- $model = new self();
- $model = $model->alias('c');
- $model = $model->join('StoreProduct s','s.id=c.product_id');
- $model = $model->field('c.*,s.price as product_price');
- $model = $model->order('c.sort desc,c.id desc');
- $model = $model->where('c.is_show',1);
- $model = $model->where('c.is_del',0);
- $model = $model->where('c.start_time','LT',time());
- $model = $model->where('c.stop_time','GT',time());
- if($limit && $length) $model = $model->limit($limit,$length);
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取一条拼团数据
- * @param $id
- * @return mixed
- */
- public static function getCombinationOne($id){
- $model = new self();
- $model = $model->alias('c');
- $model = $model->join('StoreProduct s','s.id=c.product_id');
- $model = $model->field('c.*,s.price as product_price');
- $model = $model->where('c.is_show',1);
- $model = $model->where('c.is_del',0);
- $model = $model->where('c.id',$id);
-// $model = $model->where('c.start_time','LT',time());
-// $model = $model->where('c.stop_time','GT',time()-86400);
- $list = $model->find();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取推荐的拼团产品
- * @return mixed
- */
- public static function getCombinationHost($limit = 0){
- $model = new self();
- $model = $model->alias('c');
- $model = $model->join('StoreProduct s','s.id=c.product_id');
- $model = $model->field('c.id,c.image,c.price,c.sales,c.title,c.people,s.price as product_price');
- $model = $model->where('c.is_del',0);
- $model = $model->where('c.is_host',1);
- $model = $model->where('c.start_time','LT',time());
- $model = $model->where('c.stop_time','GT',time());
- if($limit) $model = $model->limit($limit);
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 修改销量和库存
- * @param $num
- * @param $CombinationId
- * @return bool
- */
- public static function decCombinationStock($num,$CombinationId)
- {
- $res = false !== self::where('id',$CombinationId)->dec('stock',$num)->inc('sales',$num)->update();
- return $res;
- }
- /**
- * 判断库存是否足够
- * @param $id
- * @param $cart_num
- * @return int|mixed
- */
- public static function getCombinationStock($id,$cart_num){
- $stock = self::where('id',$id)->value('stock');
- return $stock > $cart_num ? $stock : 0;
- }
- /**
- * 获取产品状态
- * @param $id
- * @return mixed
- */
- public static function isValidCombination($id){
- $model = new self();
- $model = $model->where('id',$id);
- $model = $model->where('is_del',0);
- $model = $model->where('is_show',1);
- return $model->count();
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCoupon.php b/application/routine/model/store/StoreCoupon.php
deleted file mode 100644
index 6badd04c..00000000
--- a/application/routine/model/store/StoreCoupon.php
+++ /dev/null
@@ -1,17 +0,0 @@
-
- * @day: 2018/01/22
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreCoupon extends ModelBasic
-{
- use ModelTrait;
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCouponIssue.php b/application/routine/model/store/StoreCouponIssue.php
deleted file mode 100644
index 237cfb1c..00000000
--- a/application/routine/model/store/StoreCouponIssue.php
+++ /dev/null
@@ -1,60 +0,0 @@
-
- * @day: 2018/01/18
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreCouponIssue extends ModelBasic
-{
- use ModelTrait;
-
- /**
- * @param string $prefix
- * @return $this
- */
- public static function validWhere($prefix = '')
- {
- $model = new self;
- if($prefix){
- $model->alias($prefix);
- $prefix .= '.';
- }
- $newTime = time();
- return $model->where("{$prefix}status",1)
- ->where(function($query) use($newTime,$prefix){
- $query->where(function($query) use($newTime,$prefix){
- $query->where("{$prefix}start_time",'<',$newTime)->where("{$prefix}end_time",'>',$newTime);
- })->whereOr(function ($query) use($prefix){
- $query->where("{$prefix}start_time",0)->where("{$prefix}end_time",0);
- });
- })->where("{$prefix}is_del",0);
- }
-
-
- public static function issueUserCoupon($id,$uid)
- {
- $issueCouponInfo = self::validWhere()->where('id',$id)->find();
- if(!$issueCouponInfo) return self::setErrorInfo('领取的优惠劵已领完或已过期!');
- if(StoreCouponIssueUser::be(['uid'=>$uid,'issue_coupon_id'=>$id]))
- return self::setErrorInfo('已领取过该优惠劵!');
- self::beginTrans();
- $res1 = false != StoreCouponUser::addUserCoupon($uid,$issueCouponInfo['cid']);
- $res2 = false != StoreCouponIssueUser::addUserIssue($uid,$id);
- $res3 = true;
- if($issueCouponInfo['total_count'] > 0){
- $issueCouponInfo['remain_count'] -= 1;
- $res3 = false !== $issueCouponInfo->save();
- }
- $res = $res1 && $res2 & $res3;
- self::checkTrans($res);
- return $res;
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCouponIssueUser.php b/application/routine/model/store/StoreCouponIssueUser.php
deleted file mode 100644
index d3bb3237..00000000
--- a/application/routine/model/store/StoreCouponIssueUser.php
+++ /dev/null
@@ -1,22 +0,0 @@
-
- * @day: 2018/01/22
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreCouponIssueUser extends ModelBasic
-{
- use ModelTrait;
- public static function addUserIssue($uid,$issue_coupon_id)
- {
- $add_time = time();
- return self::set(compact('uid','issue_coupon_id','add_time'));
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreCouponUser.php b/application/routine/model/store/StoreCouponUser.php
deleted file mode 100644
index 31114bb8..00000000
--- a/application/routine/model/store/StoreCouponUser.php
+++ /dev/null
@@ -1,146 +0,0 @@
-
- * @day: 2017/12/20
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreCouponUser extends ModelBasic
-{
- use ModelTrait;
- /**
- * 获取用户优惠券(全部)
- * @return \think\response\Json
- */
- public static function getUserAllCoupon($uid)
- {
- self::checkInvalidCoupon();
- $couponList = self::where('uid',$uid)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
- return self::tidyCouponList($couponList);
- }
- /**
- * 获取用户优惠券(未使用)
- * @return \think\response\Json
- */
- public static function getUserValidCoupon($uid)
- {
- self::checkInvalidCoupon();
- $couponList = self::where('uid',$uid)->where('status',0)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
- return self::tidyCouponList($couponList);
- }
- /**
- * 获取用户优惠券(已使用)
- * @return \think\response\Json
- */
- public static function getUserAlreadyUsedCoupon($uid)
- {
- self::checkInvalidCoupon();
- $couponList = self::where('uid',$uid)->where('status',1)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
- return self::tidyCouponList($couponList);
- }
- /**
- * 获取用户优惠券(已过期)
- * @return \think\response\Json
- */
- public static function getUserBeOverdueCoupon($uid)
- {
- self::checkInvalidCoupon();
- $couponList = self::where('uid',$uid)->where('status',2)->order('is_fail ASC,status ASC,add_time DESC')->select()->toArray();
- return self::tidyCouponList($couponList);
- }
- public static function beUsableCoupon($uid,$price)
- {
- return self::where('uid',$uid)->where('is_fail',0)->where('status',0)->where('use_min_price','<=',$price)->find();
- }
-
- /**
- * 获取用户可以使用的优惠券
- * @param $uid
- * @param $price
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function beUsableCouponList($uid,$price){
- return self::where('uid',$uid)->where('is_fail',0)->where('status',0)->where('use_min_price','<=',$price)->select();
- }
-
- public static function validAddressWhere($model=null,$prefix = '')
- {
- self::checkInvalidCoupon();
- if($prefix) $prefix .='.';
- $model = self::getSelfModel($model);
- return $model->where("{$prefix}is_fail",0)->where("{$prefix}status",0);
- }
-
- public static function checkInvalidCoupon()
- {
- self::where('end_time','<',time())->where('status',0)->update(['status'=>2]);
- }
-
- public static function tidyCouponList($couponList)
- {
- $time = time();
- foreach ($couponList as $k=>$coupon){
- $coupon['_add_time'] = date('Y/m/d',$coupon['add_time']);
- $coupon['_end_time'] = date('Y/m/d',$coupon['end_time']);
- $coupon['use_min_price'] = floatval($coupon['use_min_price']);
- $coupon['coupon_price'] = floatval($coupon['coupon_price']);
- if($coupon['is_fail']){
- $coupon['_type'] = 0;
- $coupon['_msg'] = '已失效';
- }else if ($coupon['status'] == 1){
- $coupon['_type'] = 0;
- $coupon['_msg'] = '已使用';
- }else if ($coupon['status'] == 2){
- $coupon['_type'] = 0;
- $coupon['_msg'] = '已过期';
- }else if($coupon['add_time'] > $time || $coupon['end_time'] < $time){
- $coupon['_type'] = 0;
- $coupon['_msg'] = '已过期';
- }else{
- if($coupon['add_time']+ 3600*24 > $time){
- $coupon['_type'] = 2;
- $coupon['_msg'] = '可使用';
- }else{
- $coupon['_type'] = 1;
- $coupon['_msg'] = '可使用';
- }
- }
- $couponList[$k] = $coupon;
- }
- return $couponList;
- }
-
- public static function getUserValidCouponCount($uid)
- {
- self::checkInvalidCoupon();
- return self::where('uid',$uid)->where('status',0)->order('is_fail ASC,status ASC,add_time DESC')->count();
- }
-
- public static function useCoupon($id)
- {
- return self::where('id',$id)->update(['status'=>1,'use_time'=>time()]);
- }
-
- public static function addUserCoupon($uid,$cid,$type = 'get')
- {
- $couponInfo = StoreCoupon::find($cid);
- if(!$couponInfo) return self::setErrorInfo('优惠劵不存在!');
- $data = [];
- $data['cid'] = $couponInfo['id'];
- $data['uid'] = $uid;
- $data['coupon_title'] = $couponInfo['title'];
- $data['coupon_price'] = $couponInfo['coupon_price'];
- $data['use_min_price'] = $couponInfo['use_min_price'];
- $data['add_time'] = time();
- $data['end_time'] = $data['add_time']+$couponInfo['coupon_time']*86400;
- $data['type'] = $type;
- return self::set($data);
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreOrder.php b/application/routine/model/store/StoreOrder.php
deleted file mode 100644
index 34442e2e..00000000
--- a/application/routine/model/store/StoreOrder.php
+++ /dev/null
@@ -1,753 +0,0 @@
-
- * @day: 2017/12/20
- */
-
-namespace app\routine\model\store;
-
-
-use app\routine\model\store\StoreCombination;
-use app\routine\model\routine\RoutineFormId;
-use app\routine\model\routine\RoutineTemplate;
-use app\routine\model\store\StoreOrderCartInfo;
-use app\routine\model\store\StoreOrderStatus;
-use app\routine\model\store\StoreCart;
-use app\routine\model\store\StoreProductReply;
-use app\routine\model\user\User;
-use app\routine\model\user\UserAddress;
-use app\routine\model\user\UserBill;
-use app\routine\model\user\WechatUser;
-use basic\ModelBasic;
-use behavior\routine\StoreProductBehavior;
-use behavior\wechat\PaymentBehavior;
-use service\HookService;
-use service\RoutineService;
-use service\SystemConfigService;
-use service\WechatService;
-use service\WechatTemplateService;
-use think\Cache;
-use think\Url;
-use traits\ModelTrait;
-
-class StoreOrder extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected static $payType = ['weixin'=>'微信支付','yue'=>'余额支付','offline'=>'线下支付'];
-
- protected static $deliveryType = ['send'=>'商家配送','express'=>'快递配送'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- protected function setCartIdAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
-
- protected function getCartIdAttr($value)
- {
- return json_decode($value,true);
- }
-
- public static function getOrderPriceGroup($cartInfo)
- {
- $storePostage = floatval(SystemConfigService::get('store_postage'))?:0;
- $storeFreePostage = floatval(SystemConfigService::get('store_free_postage'))?:0;
- $totalPrice = self::getOrderTotalPrice($cartInfo);
- $costPrice = self::getOrderCostPrice($cartInfo);
- if(!$storeFreePostage) {
- $storePostage = 0;
- }else{
- foreach ($cartInfo as $cart){
- if(!$cart['productInfo']['is_postage'])
- $storePostage = bcadd($storePostage,$cart['productInfo']['postage'],2);
-
- }
- if($storeFreePostage <= $totalPrice) $storePostage = 0;
- }
- return compact('storePostage','storeFreePostage','totalPrice','costPrice');
- }
-
- public static function getOrderTotalPrice($cartInfo)
- {
- $totalPrice = 0;
- foreach ($cartInfo as $cart){
- $totalPrice = bcadd($totalPrice,bcmul($cart['cart_num'],$cart['truePrice'],2),2);
- }
- return $totalPrice;
- }
- public static function getOrderCostPrice($cartInfo)
- {
- $costPrice=0;
- foreach ($cartInfo as $cart){
- $costPrice = bcadd($costPrice,bcmul($cart['cart_num'],$cart['costPrice'],2),2);
- }
- return $costPrice;
- }
-
-
-
- /**
- * 拼团
- * @param $cartInfo
- * @return array
- */
- public static function getCombinationOrderPriceGroup($cartInfo)
- {
- $storePostage = floatval(SystemConfigService::get('store_postage'))?:0;
- $storeFreePostage = floatval(SystemConfigService::get('store_free_postage'))?:0;
- $totalPrice = self::getCombinationOrderTotalPrice($cartInfo);
- $costPrice = self::getCombinationOrderCostPrice($cartInfo);
- if(!$storeFreePostage) {
- $storePostage = 0;
- }else{
- foreach ($cartInfo as $cart){
- if(!StoreCombination::where('id',$cart['combination_id'])->value('is_postage'))
- $storePostage = bcadd($storePostage,StoreCombination::where('id',$cart['combination_id'])->value('postage'),2);
- }
- if($storeFreePostage <= $totalPrice) $storePostage = 0;
- }
- return compact('storePostage','storeFreePostage','totalPrice','costPrice');
- }
-
-
- /**
- * 拼团价格
- * @param $cartInfo
- * @return float
- */
- public static function getCombinationOrderTotalPrice($cartInfo)
- {
- $totalPrice = 0;
- foreach ($cartInfo as $cart){
- if($cart['combination_id']){
- $totalPrice = bcadd($totalPrice,bcmul($cart['cart_num'],StoreCombination::where('id',$cart['combination_id'])->value('price'),2),2);
- }
- }
- return (float)$totalPrice;
- }
- public static function getCombinationOrderCostPrice($cartInfo)
- {
- $costPrice = 0;
- foreach ($cartInfo as $cart){
- if($cart['combination_id']){
- $totalPrice = bcadd($costPrice,bcmul($cart['cart_num'],StoreCombination::where('id',$cart['combination_id'])->value('price'),2),2);
- }
- }
- return (float)$costPrice;
- }
-
-
- public static function cacheOrderInfo($uid,$cartInfo,$priceGroup,$other = [],$cacheTime = 600)
- {
- $key = md5(time());
- Cache::set('user_order_'.$uid.$key,compact('cartInfo','priceGroup','other'),$cacheTime);
- return $key;
- }
-
- public static function getCacheOrderInfo($uid,$key)
- {
- $cacheName = 'user_order_'.$uid.$key;
- if(!Cache::has($cacheName)) return null;
- return Cache::get($cacheName);
- }
-
- public static function clearCacheOrderInfo($uid,$key)
- {
- Cache::clear('user_order_'.$uid.$key);
- }
-
- public static function cacheKeyCreateOrder($uid,$key,$addressId,$payType,$useIntegral = false,$couponId = 0,$mark = '',$combinationId = 0,$pinkId = 0,$seckill_id=0,$bargain_id=0)
- {
- if(!array_key_exists($payType,self::$payType)) return self::setErrorInfo('选择支付方式有误!');
- if(self::be(['unique'=>$key,'uid'=>$uid])) return self::setErrorInfo('请勿重复提交订单');
- $userInfo = User::getUserInfo($uid);
- if(!$userInfo) return self::setErrorInfo('用户不存在!');
- $cartGroup = self::getCacheOrderInfo($uid,$key);
- if(!$cartGroup) return self::setErrorInfo('订单已过期,请刷新当前页面!');
- $cartInfo = $cartGroup['cartInfo'];
- $priceGroup = $cartGroup['priceGroup'];
- $other = $cartGroup['other'];
- $payPrice = $priceGroup['totalPrice'];
- $payPostage = $priceGroup['storePostage'];
- if(!$addressId) return self::setErrorInfo('请选择收货地址!');
- if(!UserAddress::be(['uid'=>$uid,'id'=>$addressId,'is_del'=>0]) || !($addressInfo = UserAddress::find($addressId)))
- return self::setErrorInfo('地址选择有误!');
-
- //使用优惠劵
- $res1 = true;
- if($couponId){
- $couponInfo = StoreCouponUser::validAddressWhere()->where('id',$couponId)->where('uid',$uid)->find();
- if(!$couponInfo) return self::setErrorInfo('选择的优惠劵无效!');
- if($couponInfo['use_min_price'] > $payPrice)
- return self::setErrorInfo('不满足优惠劵的使用条件!');
- $payPrice = bcsub($payPrice,$couponInfo['coupon_price'],2);
- $res1 = StoreCouponUser::useCoupon($couponId);
- $couponPrice = $couponInfo['coupon_price'];
- }else{
- $couponId = 0;
- $couponPrice = 0;
- }
- if(!$res1) return self::setErrorInfo('使用优惠劵失败!');
-
- //是否包邮
- if((isset($other['offlinePostage']) && $other['offlinePostage'] && $payType == 'offline')) $payPostage = 0;
- $payPrice = bcadd($payPrice,$payPostage,2);
-
- //积分抵扣
- $res2 = true;
- if($useIntegral && $userInfo['integral'] > 0){
- $deductionPrice = bcmul($userInfo['integral'],$other['integralRatio'],2);
- if($deductionPrice < $payPrice){
- $payPrice = bcsub($payPrice,$deductionPrice,2);
- $usedIntegral = $userInfo['integral'];
- $res2 = false !== User::edit(['integral'=>0],$userInfo['uid'],'uid');
- }else{
- $deductionPrice = $payPrice;
- $usedIntegral = bcdiv($payPrice,$other['integralRatio'],2);
- $res2 = false !== User::bcDec($userInfo['uid'],'integral',$usedIntegral,'uid');
- $payPrice = 0;
- }
- $res2 = $res2 && false != UserBill::expend('积分抵扣',$uid,'integral','deduction',$usedIntegral,$key,$userInfo['integral'],'购买商品使用'.floatval($usedIntegral).'积分抵扣'.floatval($deductionPrice).'元');
- }else{
- $deductionPrice = 0;
- $usedIntegral = 0;
- }
- if(!$res2) return self::setErrorInfo('使用积分抵扣失败!');
-
- $cartIds = [];
- $totalNum = 0;
- $gainIntegral = 0;
- foreach ($cartInfo as $cart){
- $cartIds[] = $cart['id'];
- $totalNum += $cart['cart_num'];
- $gainIntegral = bcadd($gainIntegral,isset($cart['productInfo']['give_integral']) ? : 0,2);
- }
- $orderInfo = [
- 'uid'=>$uid,
- 'order_id'=>self::getNewOrderId(),
- 'real_name'=>$addressInfo['real_name'],
- 'user_phone'=>$addressInfo['phone'],
- 'user_address'=>$addressInfo['province'].' '.$addressInfo['city'].' '.$addressInfo['district'].' '.$addressInfo['detail'],
- 'cart_id'=>$cartIds,
- 'total_num'=>$totalNum,
- 'total_price'=>$priceGroup['totalPrice'],
- 'total_postage'=>$priceGroup['storePostage'],
- 'coupon_id'=>$couponId,
- 'coupon_price'=>$couponPrice,
- 'pay_price'=>$payPrice,
- 'pay_postage'=>$payPostage,
- 'deduction_price'=>$deductionPrice,
- 'paid'=>0,
- 'pay_type'=>$payType,
- 'use_integral'=>$usedIntegral,
- 'gain_integral'=>$gainIntegral,
- 'mark'=>htmlspecialchars($mark),
- 'combination_id'=>$combinationId,
- 'pink_id'=>$pinkId,
- 'seckill_id'=>$seckill_id,
- 'bargain_id'=>$bargain_id,
- 'cost'=>$priceGroup['costPrice'],
- 'is_channel'=>1,
- 'unique'=>$key
- ];
- $order = self::set($orderInfo);
- if(!$order)return self::setErrorInfo('订单生成失败!');
- $res5 = true;
- foreach ($cartInfo as $cart){
- //减库存加销量
- if($combinationId) $res5 = $res5 && StoreCombination::decCombinationStock($cart['cart_num'],$combinationId);
- else if($seckill_id) $res5 = $res5 && StoreSeckill::decSeckillStock($cart['cart_num'],$seckill_id);
- else if($bargain_id) $res5 = $res5 && StoreBargain::decBargainStock($cart['cart_num'],$bargain_id);
- else $res5 = $res5 && StoreProduct::decProductStock($cart['cart_num'],$cart['productInfo']['id'],isset($cart['productInfo']['attrInfo']) ? $cart['productInfo']['attrInfo']['unique']:'');
- }
- //保存购物车商品信息
- $res4 = false !== StoreOrderCartInfo::setCartInfo($order['id'],$cartInfo);
- //购物车状态修改
- $res6 = false !== StoreCart::where('id','IN',$cartIds)->update(['is_pay'=>1]);
- if(!$res4 || !$res5 || !$res6) return self::setErrorInfo('订单生成失败!');
- try{
- HookService::listen('store_product_order_create',$order,compact('cartInfo','addressId'),false,StoreProductBehavior::class);
- }catch (\Exception $e){
- return self::setErrorInfo($e->getMessage());
- }
- self::clearCacheOrderInfo($uid,$key);
- self::commitTrans();
- StoreOrderStatus::status($order['id'],'cache_key_create_order','订单生成');
- return $order;
- }
-
- public static function getNewOrderId()
- {
- $count = (int) self::where('add_time',['>=',strtotime(date("Y-m-d"))],['<',strtotime(date("Y-m-d",strtotime('+1 day')))])->count();
- return 'wx'.date('YmdHis',time()).(10000+$count+1);
- }
-
- public static function changeOrderId($orderId)
- {
- $ymd = substr($orderId,2,8);
- $key = substr($orderId,16);
- return 'wx'.$ymd.date('His').$key;
- }
-
- public static function jsPay($orderId,$field = 'order_id')
- {
- if(is_string($orderId))
- $orderInfo = self::where($field,$orderId)->find();
- else
- $orderInfo = $orderId;
- if(!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
- if($orderInfo['paid']) exception('支付已支付!');
- if($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
- $openid = WechatUser::getOpenId($orderInfo['uid']);
- return RoutineService::payRoutine($openid,$orderInfo['order_id'],$orderInfo['pay_price'],'productr',SystemConfigService::get('site_name'));
- }
-
- public static function yuePay($order_id,$uid,$formId = '')
- {
- $orderInfo = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->find();
- if(!$orderInfo) return self::setErrorInfo('订单不存在!');
- if($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
- if($orderInfo['pay_type'] != 'yue') return self::setErrorInfo('该订单不能使用余额支付!');
- $userInfo = User::getUserInfo($uid);
- if($userInfo['now_money'] < $orderInfo['pay_price'])
- return self::setErrorInfo('余额不足'.floatval($orderInfo['pay_price']));
- self::beginTrans();
- $res1 = false !== User::bcDec($uid,'now_money',$orderInfo['pay_price'],'uid');
- $res2 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'余额支付'.floatval($orderInfo['pay_price']).'元购买商品');
- $res3 = self::paySuccess($order_id,$formId);
- try{
-// HookService::listen('yue_pay_product',$userInfo,$orderInfo,false,PaymentBehavior::class);
- }catch (\Exception $e){
- self::rollbackTrans();
- return self::setErrorInfo($e->getMessage());
- }
- $res = $res1 && $res2 && $res3;
- self::checkTrans($res);
- return $res;
- }
-
- /**
- * 微信支付 为 0元时
- * @param $order_id
- * @param $uid
- * @return bool
- */
- public static function jsPayPrice($order_id,$uid,$formId = ''){
- $orderInfo = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->find();
- if(!$orderInfo) return self::setErrorInfo('订单不存在!');
- if($orderInfo['paid']) return self::setErrorInfo('该订单已支付!');
- $userInfo = User::getUserInfo($uid);
- self::beginTrans();
- $res1 = UserBill::expend('购买商品',$uid,'now_money','pay_product',$orderInfo['pay_price'],$orderInfo['id'],$userInfo['now_money'],'微信支付'.floatval($orderInfo['pay_price']).'元购买商品');
- $res2 = self::paySuccess($order_id,$formId);
- $res = $res1 && $res2;
- self::checkTrans($res);
- return $res;
- }
-
-
-
- /**
- * 用户申请退款
- * @param $uni
- * @param $uid
- * @param string $refundReasonWap
- * @return bool
- */
- public static function orderApplyRefund($uni, $uid,$refundReasonWap = '',$refundReasonWapExplain = '',$refundReasonWapImg = array())
- {
- $order = self::getUserOrderDetail($uid,$uni);
- if(!$order) return self::setErrorInfo('支付订单不存在!');
- if($order['refund_status'] == 2) return self::setErrorInfo('订单已退款!');
- if($order['refund_status'] == 1) return self::setErrorInfo('正在申请退款中!');
- if($order['status'] == 1) return self::setErrorInfo('订单当前无法退款!');
- self::beginTrans();
- $res1 = false !== StoreOrderStatus::status($order['id'],'apply_refund','用户申请退款,原因:'.$refundReasonWap);
- $res2 = false !== self::edit(['refund_status'=>1,'refund_reason_time'=>time(),'refund_reason_wap'=>$refundReasonWap,'refund_reason_wap_explain'=>$refundReasonWapExplain,'refund_reason_wap_img'=>json_encode($refundReasonWapImg)],$order['id'],'id');
- $res = $res1 && $res2;
- self::checkTrans($res);
- if(!$res)
- return self::setErrorInfo('申请退款失败!');
- else{
- $adminIds = SystemConfigService::get('site_store_admin_uids');
- if(!empty($adminIds)){
- try{
- if(!($adminList = array_unique(array_filter(explode(',',trim($adminIds)))))){
- self::setErrorInfo('申请退款成功,');
- return false;
- }
- RoutineTemplate::sendOrderRefundStatus($order,$refundReasonWap,$adminList);//小程序 发送模板消息
- }catch (\Exception $e){}
- }
- return true;
- }
- }
-
- /**
- * //TODO 支付成功后
- * @param $orderId
- * @param $notify
- * @return bool
- */
- public static function paySuccess($orderId,$formId = '')
- {
- $order = self::where('order_id',$orderId)->find();
- $resPink = true;
- $res1 = self::where('order_id',$orderId)->update(['paid'=>1,'pay_time'=>time()]);
- User::bcInc($order['uid'],'pay_count',1,'uid');
- if($order->combination_id && $res1 && !$order->refund_status) $resPink = StorePink::createPink($order);//创建拼团
- $oid = self::where('order_id',$orderId)->value('id');
- StoreOrderStatus::status($oid,'pay_success','用户付款成功');
- RoutineTemplate::sendOrderSuccess($formId,$orderId);
- $res = $res1 && $resPink;
- return false !== $res;
- }
-
- public static function createOrderTemplate($order)
- {
- $goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
- WechatTemplateService::sendTemplate(WechatUser::getOpenId($order['uid']),WechatTemplateService::ORDER_CREATE, [
- 'first'=>'亲,您购买的商品已支付成功',
- 'keyword1'=>date('Y/m/d H:i',$order['add_time']),
- 'keyword2'=>implode(',',$goodsName),
- 'keyword3'=>$order['order_id'],
- 'remark'=>'点击查看订单详情'
- ],Url::build('/wap/My/order',['uni'=>$order['order_id']],true,true));
- WechatTemplateService::sendAdminNoticeTemplate([
- 'first'=>"亲,您有一个新订单 \n订单号:{$order['order_id']}",
- 'keyword1'=>'新订单',
- 'keyword2'=>'线下支付',
- 'keyword3'=>date('Y/m/d H:i',time()),
- 'remark'=>'请及时处理'
- ]);
- }
-
- public static function getUserOrderDetail($uid,$key)
- {
- return self::where('order_id|unique',$key)->where('uid',$uid)->where('is_del',0)->find();
- }
-
-
- /**
- * TODO 订单发货
- * @param array $postageData 发货信息
- * @param string $oid orderID
- */
- public static function orderPostageAfter($postageData, $oid)
- {
- $order = self::where('id',$oid)->find();
- $openid = WechatUser::getOpenId($order['uid']);
- $url = Url::build('wap/My/order',['uni'=>$order['order_id']],true,true);
- $group = [
- 'first'=>'亲,您的订单已发货,请注意查收',
- 'remark'=>'点击查看订单详情'
- ];
- if($postageData['delivery_type'] == 'send'){//送货
- $goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
- $group = array_merge($group,[
- 'keyword1'=>$goodsName,
- 'keyword2'=>$order['pay_type'] == 'offline' ? '线下支付' : date('Y/m/d H:i',$order['pay_time']),
- 'keyword3'=>$order['user_address'],
- 'keyword4'=>$postageData['delivery_name'],
- 'keyword5'=>$postageData['delivery_id']
- ]);
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_DELIVER_SUCCESS,$group,$url);
-
- }else if($postageData['delivery_type'] == 'express'){//发货
- $group = array_merge($group,[
- 'keyword1'=>$order['order_id'],
- 'keyword2'=>$postageData['delivery_name'],
- 'keyword3'=>$postageData['delivery_id']
- ]);
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_POSTAGE_SUCCESS,$group,$url);
- }
- }
-
- public static function orderTakeAfter($order)
- {
- $openid = WechatUser::getOpenId($order['uid']);
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_TAKE_SUCCESS,[
- 'first'=>'亲,您的订单以成功签收,快去评价一下吧',
- 'keyword1'=>$order['order_id'],
- 'keyword2'=>'已收货',
- 'keyword3'=>date('Y/m/d H:i',time()),
- 'keyword4'=>implode(',',StoreOrderCartInfo::getProductNameList($order['id'])),
- 'remark'=>'点击查看订单详情'
- ],Url::build('My/order',['uni'=>$order['order_id']],true,true));
- }
-
- /**
- * 删除订单
- * @param $uni
- * @param $uid
- * @return bool
- */
- public static function removeOrder($uni, $uid)
- {
- $order = self::getUserOrderDetail($uid,$uni);
- if(!$order) return self::setErrorInfo('订单不存在!');
- $order = self::tidyOrder($order);
- if($order['_status']['_type'] != 0 && $order['_status']['_type']!= -2 && $order['_status']['_type'] != 4)
- return self::setErrorInfo('该订单无法删除!');
- if(false !== self::edit(['is_del'=>1],$order['id'],'id') &&
- false !==StoreOrderStatus::status($order['id'],'remove_order','删除订单'))
- return true;
- else
- return self::setErrorInfo('订单删除失败!');
- }
-
-
- /**
- * //TODO 用户确认收货
- * @param $uni
- * @param $uid
- */
- public static function takeOrder($uni, $uid)
- {
- $order = self::getUserOrderDetail($uid,$uni);
- if(!$order) return self::setErrorInfo('订单不存在!');
- $order = self::tidyOrder($order);
- if($order['_status']['_type'] != 2) return self::setErrorInfo('订单状态错误!');
- self::beginTrans();
- if(false !== self::edit(['status'=>2],$order['id'],'id') &&
- false !== StoreOrderStatus::status($order['id'],'user_take_delivery','用户已收货')){
- try{
- HookService::listen('store_product_order_user_take_delivery',$order,$uid,false,StoreProductBehavior::class);
- }catch (\Exception $e){
- return self::setErrorInfo($e->getMessage());
- }
- self::commitTrans();
- return true;
- }else{
- self::rollbackTrans();
- return false;
- }
- }
-
- public static function tidyOrder($order,$detail = false)
- {
- if($detail == true && isset($order['id'])){
- $cartInfo = self::getDb('StoreOrderCartInfo')->where('oid',$order['id'])->column('cart_info','unique')?:[];
- foreach ($cartInfo as $k=>$cart){
- $cartInfo[$k] = json_decode($cart, true);
- $cartInfo[$k]['unique'] = $k;
- }
- $order['cartInfo'] = $cartInfo;
- }
-
- $status = [];
- if(!$order['paid'] && $order['pay_type'] == 'offline' && !$order['status'] >= 2){
- $status['_type'] = 9;
- $status['_title'] = '线下付款';
- $status['_msg'] = '等待商家处理,请耐心等待';
- $status['_class'] = 'nobuy';
- }else if(!$order['paid']){
- $status['_type'] = 0;
- $status['_title'] = '未支付';
- $status['_msg'] = '立即支付订单吧';
- $status['_class'] = 'nobuy';
- }else if($order['refund_status'] == 1){
- $status['_type'] = -1;
- $status['_title'] = '申请退款中';
- $status['_msg'] = '商家审核中,请耐心等待';
- $status['_class'] = 'state-sqtk';
- }else if($order['refund_status'] == 2){
- $status['_type'] = -2;
- $status['_title'] = '已退款';
- $status['_msg'] = '已为您退款,感谢您的支持';
- $status['_class'] = 'state-sqtk';
- }else if(!$order['status']){
- if($order['pink_id']){
- if(StorePink::where('id',$order['pink_id'])->where('status',1)->count()){
- $status['_type'] = 1;
- $status['_title'] = '拼团中';
- $status['_msg'] = '等待其他人参加拼团';
- $status['_class'] = 'state-nfh';
- }else{
- $status['_type'] = 1;
- $status['_title'] = '未发货';
- $status['_msg'] = '商家未发货,请耐心等待';
- $status['_class'] = 'state-nfh';
- }
- }else{
- $status['_type'] = 1;
- $status['_title'] = '未发货';
- $status['_msg'] = '商家未发货,请耐心等待';
- $status['_class'] = 'state-nfh';
- }
- }else if($order['status'] == 1){
- $status['_type'] = 2;
- $status['_title'] = '待收货';
- $status['_msg'] = date('m月d日H时i分',StoreOrderStatus::getTime($order['id'],'delivery_goods')).'服务商已发货';
- $status['_class'] = 'state-ysh';
- }else if($order['status'] == 2){
- $status['_type'] = 3;
- $status['_title'] = '待评价';
- $status['_msg'] = '已收货,快去评价一下吧';
- $status['_class'] = 'state-ypj';
- }else if($order['status'] == 3){
- $status['_type'] = 4;
- $status['_title'] = '交易完成';
- $status['_msg'] = '交易完成,感谢您的支持';
- $status['_class'] = 'state-ytk';
- }
- if(isset($order['pay_type']))
- $status['_payType'] = isset(self::$payType[$order['pay_type']]) ? self::$payType[$order['pay_type']] : '其他方式';
- if(isset($order['delivery_type']))
- $status['_deliveryType'] = isset(self::$deliveryType[$order['delivery_type']]) ? self::$deliveryType[$order['delivery_type']] : '其他方式';
- $order['_status'] = $status;
- return $order;
- }
-
- public static function statusByWhere($status,$model = null)
- {
- $orderId = StorePink::where('uid',User::getActiveUid())->where('status',1)->column('order_id','id');//获取正在拼团的订单编号
- if($model == null) $model = new self;
- if('' === $status)
- return $model;
- else if($status == 0)
- return $model->where('paid',0)->where('status',0)->where('refund_status',0);
- else if($status == 1)//待发货
- return $model->where('paid',1)->where('order_id','NOT IN',implode(',',$orderId))->where('status',0)->where('refund_status',0);
- else if($status == 2)
- return $model->where('paid',1)->where('status',1)->where('refund_status',0);
- else if($status == 3)
- return $model->where('paid',1)->where('status',2)->where('refund_status',0);
- else if($status == 4)
- return $model->where('paid',1)->where('status',3)->where('refund_status',0);
- else if($status == -1)
- return $model->where('paid',1)->where('refund_status',1);
- else if($status == -2)
- return $model->where('paid',1)->where('refund_status',2);
- else if($status == -3)
- return $model->where('paid',1)->where('refund_status','IN','1,2');
- else if($status == 11){
- return $model->where('order_id','IN',implode(',',$orderId));
- }
- else
- return $model;
- }
-
- public static function getUserOrderList($uid,$status = '',$first = 0,$limit = 8)
- {
- $list = self::statusByWhere($status)->where('is_del',0)->where('uid',$uid)
- ->field('seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,pink_id,delivery_type')
- ->order('add_time DESC')->limit($first,$limit)->select()->toArray();
- foreach ($list as $k=>$order){
- $list[$k] = self::tidyOrder($order,true);
- }
-
- return $list;
- }
-
- /**
- * 获取推广人地下用户的订单金额
- * @param string $uid
- * @param string $status
- * @return array
- */
- public static function getUserOrderCount($uid = '',$status = ''){
- $res = self::statusByWhere($status)->where('uid','IN',$uid)->column('pay_price');
- return $res;
- }
-
- public static function searchUserOrder($uid,$order_id)
- {
- $order = self::where('uid',$uid)->where('order_id',$order_id)->where('is_del',0)->field('seckill_id,bargain_id,combination_id,id,order_id,pay_price,total_num,total_price,pay_postage,total_postage,paid,status,refund_status,pay_type,coupon_price,deduction_price,delivery_type')
- ->order('add_time DESC')->find();
- if(!$order)
- return false;
- else
- return self::tidyOrder($order->toArray(),true);
-
- }
-
- public static function orderOver($oid)
- {
- $res = self::edit(['status'=>'3'],$oid,'id');
- if(!$res) exception('评价后置操作失败!');
- StoreOrderStatus::status($oid,'check_order_over','用户评价');
- }
-
- public static function checkOrderOver($oid)
- {
- $uniqueList = StoreOrderCartInfo::where('oid',$oid)->column('unique');
- if(StoreProductReply::where('unique','IN',$uniqueList)->where('oid',$oid)->count() == count($uniqueList)){
- HookService::listen('store_product_order_over',$oid,null,false,StoreProductBehavior::class);
- self::orderOver($oid);
- }
- }
-
-
- public static function getOrderStatusNum($uid)
- {
- $noBuy = self::where('uid',$uid)->where('paid',0)->where('is_del',0)->where('pay_type','<>','offline')->count();
- $noPostageNoPink = self::where('o.uid',$uid)->alias('o')->where('o.paid',1)->where('o.pink_id',0)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
- $noPostageYesPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',2)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
- $noPostage = bcadd($noPostageNoPink,$noPostageYesPink);
- $noTake = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',1)->where('pay_type','<>','offline')->count();
- $noReply = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('status',2)->count();
- $noPink = self::where('o.uid',$uid)->alias('o')->join('StorePink p','o.pink_id = p.id')->where('p.status',1)->where('o.paid',1)->where('o.is_del',0)->where('o.status',0)->where('o.pay_type','<>','offline')->count();
- $noRefund = self::where('uid',$uid)->where('paid',1)->where('is_del',0)->where('refund_status','IN','1,2')->count();
- return compact('noBuy','noPostage','noTake','noReply','noPink','noRefund');
- }
-
- public static function gainUserIntegral($order)
- {
- if($order['gain_integral'] > 0){
- $userInfo = User::getUserInfo($order['uid']);
- ModelBasic::beginTrans();
- $res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
- $res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],$userInfo['integral'],'购买商品赠送'.floatval($order['gain_integral']).'积分');
- $res = $res1 && $res2;
- ModelBasic::checkTrans($res);
- return $res;
- }
- return true;
- }
-
- /**
- * 获取当前订单中有没有拼团存在
- * @param $pid
- * @return int|string
- */
- public static function getIsOrderPink($pid = 0 ,$uid = 0){
- return self::where('uid',$uid)->where('pink_id',$pid)->where('refund_status',0)->where('is_del',0)->count();
- }
-
- /**
- * 获取order_id
- * @param $pid
- * @return mixed
- */
- public static function getStoreIdPink($pid = 0 ,$uid = 0){
- return self::where('uid',$uid)->where('pink_id',$pid)->where('is_del',0)->value('order_id');
- }
-
- /**
- * 删除当前用户拼团未支付的订单
- */
- public static function delCombination(){
- self::where('combination','GT',0)->where('paid',0)->where('uid',User::getActiveUid())->delete();
- }
-
- public static function getUserPrice($uid =0){
- if(!$uid) return 0;
- $price = self::where('paid',1)->where('uid',$uid)->where('status',2)->where('refund_status',0)->column('pay_price','id');
- $count = 0;
- if($price){
- foreach ($price as $v){
- $count = bcadd($count,$v,2);
- }
- }
- return $count;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreOrderCartInfo.php b/application/routine/model/store/StoreOrderCartInfo.php
deleted file mode 100644
index 48e51427..00000000
--- a/application/routine/model/store/StoreOrderCartInfo.php
+++ /dev/null
@@ -1,49 +0,0 @@
-
- * @day: 2017/12/26
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreOrderCartInfo extends ModelBasic
-{
- use ModelTrait;
-
- public static function getCartInfoAttr($value)
- {
- return json_decode($value,true)?:[];
- }
-
- public static function setCartInfo($oid,array $cartInfo)
- {
- $group = [];
- foreach ($cartInfo as $cart){
- $group[] = [
- 'oid'=>$oid,
- 'cart_id'=>$cart['id'],
- 'product_id'=>$cart['productInfo']['id'],
- 'cart_info'=>json_encode($cart),
- 'unique'=>md5($cart['id'].''.$oid)
- ];
- }
- return self::setAll($group);
- }
-
- public static function getProductNameList($oid)
- {
- $cartInfo = self::where('oid',$oid)->select();
- $goodsName = [];
- foreach ($cartInfo as $cart){
- $suk = isset($cart['cart_info']['productInfo']['attrInfo']) ? '('.$cart['cart_info']['productInfo']['attrInfo']['suk'].')' : '';
- $goodsName[] = $cart['cart_info']['productInfo']['store_name'].$suk;
- }
- return $goodsName;
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreOrderStatus.php b/application/routine/model/store/StoreOrderStatus.php
deleted file mode 100644
index 614e01cf..00000000
--- a/application/routine/model/store/StoreOrderStatus.php
+++ /dev/null
@@ -1,29 +0,0 @@
-
- * @day: 2017/12/28
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreOrderStatus extends ModelBasic
-{
- use ModelTrait;
-
- public static function status($oid,$change_type,$change_message,$change_time = null)
- {
- if($change_time == null) $change_time = time();
- return self::set(compact('oid','change_type','change_message','change_time'));
- }
-
- public static function getTime($oid,$change_type)
- {
- return self::where('oid',$oid)->where('change_type',$change_type)->value('change_time');
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StorePink.php b/application/routine/model/store/StorePink.php
deleted file mode 100644
index e27e6d1a..00000000
--- a/application/routine/model/store/StorePink.php
+++ /dev/null
@@ -1,373 +0,0 @@
-
- * @day: 2017/12/18
- */
-
-namespace app\routine\model\store;
-
-use app\routine\model\store\StoreCombination;
-use app\routine\model\user\User;
-use app\routine\model\user\UserBill;
-use app\routine\model\user\WechatUser;
-use basic\ModelBasic;
-use service\SystemConfigService;
-use service\WechatTemplateService;
-use think\Url;
-use traits\ModelTrait;
-
-/**
- * 拼团Model
- * Class StorePink
- * @package app\wap\model\store
- */
-class StorePink extends ModelBasic
-{
- use ModelTrait;
-
-
- /**
- * 获取一条拼团数据
- * @param $id
- * @return mixed
- */
- public static function getPinkUserOne($id){
- $model = new self();
- $model = $model->alias('p');
- $model = $model->field('p.*,u.nickname,u.avatar');
- $model = $model->where('id',$id);
- $model = $model->join('__USER__ u','u.uid = p.uid');
- $list = $model->find();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取拼团的团员
- * @param $id
- * @return mixed
- */
- public static function getPinkMember($id){
- $model = new self();
- $model = $model->alias('p');
- $model = $model->field('p.*,u.nickname,u.avatar');
- $model = $model->where('k_id',$id);
- $model = $model->where('is_refund',0);
- $model = $model->join('__USER__ u','u.uid = p.uid');
- $model = $model->order('id asc');
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 设置结束时间
- * @param $idAll
- * @return $this
- */
- public static function setPinkStopTime($idAll){
- $model = new self();
- $model = $model->where('id','IN',$idAll);
- return $model->update(['stop_time'=>time(),'status'=>2]);
- }
-
- /**
- * 获取正在拼团的数据 团长
- * @return mixed
- */
- public static function getPinkAll($cid){
- $model = new self();
- $model = $model->alias('p');
- $model = $model->field('p.*,u.nickname,u.avatar');
- $model = $model->where('stop_time','GT',time());
- $model = $model->where('cid',$cid);
- $model = $model->where('k_id',0);
- $model = $model->where('is_refund',0);
- $model = $model->order('add_time desc');
- $model = $model->join('__USER__ u','u.uid = p.uid');
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取还差几人
- */
- public static function getPinkPeople($kid,$people){
- $model = new self();
- $model = $model->where('k_id',$kid)->where('is_refund',0);
- $count = bcadd($model->count(),1,0);
- return bcsub($people,$count,0);
- }
-
- /**
- * 判断订单是否在当前的拼团中
- * @param $orderId
- * @param $kid
- * @return bool
- */
- public static function getOrderIdAndPink($orderId,$kid){
- $model = new self();
- $pink = $model->where('k_id',$kid)->whereOr('id',$kid)->column('order_id');
- if(in_array($orderId,$pink))return true;
- else return false;
- }
-
- /**
- * 判断用户是否在团内
- * @param $id
- * @return int|string
- */
- public static function getIsPinkUid($id = 0,$uid = 0){
- $pinkT = self::where('id',$id)->where('uid',$uid)->where('is_refund',0)->count();
- $pink = self::whereOr('k_id',$id)->where('uid',$uid)->where('is_refund',0)->count();
- if($pinkT) return true;
- if($pink) return true;
- else return false;
- }
-
-
- /**
- * 判断是否发送模板消息 0 未发送 1已发送
- * @param $uidAll
- * @return int|string
- */
- public static function isTpl($uidAll,$pid){
- if(is_array($uidAll)){
- $countK = self::where('uid','IN',implode(',',$uidAll))->where('is_tpl',0)->where('id',$pid)->count();
- $count = self::where('uid','IN',implode(',',$uidAll))->where('is_tpl',0)->where('k_id',$pid)->count();
- }
- else {
- $countK = self::where('uid',$uidAll)->where('is_tpl',0)->where('id',$pid)->count();
- $count = self::where('uid',$uidAll)->where('is_tpl',0)->where('k_id',$pid)->count();
- }
- return bcadd($countK,$count,0);
- }
- /**
- * 拼团成功提示模板消息
- * @param $uidAll
- * @param $pid
- */
- public static function orderPinkAfter($uidAll,$pid){
-// foreach ($uidAll as $v){
-// $openid = WechatUser::uidToOpenid($v);
-// WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_USER_GROUPS_SUCCESS,[
-// 'first'=>'亲,您的拼团已经完成了',
-// 'keyword1'=> self::where('id',$pid)->whereOr('k_id',$pid)->where('uid',$v)->value('order_id'),
-// 'keyword2'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$v)->join('__STORE_COMBINATION__ c','c.id=p.cid')->value('c.title'),
-// 'remark'=>'点击查看订单详情'
-// ],Url::build('My/order_pink_after',['id'=>$pid],true,true));
-// }
- self::beginTrans();
- $res1 = self::where('uid','IN',implode(',',$uidAll))->where('id',$pid)->whereOr('k_id',$pid)->update(['is_tpl'=>1]);
- $res2 = true;
-// if(SystemConfigService::get('colonel_status')) $res2 = self::setRakeBackColonel($pid);
-// else $res2 = true;
- $res = $res1 && $res2;
- self::checkTrans($res);
- }
-
- /**
- * 拼团失败发送的模板消息
- * @param $uid
- * @param $pid
- */
- public static function orderPinkAfterNo($uid,$pid){
- $openid = WechatUser::uidToOpenid($uid);
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_USER_GROUPS_LOSE,[
- 'first'=>'亲,您的拼团失败',
- 'keyword1'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$uid)->join('__STORE_COMBINATION__ c','c.id=p.cid')->value('c.title'),
- 'keyword2'=> self::where('id',$pid)->whereOr('k_id',$pid)->where('uid',$uid)->value('price'),
- 'keyword3'=> self::alias('p')->where('p.id',$pid)->whereOr('p.k_id',$pid)->where('p.uid',$uid)->join('__STORE_ORDER__ c','c.order_id=p.order_id')->value('c.pay_price'),
- 'remark'=>'点击查看订单详情'
- ],Url::build('My/order_pink_after',['id'=>$pid],true,true));
- self::where('id',$pid)->update(['status'=>3]);
- self::where('k_id',$pid)->update(['status'=>3]);
- }
-
- /**
- * 获取当前拼团数据返回订单编号
- * @param $id
- * @return array|false|\PDOStatement|string|\think\Model
- */
- public static function getCurrentPink($id){
- $uid = User::getActiveUid();//获取当前登录人的uid
- $pink = self::where('id',$id)->where('uid',$uid)->find();
- if(!$pink) $pink = self::where('k_id',$id)->where('uid',$uid)->find();
- return StoreOrder::where('id',$pink['order_id_key'])->value('order_id');
- }
-
- public static function systemPage($where){
- $model = new self;
- $model = $model->alias('p');
- $model = $model->field('p.*,c.title');
- if($where['data'] !== ''){
- list($startTime,$endTime) = explode(' - ',$where['data']);
- $model = $model->where('p.add_time','>',strtotime($startTime));
- $model = $model->where('p.add_time','<',strtotime($endTime));
- }
- if($where['status']) $model = $model->where('p.status',$where['status']);
- $model = $model->where('p.k_id',0);
- $model = $model->order('p.id desc');
- $model = $model->join('StoreCombination c','c.id=p.cid');
- return self::page($model,function($item)use($where){
- $item['count_people'] = bcadd(self::where('k_id',$item['id'])->count(),1,0);
- },$where);
- }
-
- public static function isPinkBe($data,$id){
- $data['id'] = $id;
- $count = self::where($data)->count();
- if($count) return $count;
- $data['k_id'] = $id;
- $count = self::where($data)->count();
- if($count) return $count;
- else return 0;
- }
- public static function isPinkStatus($pinkId){
- if(!$pinkId) return false;
- $stopTime = self::where('id',$pinkId)->value('stop_time');
- if($stopTime < time()) return true; //拼团结束
- else return false;//拼团未结束
- }
-
- /**
- * 判断拼团结束 后的状态
- * @param $pinkId
- * @return bool
- */
- public static function isSetPinkOver($pinkId){
- $people = self::where('id',$pinkId)->value('people');
- $stopTime = self::where('id',$pinkId)->value('stop_time');
- if($stopTime < time()){
- $countNum = self::getPinkPeople($pinkId,$people);
- if($countNum) return false;//拼团失败
- else return true;//拼团成功
- }else return true;
- }
-
- /**
- * 拼团退款
- * @param $id
- * @return bool
- */
- public static function setRefundPink($oid){
- $res = true;
- $order = StoreOrder::where('id',$oid)->find();
- if($order['pink_id']) $id = $order['pink_id'];
- else return $res;
- $count = self::where('id',$id)->where('uid',$order['uid'])->find();//正在拼团 团长
- $countY = self::where('k_id',$id)->where('uid',$order['uid'])->find();//正在拼团 团员
- if(!$count && !$countY) return $res;
- if($count){//团长
- //判断团内是否还有其他人 如果有 团长为第二个进团的人
- $kCount = self::where('k_id',$id)->order('add_time asc')->find();
- if($kCount){
- $res11 = self::where('k_id',$id)->update(['k_id'=>$kCount['id']]);
- $res12 = self::where('id',$kCount['id'])->update(['stop_time'=>$count['add_time']+86400,'k_id'=>0]);
- $res1 = $res11 && $res12;
- $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$kCount['id'],'status'=>3]);
- }else{
- $res1 = true;
- $res2 = self::where('id',$id)->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
- }
- //修改结束时间为前一秒 团长ID为0
- $res = $res1 && $res2;
- }else if($countY){//团员
- $res = self::where('id',$countY['id'])->update(['stop_time'=>time()-1,'k_id'=>0,'is_refund'=>$id,'status'=>3]);
- }
- return $res;
-
- }
-
-
-
- /**
- * 拼团人数完成时,判断全部人都是未退款状态
- * @param $pinkIds
- * @return bool
- */
- public static function setPinkStatus($pinkIds){
- $orderPink = self::where('id','IN',$pinkIds)->where('is_refund',1)->count();
- if(!$orderPink) return true;
- else return false;
- }
-
-
- /**
- * 创建拼团
- * @param $order
- * @return mixed
- */
- public static function createPink($order){
- $order = StoreOrder::tidyOrder($order,true)->toArray();
- if($order['pink_id']){//拼团存在
- $res = false;
- $pink['uid'] = $order['uid'];//用户id
- if(self::isPinkBe($pink,$order['pink_id'])) return false;
- $pink['order_id'] = $order['order_id'];//订单id 生成
- $pink['order_id_key'] = $order['id'];//订单id 数据库id
- $pink['total_num'] = $order['total_num'];//购买个数
- $pink['total_price'] = $order['pay_price'];//总金额
- $pink['k_id'] = $order['pink_id'];//拼团id
- foreach ($order['cartInfo'] as $v){
- $pink['cid'] = $v['combination_id'];//拼团产品id
- $pink['pid'] = $v['product_id'];//产品id
- $pink['people'] = StoreCombination::where('id',$v['combination_id'])->value('people');//几人拼团
- $pink['price'] = $v['productInfo']['price'];//单价
- $pink['stop_time'] = 0;//结束时间
- $pink['add_time'] = time();//开团时间
- $res = StorePink::set($pink)->toArray();
- }
- if($res) return true;
- else return false;
- }else{
- $res = false;
- $pink['uid'] = $order['uid'];//用户id
- $pink['order_id'] = $order['order_id'];//订单id 生成
- $pink['order_id_key'] = $order['id'];//订单id 数据库id
- $pink['total_num'] = $order['total_num'];//购买个数
- $pink['total_price'] = $order['pay_price'];//总金额
- $pink['k_id'] = 0;//拼团id
- foreach ($order['cartInfo'] as $v){
- $pink['cid'] = $v['combination_id'];//拼团产品id
- $pink['pid'] = $v['product_id'];//产品id
- $pink['people'] = StoreCombination::where('id',$v['combination_id'])->value('people');//几人拼团
- $pink['price'] = $v['productInfo']['price'];//单价
-// $stopTime = StoreCombination::where('id',$v['combination_id'])->value('stop_time');//获取拼团产品结束的时间
-// if($stopTime < time()+86400) $pink['stop_time'] = $stopTime;//结束时间
- $pink['stop_time'] = time()+86400;//结束时间
- $pink['add_time'] = time();//开团时间
- $res1 = self::set($pink)->toArray();
- $res2 = StoreOrder::where('id',$order['id'])->update(['pink_id'=>$res1['id']]);
- $res = $res1 && $res2;
- }
- if($res) return true;
- else return false;
- }
- }
-
- /**
- * 拼团成功后给团长返佣金
- * @param int $id
- * @return bool
- */
-// public static function setRakeBackColonel($id = 0){
-// if(!$id) return false;
-// $pinkRakeBack = self::where('id',$id)->field('people,price,uid,id')->find()->toArray();
-// $countPrice = bcmul($pinkRakeBack['people'],$pinkRakeBack['price'],2);
-// if(bcsub((float)$countPrice,0,2) <= 0) return true;
-// $rakeBack = (SystemConfigService::get('rake_back_colonel') ?: 0)/100;
-// if($rakeBack <= 0) return true;
-// $rakeBackPrice = bcmul($countPrice,$rakeBack,2);
-// if($rakeBackPrice <= 0) return true;
-// $mark = '拼团成功,奖励佣金'.floatval($rakeBackPrice);
-// self::beginTrans();
-// $res1 = UserBill::income('获得拼团佣金',$pinkRakeBack['uid'],'now_money','colonel',$rakeBackPrice,$id,0,$mark);
-// $res2 = User::bcInc($pinkRakeBack['uid'],'now_money',$rakeBackPrice,'uid');
-// $res = $res1 && $res2;
-// self::checkTrans($res);
-// return $res;
-// }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreProduct.php b/application/routine/model/store/StoreProduct.php
deleted file mode 100644
index eb9512f1..00000000
--- a/application/routine/model/store/StoreProduct.php
+++ /dev/null
@@ -1,148 +0,0 @@
-
- * @day: 2017/12/12
- */
-
-namespace app\routine\model\store;
-
-
-use app\admin\model\store\StoreProductAttrValue as StoreProductAttrValuemodel;
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreProduct extends ModelBasic
-{
- use ModelTrait;
-
- protected function getSliderImageAttr($value)
- {
- return json_decode($value,true)?:[];
- }
-
- public static function getValidProduct($productId,$field = '*')
- {
- return self::where('is_del',0)->where('is_show',1)->where('id',$productId)->field($field)->find();
- }
-
- public static function validWhere()
- {
- return self::where('is_del',0)->where('is_show',1)->where('mer_id',0);
- }
-
- /**
- * 新品产品
- * @param string $field
- * @param int $limit
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function getNewProduct($field = '*',$limit = 0)
- {
- $model = self::where('is_new',1)->where('is_del',0)->where('mer_id',0)
- ->where('stock','>',0)->where('is_show',1)->field($field)
- ->order('sort DESC, id DESC');
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
- /**
- * 热卖产品
- * @param string $field
- * @param int $limit
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function getHotProduct($field = '*',$limit = 0)
- {
- $model = self::where('is_hot',1)->where('is_del',0)->where('mer_id',0)
- ->where('stock','>',0)->where('is_show',1)->field($field)
- ->order('sort DESC, id DESC');
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
- /**
- * 热卖产品
- * @param string $field
- * @param int $limit
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function getHotProductLoading($field = '*',$offset = 0,$limit = 0)
- {
- $model = self::where('is_hot',1)->where('is_del',0)->where('mer_id',0)
- ->where('stock','>',0)->where('is_show',1)->field($field)
- ->order('sort DESC, id DESC');
- if($limit) $model->limit($offset,$limit);
- return $model->select();
- }
-
- /**
- * 精品产品
- * @param string $field
- * @param int $limit
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function getBestProduct($field = '*',$limit = 0)
- {
- $model = self::where('is_best',1)->where('is_del',0)->where('mer_id',0)
- ->where('stock','>',0)->where('is_show',1)->field($field)
- ->order('sort DESC, id DESC');
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
-
- /**
- * 优惠产品
- * @param string $field
- * @param int $limit
- * @return false|\PDOStatement|string|\think\Collection
- */
- public static function getBenefitProduct($field = '*',$limit = 0)
- {
- $model = self::where('is_benefit',1)
- ->where('is_del',0)->where('mer_id',0)->where('stock','>',0)
- ->where('is_show',1)->field($field)
- ->order('sort DESC, id DESC');
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
- public static function cateIdBySimilarityProduct($cateId,$field='*',$limit = 0)
- {
- $pid = StoreCategory::cateIdByPid($cateId)?:$cateId;
- $cateList = StoreCategory::pidByCategory($pid,'id') ?:[];
- $cid = [$pid];
- foreach ($cateList as $cate){
- $cid[] = $cate['id'];
- }
- $model = self::where('cate_id','IN',$cid)->where('is_show',1)->where('is_del',0)
- ->field($field)->order('sort DESC,id DESC');
- if($limit) $model->limit($limit);
- return $model->select();
- }
-
- public static function isValidProduct($productId)
- {
- return self::be(['id'=>$productId,'is_del'=>0,'is_show'=>1]) > 0;
- }
-
- public static function getProductStock($productId,$uniqueId = '')
- {
- return $uniqueId == '' ?
- self::where('id',$productId)->value('stock')?:0
- : StoreProductAttr::uniqueByStock($uniqueId);
- }
-
- public static function decProductStock($num,$productId,$unique = '')
- {
- if($unique){
- $res = false !== StoreProductAttrValuemodel::decProductAttrStock($productId,$unique,$num);
- $res = $res && self::where('id',$productId)->setInc('sales',$num);
- }else{
- $res = false !== self::where('id',$productId)->dec('stock',$num)->inc('sales',$num)->update();
- }
- return $res;
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreProductAttr.php b/application/routine/model/store/StoreProductAttr.php
deleted file mode 100644
index fdb5e73b..00000000
--- a/application/routine/model/store/StoreProductAttr.php
+++ /dev/null
@@ -1,67 +0,0 @@
-
- * @day: 2017/12/13
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use think\Db;
-use traits\ModelTrait;
-
-class StoreProductAttr extends ModelBasic
-{
-
- use ModelTrait;
-
- protected function getAttrValuesAttr($value)
- {
- return explode(',',$value);
- }
-
- public static function storeProductAttrValueDb()
- {
- return Db::name('StoreProductAttrValue');
- }
-
-
- /**
- * 获取商品属性数据
- * @param $productId
- * @return array
- */
- public static function getProductAttrDetail($productId)
- {
- $attr = self::where('product_id',$productId)->select()->toArray()?:[];
- $_values = self::storeProductAttrValueDb()->where('product_id',$productId)->select();
- $values = [];
- foreach ($_values as $value){
- $values[$value['suk']] = $value;
- }
- return [$attr,$values];
- }
-
- public static function uniqueByStock($unique)
- {
- return self::storeProductAttrValueDb()->where('unique',$unique)->value('stock')?:0;
- }
-
- public static function uniqueByAttrInfo($unique, $field = '*')
- {
- return self::storeProductAttrValueDb()->field($field)->where('unique',$unique)->find();
- }
-
- public static function issetProductUnique($productId,$unique)
- {
- $res = self::be(['product_id'=>$productId]);
- if($unique){
- return $res && self::storeProductAttrValueDb()->where('product_id',$productId)->where('unique',$unique)->count() > 0;
- }else{
- return !$res;
- }
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreProductRelation.php b/application/routine/model/store/StoreProductRelation.php
deleted file mode 100644
index 6dbc5af7..00000000
--- a/application/routine/model/store/StoreProductRelation.php
+++ /dev/null
@@ -1,118 +0,0 @@
-
- * @day: 2017/11/11
- */
-
-namespace app\routine\model\store;
-
-use behavior\wap\StoreProductBehavior;
-use service\HookService;
-use traits\ModelTrait;
-use basic\ModelBasic;
-
-/**
- * 点赞收藏model
- * Class StoreProductRelation
- * @package app\routine\model\store
- */
-class StoreProductRelation extends ModelBasic
-{
- use ModelTrait;
-
- /**
- * 获取用户点赞所有产品的个数
- * @param $uid
- * @return int|string
- */
- public static function getUserIdLike($uid = 0){
- $count = self::where('uid',$uid)->where('type','like')->count();
- return $count;
- }
-
- /**
- * 获取用户收藏所有产品的个数
- * @param $uid
- * @return int|string
- */
- public static function getUserIdCollect($uid = 0){
- $count = self::where('uid',$uid)->where('type','collect')->count();
- return $count;
- }
-
- /**
- * 添加点赞 收藏
- * @param $productId
- * @param $uid
- * @param $relationType
- * @param string $category
- * @return bool
- */
- public static function productRelation($productId,$uid,$relationType,$category = 'product')
- {
- if(!$productId) return self::setErrorInfo('产品不存在!');
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- $data = ['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category];
- if(self::be($data)) return true;
- $data['add_time'] = time();
- self::set($data);
- HookService::afterListen('store_'.$category.'_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
- return true;
- }
-
- /**
- * 批量 添加点赞 收藏
- * @param $productIdS
- * @param $uid
- * @param $relationType
- * @param string $category
- * @return bool
- */
- public static function productRelationAll($productIdS,$uid,$relationType,$category = 'product'){
- $res = true;
- if(is_array($productIdS)){
- self::beginTrans();
- foreach ($productIdS as $productId){
- $res = $res && self::productRelation($productId,$uid,$relationType,$category);
- }
- self::checkTrans($res);
- return $res;
- }
- return $res;
- }
-
- /**
- * 取消 点赞 收藏
- * @param $productId
- * @param $uid
- * @param $relationType
- * @param string $category
- * @return bool
- */
- public static function unProductRelation($productId,$uid,$relationType,$category = 'product')
- {
- if(!$productId) return self::setErrorInfo('产品不存在!');
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- self::where(['uid'=>$uid,'product_id'=>$productId,'type'=>$relationType,'category'=>$category])->delete();
- HookService::afterListen('store_'.$category.'_un_'.$relationType,$productId,$uid,false,StoreProductBehavior::class);
- return true;
- }
-
- public static function productRelationNum($productId,$relationType,$category = 'product')
- {
- $relationType = strtolower($relationType);
- $category = strtolower($category);
- return self::where('type',$relationType)->where('product_id',$productId)->where('category',$category)->count();
- }
-
- public static function isProductRelation($product_id,$uid,$relationType,$category = 'product')
- {
- $type = strtolower($relationType);
- $category = strtolower($category);
- return self::be(compact('product_id','uid','type','category'));
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreProductReply.php b/application/routine/model/store/StoreProductReply.php
deleted file mode 100644
index abd044fa..00000000
--- a/application/routine/model/store/StoreProductReply.php
+++ /dev/null
@@ -1,98 +0,0 @@
-
- * @day: 2017/12/29
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use service\UtilService;
-use traits\ModelTrait;
-
-class StoreProductReply extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- protected function setPicsAttr($value)
- {
- return is_array($value) ? json_encode($value) : $value;
- }
-
- protected function getPicsAttr($value)
- {
- return json_decode($value,true);
- }
-
- public static function reply($group,$type = 'product')
- {
- $group['reply_type'] = $type;
- return self::set($group);
- }
-
- public static function productValidWhere($alias = '')
- {
- $model = new self;
- if($alias){
- $model->alias($alias);
- $alias .= '.';
- }
- return $model->where("{$alias}is_del",0)->where("{$alias}reply_type",'product');
- }
-
- public static function getProductReplyList($productId,$order = 'All',$first = 0,$limit = 8)
- {
- $model = self::productValidWhere('A')->where('A.product_id',$productId)
- ->field('A.product_score,A.service_score,A.comment,A.merchant_reply_content,A.merchant_reply_time,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info,A.merchant_reply_content')
- ->join('__USER__ B','A.uid = B.uid')
- ->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique');
- $baseOrder = 'A.add_time DESC,A.product_score DESC, A.service_score DESC';
- if($order == 'new') $model->order($baseOrder);
- else if($order == 'pic') $model->where('A.pics',['<>',''],['<>','[]'])->order('A.add_time DESC,'.$baseOrder);
- else $model->order('A.add_time DESC,'.$baseOrder);
- $list = $model->limit($first,$limit)->select()->toArray()?:[];
- foreach ($list as $k=>$reply){
- $list[$k] = self::tidyProductReply($reply);
- }
- return $list;
- }
-
- public static function tidyProductReply($res)
- {
- $res['cart_info'] = json_decode($res['cart_info'],true)?:[];
- $res['suk'] = isset($res['cart_info']['productInfo']['attrInfo']) ? $res['cart_info']['productInfo']['attrInfo']['suk'] : '';
- $res['nickname'] = UtilService::anonymity($res['nickname']);
- $res['merchant_reply_time'] = date('Y-m-d H:i',$res['merchant_reply_time']);
- $res['add_time'] = date('Y-m-d H:i',$res['add_time']);
- $res['star'] = ceil(($res['product_score'] + $res['service_score'])/2);
- $res['comment'] = $res['comment']?:'此用户没有填写评价';
- unset($res['cart_info']);
- return $res;
- }
-
- public static function isReply($unique,$reply_type = 'product')
- {
- return self::be(['unique'=>$unique,'reply_type'=>$reply_type]);
- }
-
- public static function getRecProductReply($productId)
- {
- $res = self::productValidWhere('A')->where('A.product_id',$productId)
- ->field('A.product_score,A.service_score,A.comment,A.merchant_reply_content,A.merchant_reply_time,A.pics,A.add_time,B.nickname,B.avatar,C.cart_info')
- ->join('__USER__ B','A.uid = B.uid')
- ->join('__STORE_ORDER_CART_INFO__ C','A.unique = C.unique')
- ->order('A.add_time DESC,A.product_score DESC, A.service_score DESC, A.add_time DESC')->find();
- if(!$res) return null;
- return self::tidyProductReply($res->toArray());
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreSeckill.php b/application/routine/model/store/StoreSeckill.php
deleted file mode 100644
index 22ced0d2..00000000
--- a/application/routine/model/store/StoreSeckill.php
+++ /dev/null
@@ -1,109 +0,0 @@
-
- * @day: 2017/12/18
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-
-class StoreSeckill extends ModelBasic
-{
-
- protected function getImagesAttr($value)
- {
- return json_decode($value,true)?:[];
- }
-
-
- /**
- * 获取所有秒杀产品
- * @param string $field
- * @return array
- */
- public static function getListAll($offset = 0,$limit = 10,$field = 'id,product_id,image,title,price,ot_price,start_time,stop_time,stock,sales'){
- $time = time();
- $model = self::where('is_del',0)->where('status',1)->where('stock','>',0)->field($field)
- ->where('start_time','<',$time)->where('stop_time','>',$time)->order('sort DESC,add_time DESC');
- $model = $model->limit($offset,$limit);
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
- /**
- * 获取热门推荐的秒杀产品
- * @param int $limit
- * @param string $field
- * @return array
- */
- public static function getHotList($limit = 0,$field = 'id,product_id,image,title,price,ot_price,start_time,stop_time,stock')
- {
- $time = time();
- $model = self::where('is_hot',1)->where('is_del',0)->where('status',1)->where('stock','>',0)->field($field)
- ->where('start_time','<',$time)->where('stop_time','>',$time)->order('sort DESC,add_time DESC');
- if($limit) $model->limit($limit);
- $list = $model->select();
- if($list) return $list->toArray();
- else return [];
- }
-
- /**
- * 获取一条秒杀产品
- * @param $id
- * @param string $field
- * @return array|false|\PDOStatement|string|\think\Model
- */
- public static function getValidProduct($id,$field = '*')
- {
- $time = time();
- return self::where('id',$id)->where('is_del',0)->where('status',1)->where('start_time','<',$time)->where('stop_time','>',$time)
- ->field($field)->find();
- }
-
- public static function initFailSeckill()
- {
- self::where('is_hot',1)->where('is_del',0)->where('status','<>',1)->where('stop_time','<',time())->update(['status'=>'-1']);
- }
-
- public static function idBySimilaritySeckill($id,$limit = 4,$field='*')
- {
- $time = time();
- $list = [];
- $productId = self::where('id',$id)->value('product_id');
- if($productId){
- $list = array_merge($list, self::where('product_id',$productId)->where('id','<>',$id)
- ->where('is_del',0)->where('status',1)->where('stock','>',0)
- ->field($field)->where('start_time','<',$time)->where('stop_time','>',$time)
- ->order('sort DESC,add_time DESC')->limit($limit)->select()->toArray());
- }
- $limit = $limit - count($list);
- if($limit){
- $list = array_merge($list,self::getHotList($limit,$field));
- }
-
- return $list;
- }
-
- public static function getProductStock($id){
- $stock = self::where('id',$id)->value('stock');
- if(self::where('id',$id)->where('num','gt',$stock)->count()){//单次购买的产品多于库存
- return $stock;
- }else{
- return self::where('id',$id)->value('num');
- }
- }
-
- /**
- * 修改秒杀库存
- * @param int $num
- * @param int $seckillId
- * @return bool
- */
- public static function decSeckillStock($num = 0,$seckillId = 0){
- $res = false !== self::where('id',$seckillId)->dec('stock',$num)->inc('sales',$num)->update();
- return $res;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreService.php b/application/routine/model/store/StoreService.php
deleted file mode 100644
index bbcd53ad..00000000
--- a/application/routine/model/store/StoreService.php
+++ /dev/null
@@ -1,17 +0,0 @@
-
- * @day: 2017/12/23
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreService extends ModelBasic
-{
- use ModelTrait;
-}
\ No newline at end of file
diff --git a/application/routine/model/store/StoreServiceLog.php b/application/routine/model/store/StoreServiceLog.php
deleted file mode 100644
index f5748035..00000000
--- a/application/routine/model/store/StoreServiceLog.php
+++ /dev/null
@@ -1,17 +0,0 @@
-
- * @day: 2017/12/23
- */
-
-namespace app\routine\model\store;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class StoreServiceLog extends ModelBasic
-{
- use ModelTrait;
-}
\ No newline at end of file
diff --git a/application/routine/model/user/RoutineUser.php b/application/routine/model/user/RoutineUser.php
deleted file mode 100644
index 58e321e6..00000000
--- a/application/routine/model/user/RoutineUser.php
+++ /dev/null
@@ -1,84 +0,0 @@
-
- * @day: 2017/12/21
- */
-
-namespace app\routine\model\user;
-
-use app\routine\model\routine\RoutineQrcode;
-use basic\ModelBasic;
-use traits\ModelTrait;
-use app\routine\model\user\User;
-use app\routine\model\user\WechatUser;
-class RoutineUser extends ModelBasic
-{
- use ModelTrait;
-
- /**
- * 小程序创建用户后返回uid
- * @param $routineInfo
- * @return mixed
- */
- public static function routineOauth($routine){
- $routineInfo['nickname'] = $routine['nickName'];//姓名
- $routineInfo['sex'] = $routine['gender'];//性别
- $routineInfo['language'] = $routine['language'];//语言
- $routineInfo['city'] = $routine['city'];//城市
- $routineInfo['province'] = $routine['province'];//省份
- $routineInfo['country'] = $routine['country'];//国家
- $routineInfo['headimgurl'] = $routine['avatarUrl'];//头像
-// $routineInfo[''] = $routine['code'];//临时登录凭证 是获取用户openid和session_key(会话密匙)
- $routineInfo['routine_openid'] = $routine['routine_openid'];//openid
- $routineInfo['session_key'] = $routine['session_key'];//会话密匙
- $routineInfo['unionid'] = $routine['unionid'];//用户在开放平台的唯一标识符
- $routineInfo['user_type'] = 'routine';//用户类型
- $page = '';//跳转小程序的页面
- $spid = 0;//绑定关系uid
- //获取是否有扫码进小程序
- if($routine['spid']){
- $info = RoutineQrcode::getRoutineQrcodeFindType($routine['spid']);
- if($info){
- $spid = $info['third_id'];
- $page = $info['page'];
- }
- }
- // 判断unionid 存在根据unionid判断
- if($routineInfo['unionid'] != '' && WechatUser::be(['unionid'=>$routineInfo['unionid']])){
- WechatUser::edit($routineInfo,$routineInfo['unionid'],'unionid');
- $uid = WechatUser::where('unionid',$routineInfo['unionid'])->value('uid');
- User::updateWechatUser($routineInfo,$uid);
- }else if(WechatUser::be(['routine_openid'=>$routineInfo['routine_openid']])){ //根据小程序openid判断
- WechatUser::edit($routineInfo,$routineInfo['routine_openid'],'routine_openid');
- $uid = WechatUser::where('routine_openid',$routineInfo['routine_openid'])->value('uid');
- User::updateWechatUser($routineInfo,$uid);
- }else{
- $routineInfo['add_time'] = time();//用户添加时间
- $routineInfo = WechatUser::set($routineInfo);
- if(User::isUserSpread($spid)) {
- $res = User::setRoutineUser($routineInfo,$spid); //用户上级
- }else $res = User::setRoutineUser($routineInfo);
- $uid = $res->uid;
- }
- $data['page'] = $page;
- $data['uid'] = $uid;
- return $data;
- }
-
- /**
- * 判断是否是小程序用户
- * @param int $uid
- * @return bool|int|string
- */
- public static function isRoutineUser($uid = 0){
- if(!$uid) return false;
- return WechatUser::where('uid',$uid)->where('user_type','routine')->count();
- }
-
- public static function isUserStatus($uid = 0){
- if(!$uid) return 0;
- $user = User::getUserInfo($uid);
- return $user['status'];
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/User.php b/application/routine/model/user/User.php
deleted file mode 100644
index 8913faea..00000000
--- a/application/routine/model/user/User.php
+++ /dev/null
@@ -1,148 +0,0 @@
-
- * @day: 2017/12/21
- */
-
-namespace app\routine\model\user;
-
-use basic\ModelBasic;
-use service\SystemConfigService;
-use think\Request;
-use think\Session;
-use traits\ModelTrait;
-
-/**
- * 用户model
- * Class User
- * @package app\routine\model\user
- */
-class User extends ModelBasic
-{
- use ModelTrait;
-
- public static function updateWechatUser($wechatUser,$uid)
- {
- return self::edit([
- 'nickname'=>$wechatUser['nickname']?:'',
- 'avatar'=>$wechatUser['headimgurl']?:'',
- 'last_time'=>time(),
- 'last_ip'=>Request::instance()->ip(),
- ],$uid,'uid');
- }
-
-
-
- /**
- * 小程序用户添加
- * @param $routineUser
- * @param int $spread_uid
- * @return object
- */
- public static function setRoutineUser($routineUser,$spread_uid = 0){
- return self::set([
- 'account'=>'rt'.$routineUser['uid'].time(),
- 'pwd'=>md5(123456),
- 'nickname'=>$routineUser['nickname']?:'',
- 'avatar'=>$routineUser['headimgurl']?:'',
- 'spread_uid'=>$spread_uid,
- 'uid'=>$routineUser['uid'],
- 'add_time'=>$routineUser['add_time'],
- 'add_ip'=>Request::instance()->ip(),
- 'last_time'=>time(),
- 'last_ip'=>Request::instance()->ip(),
- 'user_type'=>$routineUser['user_type']
- ]);
- }
-
- /**
- * 获得当前登陆用户UID
- * @return int $uid
- */
- public static function getActiveUid()
- {
- $uid = null;
- $uid = Session::get('LoginUid');
- if($uid) return $uid;
- else return 0;
- }
- public static function getUserInfo($uid)
- {
- $userInfo = self::where('uid',$uid)->find();
- if(!$userInfo) exception('读取用户信息失败!');
- return $userInfo->toArray();
- }
-
- /**
- * 判断当前用户是否推广员
- * @param int $uid
- * @return bool
- */
- public static function isUserSpread($uid = 0){
- if(!$uid) return false;
- $status = (int)SystemConfigService::get('store_brokerage_statu');
- $isPromoter = true;
- if($status == 1) $isPromoter = self::where('uid',$uid)->value('is_promoter');
- if($isPromoter) return true;
- else return false;
- }
-
-
- /**
- * 小程序用户一级分销
- * @param $orderInfo
- * @return bool
- */
- public static function backOrderBrokerage($orderInfo)
- {
- $userInfo = User::getUserInfo($orderInfo['uid']);
- if(!$userInfo || !$userInfo['spread_uid']) return true;
- $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
- if($storeBrokerageStatu == 1){
- if(!User::be(['uid'=>$userInfo['spread_uid'],'is_promoter'=>1])) return true;
- }
- $brokerageRatio = (SystemConfigService::get('store_brokerage_ratio') ?: 0)/100;
- if($brokerageRatio <= 0) return true;
- $cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
- if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
- $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
- if($brokeragePrice <= 0) return true;
- $mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
- self::beginTrans();
- $res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
- $res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
- $res = $res1 && $res2;
- self::checkTrans($res);
- if($res) self::backOrderBrokerageTwo($orderInfo);
- return $res;
- }
-
- /**
- * 小程序 二级推广
- * @param $orderInfo
- * @return bool
- */
- public static function backOrderBrokerageTwo($orderInfo){
- $userInfo = User::getUserInfo($orderInfo['uid']);
- $userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
- if(!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
- $storeBrokerageStatu = SystemConfigService::get('store_brokerage_statu') ? : 1;//获取后台分销类型
- if($storeBrokerageStatu == 1){
- if(!User::be(['uid'=>$userInfoTwo['spread_uid'],'is_promoter'=>1])) return true;
- }
- $brokerageRatio = (SystemConfigService::get('store_brokerage_ratio_two') ?: 0)/100;
- if($brokerageRatio <= 0) return true;
- $cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
- if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
- $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
- if($brokeragePrice <= 0) return true;
- $mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
- self::beginTrans();
- $res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],0,$mark);
- $res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
- $res = $res1 && $res2;
- self::checkTrans($res);
- return $res;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserAddress.php b/application/routine/model/user/UserAddress.php
deleted file mode 100644
index 39525a57..00000000
--- a/application/routine/model/user/UserAddress.php
+++ /dev/null
@@ -1,51 +0,0 @@
-
- * @day: 2017/12/25
- */
-
-namespace app\routine\model\user;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class UserAddress extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- public static function setDefaultAddress($id,$uid)
- {
- self::beginTrans();
- $res1 = self::where('uid',$uid)->update(['is_default'=>0]);
- $res2 = self::where('id',$id)->where('uid',$uid)->update(['is_default'=>1]);
- $res =$res1 !== false && $res2 !== false;
- self::checkTrans($res);
- return $res;
- }
-
- public static function userValidAddressWhere($model=null,$prefix = '')
- {
- if($prefix) $prefix .='.';
- $model = self::getSelfModel($model);
- return $model->where("{$prefix}is_del",0);
- }
-
- public static function getUserValidAddressList($uid,$field = '*')
- {
- return self::userValidAddressWhere()->where('uid',$uid)->order('add_time DESC')->field($field)->select()->toArray()?:[];
- }
-
- public static function getUserDefaultAddress($uid,$field = '*')
- {
- return self::userValidAddressWhere()->where('uid',$uid)->where('is_default',1)->field($field)->find();
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserBill.php b/application/routine/model/user/UserBill.php
deleted file mode 100644
index 3f036b03..00000000
--- a/application/routine/model/user/UserBill.php
+++ /dev/null
@@ -1,37 +0,0 @@
-
- * @day: 2017/12/30
- */
-
-namespace app\routine\model\user;
-
-
-use basic\ModelBasic;
-use traits\ModelTrait;
-
-class UserBill extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- public static function income($title,$uid,$category,$type,$number,$link_id = 0,$balance = 0,$mark = '',$status = 1)
- {
- $pm = 1;
- return self::set(compact('title','uid','link_id','category','type','number','balance','mark','status','pm'));
- }
-
- public static function expend($title,$uid,$category,$type,$number,$link_id = 0,$balance = 0,$mark = '',$status = 1)
- {
- $pm = 0;
- return self::set(compact('title','uid','link_id','category','type','number','balance','mark','status','pm'));
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserExtract.php b/application/routine/model/user/UserExtract.php
deleted file mode 100644
index e276e609..00000000
--- a/application/routine/model/user/UserExtract.php
+++ /dev/null
@@ -1,118 +0,0 @@
-
- * @day: 2018/3/3
- */
-
-namespace app\routine\model\user;
-
-
-use basic\ModelBasic;
-use service\SystemConfigService;
-use service\WechatTemplateService;
-use think\Url;
-use traits\ModelTrait;
-use app\routine\model\user\WechatUser;
-class UserExtract extends ModelBasic
-{
- use ModelTrait;
-
- //审核中
- const AUDIT_STATUS = 0;
- //未通过
- const FAIL_STATUS = -1;
- //已提现
- const SUCCESS_STATUS = 1;
-
- protected static $extractType = ['alipay','bank','weixin'];
-
- protected static $extractTypeMsg = ['alipay'=>'支付宝','bank'=>'银行卡','weixin'=>'微信'];
-
- protected static $status = array(
- -1=>'未通过',
- 0 =>'审核中',
- 1 =>'已提现'
- );
-
- public static function userExtract($userInfo,$data){
- if(!in_array($data['extract_type'],self::$extractType))
- return self::setErrorInfo('提现方式不存在');
- $userInfo = User::get($userInfo['uid']);
- if($data['money'] > $userInfo['now_money']) return self::setErrorInfo('余额不足');;
- $balance = bcsub($userInfo['now_money'],$data['money'],2);
- $insertData = [
- 'uid'=>$userInfo['uid'],
- 'extract_type'=>$data['extract_type'],
- 'extract_price'=>(int)$data['money'],
- 'add_time'=>time(),
- 'balance'=>$balance,
- 'status'=>self::AUDIT_STATUS
- ];
- if(isset($data['$name'])){
- $insertData['real_name']=$data['$name'];
- }else{
- $insertData['real_name']='';
- }
- if(isset($data['cardnum'])){
- $insertData['bank_code']=$data['cardnum'];
- }else{
- $insertData['bank_code']='';
- }
- if(isset($data['bankname'])){
- $insertData['bank_address']=$data['bankname'];
- }else{
- $insertData['bank_address']='';
- }
- if(isset($data['weixin'])){
- $insertData['wechat']=$data['weixin'];
- }else{
- $insertData['wechat']='';
- }
- if($data['extract_type'] == 'alipay'){
- if(!$data['alipay_code']) return self::setErrorInfo('请输入支付宝账号');
- $insertData['alipay_code'] = $data['alipay_code'];
- $mark = '使用支付宝提现'.$insertData['extract_price'].'元';
- }elseif($data['extract_type'] == 'bank'){
- if(!$data['cardnum']) return self::setErrorInfo('请输入银行卡账号');
- if(!$data['bankname']) return self::setErrorInfo('请输入开户行信息');
- $mark = '使用银联卡'.$insertData['bank_code'].'提现'.$insertData['extract_price'].'元';
- }else{
- if(!$data['weixin']) return self::setErrorInfo('请输入微信号');
- $mark = '使用微信提现'.$insertData['extract_price'].'元';
- }
- self::beginTrans();
- $res1 = self::set($insertData);
- if(!$res1) return self::setErrorInfo('提现失败');
- $res2 = User::edit(['now_money'=>$balance],$userInfo['uid'],'uid');
- $res3 = UserBill::expend('余额提现',$userInfo['uid'],'now_money','extract',$data['money'],$res1['id'],$balance,$mark);
- $res = $res2 && $res3;
- self::checkTrans($res);
- if($res){
- //发送模板消息
- return true;
- }
- else return self::setErrorInfo('提现失败!');
- }
-
- /**
- * 获得用户最后一次提现信息
- * @param $openid
- * @return mixed
- */
- public static function userLastInfo($uid)
- {
- return self::where(compact('uid'))->order('add_time DESC')->find();
- }
-
- /**
- * 获得用户提现总金额
- * @param $uid
- * @return mixed
- */
- public static function userExtractTotalPrice($uid)
- {
- return self::where('uid',$uid)->where('status',self::SUCCESS_STATUS)->value('SUM(extract_price)')?:0;
- }
-
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserNotice.php b/application/routine/model/user/UserNotice.php
deleted file mode 100644
index 18b5c22d..00000000
--- a/application/routine/model/user/UserNotice.php
+++ /dev/null
@@ -1,57 +0,0 @@
-
- * @day: 2017/11/11
- */
-
-namespace app\routine\model\user;
-
-use app\admin\model\user\UserNoticeSee;
-use traits\ModelTrait;
-use basic\ModelBasic;
-
-/**
- * 用户通知 model
- * Class UserNotice
- * @package app\admin\model\user
- */
-class UserNotice extends ModelBasic
-{
- use ModelTrait;
- public static function getNotice($uid){
- $count_notice = self::where('uid','like',"%,$uid,%")->where("is_send",1)->count();
- $see_notice = UserNoticeSee::where("uid",$uid)->count();
- return $count_notice-$see_notice;
- }
- /**
- * @return array
- */
- public static function getNoticeList($uid,$page,$limit = 8){
- //定义分页信息
- $count = self::where('uid','like',"%,$uid,%")->count();
- $data["lastpage"] = ceil($count/$limit) <= ($page+1) ? 1 : 0;
-
- $where['uid'] = array("like","%,$uid,%");
-// $where['uid'] = array(array("like","%,$uid,%"),array("eq",""), 'or');
- $where['is_send'] = 1;
- $list = self::where($where)->field('id,user,title,content,add_time')->order("add_time desc")->limit($page*$limit,$limit)->select()->toArray();
- foreach ($list as $key => $value) {
- $list[$key]["add_time"] = date("Y-m-d H:i:s",$value["add_time"]);
- $list[$key]["is_see"] = UserNoticeSee::where("uid",$uid)->where("nid",$value["id"])->count() > 0 ? 1 : 0;
- }
- $data["list"] = $list;
- return $data;
- }
- /**
- * @return array
- */
- public static function seeNotice($uid,$nid){
- if(UserNoticeSee::where("uid",$uid)->where("nid",$nid)->count() <= 0){
- $data["nid"] = $nid;
- $data["uid"] = $uid;
- $data["add_time"] = time();
- UserNoticeSee::set($data);
- }
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserRecharge.php b/application/routine/model/user/UserRecharge.php
deleted file mode 100644
index e4172604..00000000
--- a/application/routine/model/user/UserRecharge.php
+++ /dev/null
@@ -1,60 +0,0 @@
-
- * @day: 2018/01/05
- */
-
-namespace app\routine\model\user;
-
-use basic\ModelBasic;
-use service\RoutineService;
-use traits\ModelTrait;
-
-class UserRecharge extends ModelBasic
-{
- use ModelTrait;
-
- protected $insert = ['add_time'];
-
- protected function setAddTimeAttr()
- {
- return time();
- }
-
- public static function addRecharge($uid,$price,$recharge_type = 'weixin',$paid = 0)
- {
- $order_id = self::getNewOrderId($uid);
- return self::set(compact('order_id','uid','price','recharge_type','paid'));
- }
-
- public static function getNewOrderId($uid = 0)
- {
- if(!$uid) return false;
- $count = (int) self::where('add_time',['>=',strtotime(date("Y-m-d"))],['<',strtotime(date("Y-m-d",strtotime('+1 day')))])->count();
- return 'wx1'.date('YmdHis',time()).(10000+$count+$uid);
- }
-
- public static function jsPay($orderInfo)
- {
- return RoutineService::payRoutine(WechatUser::uidToOpenid($orderInfo['uid']),$orderInfo['order_id'],$orderInfo['price'],'user_recharge','用户充值');
- }
-
- /**
- * //TODO用户充值成功后
- * @param $orderId
- */
- public static function rechargeSuccess($orderId)
- {
- $order = self::where('order_id',$orderId)->where('paid',0)->find();
- if(!$order) return false;
- $user = User::getUserInfo($order['uid']);
- self::beginTrans();
- $res1 = self::where('order_id',$order['order_id'])->update(['paid'=>1,'pay_time'=>time()]);
- $res2 = UserBill::income('用户余额充值',$order['uid'],'now_money','recharge',$order['price'],$order['id'],$user['now_money'],'成功充值余额'.floatval($order['price']).'元');
- $res3 = User::edit(['now_money'=>bcadd($user['now_money'],$order['price'],2)],$order['uid'],'uid');
- $res = $res1 && $res2 && $res3;
- self::checkTrans($res);
- return $res;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/UserSign.php b/application/routine/model/user/UserSign.php
deleted file mode 100644
index db65eddf..00000000
--- a/application/routine/model/user/UserSign.php
+++ /dev/null
@@ -1,52 +0,0 @@
-
- * @day: 2018/02/28
- */
-
-namespace app\routine\model\user;
-
-
-use basic\ModelBasic;
-use service\SystemConfigService;
-use think\Model;
-
-class UserSign
-{
- public static function checkUserSigned($uid)
- {
- return UserBill::be(['uid'=>$uid,'add_time'=>['>',strtotime('today')],'category'=>'integral','type'=>'sign']);
- }
-
- public static function userSignedCount($uid)
- {
- return self::userSignBillWhere($uid)->count();
- }
-
- /**
- * @param $uid
- * @return Model
- */
- public static function userSignBillWhere($uid)
- {
- return UserBill::where(['uid'=>$uid,'category'=>'integral','type'=>'sign']);
- }
-
- public static function sign($userInfo)
- {
- $uid = $userInfo['uid'];
- $min = SystemConfigService::get('sx_sign_min_int')?:0;
- $max = SystemConfigService::get('sx_sign_max_int')?:5;
- $integral = rand($min,$max);
- ModelBasic::beginTrans();
- $res1 = UserBill::income('用户签到',$uid,'integral','sign',$integral,0,$userInfo['integral'],'签到获得'.floatval($integral).'积分');
- $res2 = User::bcInc($uid,'integral',$integral,'uid');
- $res = $res1 && $res2;
- ModelBasic::checkTrans($res);
- if($res)
- return $integral;
- else
- return false;
- }
-}
\ No newline at end of file
diff --git a/application/routine/model/user/WechatUser.php b/application/routine/model/user/WechatUser.php
deleted file mode 100644
index 80352593..00000000
--- a/application/routine/model/user/WechatUser.php
+++ /dev/null
@@ -1,43 +0,0 @@
-
- * @day: 2017/12/21
- */
-
-namespace app\routine\model\user;
-
-use app\routine\model\store\StoreCouponUser;
-use basic\ModelBasic;
-use service\SystemConfigService;
-use traits\ModelTrait;
-/**
- * 微信用户model
- * Class WechatUser
- * @package app\routine\model\user
- */
-class WechatUser extends ModelBasic
-{
- use ModelTrait;
-
- public static function getOpenId($uid = ''){
- if($uid == '') return false;
- return self::where('uid',$uid)->value('routine_openid');
- }
- /**
- * 用uid获得openid
- * @param $uid
- * @return mixed
- */
- public static function uidToOpenid($uid)
- {
- $openid = self::where('uid',$uid)->value('routine_openid');
- return $openid;
- }
-
- public static function userTakeOrderGiveCoupon($uid)
- {
- $couponId = SystemConfigService::get('store_order_give_coupon');
- if($couponId) StoreCouponUser::addUserCoupon($uid,$couponId);
- }
-}
\ No newline at end of file