diff --git a/application/admin/common.php b/application/admin/common.php
index 316ba6dd..12e02529 100644
--- a/application/admin/common.php
+++ b/application/admin/common.php
@@ -34,13 +34,13 @@ function attrFormat($arr){
//替代变量3
$rep3 = explode('_', $h);
//替代变量4
- $rep4['detail'][$rep3[0]] = $rep3[1];
+ $rep4['detail'][$rep3[0]] = isset($rep3[1]) ? $rep3[1] : '';
}
$res[] = $rep4;
}
}
}
- $data = $tmp;
+ $data = isset($tmp) ? $tmp : [];
}
}else{
$dataArr = [];
@@ -102,18 +102,18 @@ function clearfile($path,$ext = '*.log')
}
return true;
}
+
/**获取当前类方法
* @param $class
* @return array
*/
-function get_this_class_methods($class,$array4 = []) {
- $array1 = get_class_methods($class);
+function get_this_class_methods($class,$unarray = []) {
+ $arrayall = get_class_methods($class);
if ($parent_class = get_parent_class($class)) {
- $array2 = get_class_methods($parent_class);
- $array3 = array_diff($array1, $array2);//去除父级的
+ $arrayparent = get_class_methods($parent_class);
+ $arraynow = array_diff($arrayall, $arrayparent);//去除父级的
} else {
- $array3 = $array1;
+ $arraynow = $arrayall;
}
- $array5 = array_diff($array3, $array4);//去除无用的
- return $array5;
+ return array_diff($arraynow, $unarray);//去除无用的
}
diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php
index 74afc59b..2b109057 100644
--- a/application/admin/controller/Index.php
+++ b/application/admin/controller/Index.php
@@ -11,6 +11,7 @@ use app\admin\model\user\UserExtract as UserExtractModel;//分销
use app\admin\model\user\User as UserModel;//用户
use app\admin\model\store\StoreProductReply as StoreProductReplyModel;//评论
use app\admin\model\store\StoreProduct as ProductModel;//产品
+use app\core\util\SystemConfigService;
use FormBuilder\Json;
use think\DB;
@@ -28,11 +29,10 @@ class Index extends AuthController
$adminInfo = $this->adminInfo->toArray();
$roles = explode(',',$adminInfo['roles']);
$site_logo = SystemConfig::getOneConfig('menu_name','site_logo')->toArray();
-// dump(SystemMenus::menuList());
-// exit();
$this->assign([
'menuList'=>SystemMenus::menuList(),
'site_logo'=>json_decode($site_logo['value'],true),
+ 'new_order_audio_link'=>str_replace('\\','/',SystemConfigService::get('new_order_audio_link')),
'role_name'=>SystemRole::where('id',$roles[0])->field('role_name')->find()
]);
return $this->fetch();
@@ -545,32 +545,37 @@ class Index extends AuthController
$data = [];
$chartdata['legend'] = ['用户数'];//分类
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
- if(empty($user_list))return Json::fail('无数据');
- foreach ($user_list as $k=>$v){
- $data['day'][] = $v['day'];
- $data['count'][] = $v['count'];
- if($chartdata['yAxis']['maxnum'] < $v['count'])
- $chartdata['yAxis']['maxnum'] = $v['count'];
+ $chartdata['xAxis'] = [date('m-d')];//X轴值
+ $chartdata['series'] = [0];//分类1值
+ if(!empty($user_list)) {
+ foreach ($user_list as $k=>$v){
+ $data['day'][] = $v['day'];
+ $data['count'][] = $v['count'];
+ if($chartdata['yAxis']['maxnum'] < $v['count'])
+ $chartdata['yAxis']['maxnum'] = $v['count'];
+ }
+ $chartdata['xAxis'] = $data['day'];//X轴值
+ $chartdata['series'] = $data['count'];//分类1值
}
- $chartdata['xAxis'] = $data['day'];//X轴值
- $chartdata['series'] = $data['count'];//分类1值
-
return Json::succ('ok',$chartdata);
}
/**待办事统计
* @param Request|null $request
*/
- public function Jnotice()
+ public function Jnotice($newTime=30)
{
header('Content-type:text/json');
$data = [];
$data['ordernum'] = StoreOrderModel::statusByWhere(1)->count();//待发货
$replenishment_num = SystemConfig::getValue('store_stock') > 0 ? SystemConfig::getValue('store_stock') : 2;//库存预警界限
$data['inventory'] = ProductModel::where('stock','<=',$replenishment_num)->where('is_show',1)->where('is_del',0)->count();//库存
- $data['commentnum'] = StoreProductReplyModel::where('is_reply',0)->count();//评论
+ $data['commentnum'] = StoreProductReplyModel::where(['is_reply'=>0,'is_del'=>0])->count();//评论
$data['reflectnum'] = UserExtractModel::where('status',0)->count();;//提现
$data['msgcount'] = intval($data['ordernum'])+intval($data['inventory'])+intval($data['commentnum'])+intval($data['reflectnum']);
+ //新订单提醒
+ $data['newOrderId']=StoreOrderModel::statusByWhere(1)->where('is_remind',0)->column('order_id');
+ if(count($data['newOrderId'])) StoreOrderModel::where('order_id','in',$data['newOrderId'])->update(['is_remind'=>1]);
return Json::succ('ok',$data);
}
}
diff --git a/application/admin/controller/agent/AgentManage.php b/application/admin/controller/agent/AgentManage.php
index f33180fa..8b72f5a9 100644
--- a/application/admin/controller/agent/AgentManage.php
+++ b/application/admin/controller/agent/AgentManage.php
@@ -4,10 +4,14 @@ namespace app\admin\controller\agent;
use app\admin\controller\AuthController;
use app\admin\model\order\StoreOrder;
+use app\admin\model\system\SystemAttachment;
use app\admin\model\user\User;
use app\admin\model\wechat\WechatUser as UserModel;
use app\admin\library\FormBuilder;
+use app\core\model\routine\RoutineQrcode;
use app\core\model\user\UserBill;
+use service\JsonService;
+use service\UploadService;
use service\UtilService as Util;
/**
@@ -23,63 +27,250 @@ class AgentManage extends AuthController
*/
public function index()
{
- $where = Util::getMore([
- ['nickname',''],
- ['data',''],
- ['tagid_list',''],
- ['groupid','-1'],
- ['sex',''],
- ['export',''],
- ['stair',''],
- ['second',''],
- ['order_stair',''],
- ['order_second',''],
- ['subscribe',''],
- ['now_money',''],
- ['is_promoter',1],
- ],$this->request);
- $this->assign([
- 'where'=>$where,
- ]);
- $limitTimeList = [
- 'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
- 'week'=>implode(' - ',[
- date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
- date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
- ]),
- 'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
- 'quarter'=>implode(' - ',[
- date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
- date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
- ]),
- 'year'=>implode(' - ',[
- date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
- ])
- ];
- $uidAll = UserModel::getAll($where);
- $this->assign(compact('limitTimeList','uidAll'));
- $this->assign(UserModel::agentSystemPage($where));
+ $this->assign( 'year',getMonth('y'));
+ $this->assign('store_brokerage_statu',\app\core\util\SystemConfigService::get('store_brokerage_statu'));
return $this->fetch();
}
+ public function get_spread_list()
+ {
+ $where=Util::getMore([
+ ['nickname',''],
+ ['start_time',''],
+ ['end_time',''],
+ ['sex',''],
+ ['excel',''],
+ ['subscribe',''],
+ ['order',''],
+ ['data',''],
+ ['page',1],
+ ['limit',20],
+ ['user_type',''],
+ ]);
+ return JsonService::successlayui(UserModel::agentSystemPage($where));
+ }
+
+ public function get_badge()
+ {
+ $where = Util::postMore([
+ ['data',''],
+ ['nickname',''],
+ ['excel',''],
+ ]);
+ return JsonService::successful(UserModel::getSpreadBadge($where));
+ }
/**
- * 一级推荐人页面
+ * 推荐人页面
* @return mixed
*/
- public function stair($uid = ''){
+ public function stair($uid = '')
+ {
if($uid == '') return $this->failed('参数错误');
+ $this->assign('uid',$uid ? : 0);
+ $this->assign( 'year',getMonth('y'));
+ return $this->fetch();
+ }
+
+ /*
+ * 统计推广订单
+ * @param int $uid
+ * */
+ public function stair_order($uid = 0)
+ {
+ if($uid == '') return $this->failed('参数错误');
+ $this->assign('uid',$uid ? : 0);
+ $this->assign( 'year',getMonth('y'));
+ return $this->fetch();
+ }
+
+ public function get_stair_order_list(){
+ $where = Util::getMore([
+ ['uid',$this->request->param('uid',0)],
+ ['data',''],
+ ['order_id',''],
+ ['type',''],
+ ['page',1],
+ ['limit',20],
+ ]);
+ return JsonService::successlayui(UserModel::getStairOrderList($where));
+ }
+
+ public function get_stair_order_badge()
+ {
+ $where = Util::getMore([
+ ['uid',''],
+ ['data',''],
+ ['order_id',''],
+ ['type',''],
+ ]);
+ return JsonService::successful(UserModel::getStairOrderBadge($where));
+ }
+
+ public function get_stair_list()
+ {
+ $where = Util::getMore([
+ ['uid',$this->request->param('uid',0)],
+ ['data',''],
+ ['nickname',''],
+ ['type',''],
+ ['page',1],
+ ['limit',20],
+ ]);
+ return JsonService::successlayui(UserModel::getStairList($where));
+ }
+
+ public function get_stair_badge()
+ {
+ $where = Util::getMore([
+ ['uid',''],
+ ['data',''],
+ ['nickname',''],
+ ['type',''],
+ ]);
+ return JsonService::successful(UserModel::getSairBadge($where));
+ }
+ /**
+ * 二级推荐人页面
+ * @return mixed
+ */
+ public function stair_two($uid = '')
+ {
+ if($uid == '') return $this->failed('参数错误');
+ $spread_uid=User::where('spread_uid',$uid)->column('uid');
+ if(count($spread_uid))
+ $spread_uid_two=User::where('spread_uid','in',$spread_uid)->column('uid');
+ else
+ $spread_uid_two=[0];
$list = User::alias('u')
- ->where('u.spread_uid',$uid)
- ->field('u.avatar,u.nickname,u.now_money,u.add_time,u.uid')
+ ->where('u.uid','in',$spread_uid_two)
+ ->field('u.avatar,u.nickname,u.now_money,u.spread_time,u.uid')
->where('u.status',1)
->order('u.add_time DESC')
->select()
->toArray();
foreach ($list as $key=>$value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid'])?:0;
$this->assign('list',$list);
- return $this->fetch();
+ return $this->fetch('stair');
}
+ /*
+ * 批量清除推广权限
+ * */
+ public function delete_promoter()
+ {
+ list($uids)=Util::postMore([
+ ['uids',[]]
+ ],$this->request,true);
+ if(!count($uids)) return JsonService::fail('请选择需要解除推广权限的用户!');
+ User::beginTrans();
+ try{
+ if(User::where('uid','in',$uids)->update(['is_promoter'=>0])){
+ User::commitTrans();
+ return JsonService::successful('解除成功');
+ }else{
+ User::rollbackTrans();
+ return JsonService::fail('解除失败');
+ }
+ }catch (\PDOException $e){
+ User::rollbackTrans();
+ return JsonService::fail('数据库操作错误',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
+ }catch (\Exception $e){
+ User::rollbackTrans();
+ return JsonService::fail('系统错误',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
+ }
+
+ }
+
+ /*
+ * 查看公众号推广二维码
+ * @param int $uid
+ * @return json
+ * */
+ public function look_code($uid='',$action='')
+ {
+ if(!$uid || !$action) return JsonService::fail('缺少参数');
+ try{
+ if(method_exists($this,$action)){
+ $res = $this->$action($uid);
+ if($res)
+ return JsonService::successful($res);
+ else
+ return JsonService::fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!' );
+ }else
+ return JsonService::fail('暂无此方法');
+ }catch (\Exception $e){
+ return JsonService::fail('获取推广二维码失败,请检查您的微信配置',['line'=>$e->getLine(),'messag'=>$e->getMessage()]);
+ }
+ }
+ /*
+ * 获取小程序二维码
+ * */
+ public function routine_code($uid)
+ {
+ $userInfo = User::getUserInfos($uid);
+ $name = $userInfo['uid'].'_'.$userInfo['is_promoter'].'_user.jpg';
+ $imageInfo = SystemAttachment::getInfo($name,'name');
+ if(!$imageInfo){
+ $res = \app\core\model\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
+ if(!$res) throw new \think\Exception('二维码生成失败');
+ $imageInfo = UploadService::imageStream($name,$res['res'],'routine/spread/code');
+ if(!is_array($imageInfo)) return $imageInfo;
+ SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time']);
+ RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
+ $urlCode = $imageInfo['dir'];
+ }else $urlCode = $imageInfo['att_dir'];
+ return ['code_src'=>$urlCode];
+ }
+
+ /*
+ *
+ * */
+ public function wechant_code($uid)
+ {
+ $qr_code = \app\core\util\QrcodeService::getForeverQrcode('spread',$uid);
+ if(isset($qr_code['url']))
+ return ['code_src'=>$qr_code['url']];
+ else
+ throw new \think\Exception('获取失败,请稍后再试!');
+ }
+
+ /**
+ * TODO 查看小程序推广二维码
+ * @param string $uid
+ */
+ public function look_xcx_code($uid = '')
+ {
+ if(!strlen(trim($uid))) return JsonService::fail('缺少参数');
+ try{
+
+ }catch (\Exception $e){
+ return JsonService::fail('查看推广二维码失败!',['line'=>$e->getLine(),'meassge'=>$e->getMessage()]);
+ }
+ }
+ /*
+ * 解除单个用户的推广权限
+ * @param int $uid
+ * */
+ public function delete_spread($uid=0)
+ {
+ if(!$uid) return JsonService::fail('缺少参数');
+ if(User::where('uid',$uid)->update(['is_promoter'=>0]))
+ return JsonService::successful('解除成功');
+ else
+ return JsonService::fail('解除失败');
+ }
+
+ /*
+ * 清除自己的上级推广人
+ * */
+ public function empty_spread($uid=0)
+ {
+ if(!$uid) return JsonService::fail('缺少参数');
+ if(User::where('uid',$uid)->update(['spread_uid'=>0]))
+ return JsonService::successful('清除成功');
+ else
+ return JsonService::fail('清除失败');
+ }
/**
* 个人资金详情页面
* @return mixed
@@ -95,4 +286,5 @@ class AgentManage extends AuthController
$this->assign('list',$list);
return $this->fetch();
}
+
}
diff --git a/application/admin/controller/article/Article.php b/application/admin/controller/article/Article.php
index 7e1c69f8..d354ef9b 100644
--- a/application/admin/controller/article/Article.php
+++ b/application/admin/controller/article/Article.php
@@ -20,10 +20,13 @@ use app\admin\model\system\SystemAttachment;
class Article extends AuthController
{
/**
- * 显示后台管理员添加的图文
+ * TODO 显示后台管理员添加的图文
* @return mixed
+ * @throws \think\db\exception\DataNotFoundException
+ * @throws \think\db\exception\ModelNotFoundException
+ * @throws \think\exception\DbException
*/
- public function index($pid = 0)
+ public function index()
{
$where = Util::getMore([
['title',''],
@@ -32,34 +35,33 @@ class Article extends AuthController
$pid = $this->request->param('pid');
$this->assign('where',$where);
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
- $catlist = ArticleCategoryModel::where('is_del',0)->select()->toArray();
+ $cateList = ArticleCategoryModel::getArticleCategoryList();
+ $tree = [];
//获取分类列表
- if($catlist){
- $tree = Phptree::makeTreeForHtml($catlist);
- $this->assign(compact('tree'));
+ if(count($cateList)){
+ $tree = Phptree::makeTreeForHtml($cateList);
if($pid){
$pids = Util::getChildrenPid($tree,$pid);
$where['cid'] = ltrim($pid.$pids);
}
- }else{
- $tree = [];
- $this->assign(compact('tree'));
}
-
-
- $this->assign('cate',ArticleCategoryModel::getTierList());
+ $this->assign(compact('tree'));
$this->assign(ArticleModel::getAll($where));
return $this->fetch();
}
/**
- * 展示页面 添加和删除
+ * TODO 文件添加和修改
* @return mixed
+ * @throws \think\db\exception\DataNotFoundException
+ * @throws \think\db\exception\ModelNotFoundException
+ * @throws \think\exception\DbException
*/
public function create(){
- $id = input('id');
- $cid = input('cid');
- $news = array();
+ $id = $this->request->param('id');
+ $cid = $this->request->param('cid');
+ $news = [];
+ $all = [];
$news['id'] = '';
$news['image_input'] = '';
$news['title'] = '';
@@ -69,30 +71,19 @@ class Article extends AuthController
$news['content'] = '';
$news['synopsis'] = '';
$news['url'] = '';
- $news['cid'] = array();
+ $news['cid'] = [];
+ $select = 0;
if($id){
$news = ArticleModel::where('n.id',$id)->alias('n')->field('n.*,c.content')->join('ArticleContent c','c.nid=n.id')->find();
if(!$news) return $this->failedNotice('数据不存在!');
$news['cid'] = explode(',',$news['cid']);
}
- $all = array();
- $select = 0;
- if(!$cid)
- $cid = '';
- else {
- if($id){
- $all = ArticleCategoryModel::where('id',$cid)->where('hidden','neq',0)->column('id,title');
- $select = 1;
- }else{
- $all = ArticleCategoryModel::where('id',$cid)->column('id,title');
- $select = 1;
- }
-
+ if($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0,'id'))){
+ $all = ArticleCategoryModel::getArticleCategoryInfo($cid);
+ $select = 1;
}
- if(empty($all)){
- $select = 0;
+ if(!$select){
$list = ArticleCategoryModel::getTierList();
- $all = [];
foreach ($list as $menu){
$all[$menu['id']] = $menu['html'].$menu['title'];
}
@@ -110,11 +101,9 @@ class Article extends AuthController
*/
public function upload_image(){
$res = Upload::Image($_POST['file'],'wechat/image/'.date('Ymd'));
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,'',5);
- if(!$res->status) return Json::fail($res->error);
- return Json::successful('上传成功!',['url'=>$res->filePath]);
+ if(!is_array($res)) return Json::fail($res);
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
+ return Json::successful('上传成功!',['url'=>$res['dir']]);
}
/**
@@ -146,15 +135,13 @@ class Article extends AuthController
if($data['id']){
$id = $data['id'];
unset($data['id']);
+ $res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::edit($data,$id,'id');
$res2 = ArticleModel::setContent($id,$content);
- if($res1 && $res2)
+ if($res1 && $res2){
$res = true;
- else
- $res =false;
-// dump($res);
-// exit();
+ }
ArticleModel::checkTrans($res);
if($res)
return Json::successful('修改图文成功!',$id);
@@ -163,15 +150,15 @@ class Article extends AuthController
}else{
$data['add_time'] = time();
$data['admin_id'] = $this->adminId;
+ $res = false;
ArticleModel::beginTrans();
$res1 = ArticleModel::set($data);
$res2 = false;
if($res1)
$res2 = ArticleModel::setContent($res1->id,$content);
- if($res1 && $res2)
+ if($res1 && $res2){
$res = true;
- else
- $res =false;
+ }
ArticleModel::checkTrans($res);
if($res)
return Json::successful('添加图文成功!',$res1->id);
diff --git a/application/admin/controller/article/ArticleCategory.php b/application/admin/controller/article/ArticleCategory.php
index 38b80671..b062dcd2 100644
--- a/application/admin/controller/article/ArticleCategory.php
+++ b/application/admin/controller/article/ArticleCategory.php
@@ -3,6 +3,7 @@
namespace app\admin\controller\article;
use app\admin\controller\AuthController;
+use app\admin\model\system\SystemAttachment;
use service\FormBuilder as Form;
use service\UtilService as Util;
use service\JsonService as Json;
@@ -59,7 +60,7 @@ class ArticleCategory extends AuthController
// }
// return $options;
// })->multiple(1)->filterable(1);
- $f[] = Form::frameImageOne('image','分类图片',Url::build('admin/widget.images/index',array('fodder'=>'image')))->icon('image');
+ $f[] = Form::formFrameImageOne('image','分类图片');
$f[] = Form::number('sort','排序',0);
$f[] = Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
$form = Form::make_post_form('添加分类',$f,Url::build('save'));
@@ -73,11 +74,9 @@ class ArticleCategory extends AuthController
* */
public function upload(){
$res = Upload::image('file','article');
- $thumbPath = Upload::thumb($res->dir);
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
- else
- return Json::fail($res->error);
+ if(!is_array($res)) return Json::fail($res);
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
}
/**
@@ -136,7 +135,7 @@ class ArticleCategory extends AuthController
// }
// return $options;
// })->multiple(1)->filterable(1);
- $f[] = Form::frameImageOne('image','分类图片',Url::build('admin/widget.images/index',array('fodder'=>'image')),$article['image'])->icon('image');
+ $f[] = Form::formFrameImageOne('image','分类图片',$article['image']);
$f[] = Form::number('sort','排序',0);
$f[] = Form::radio('status','状态',$article['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
$form = Form::make_post_form('编辑分类',$f,Url::build('update',array('id'=>$id)));
diff --git a/application/admin/controller/finance/Finance.php b/application/admin/controller/finance/Finance.php
index cfd78a86..c05b87d3 100644
--- a/application/admin/controller/finance/Finance.php
+++ b/application/admin/controller/finance/Finance.php
@@ -28,64 +28,6 @@ class Finance extends AuthController
{
- /**
- * 显示操作记录
- */
- public function index(){
-
- //创建form
- $form = Form::create('/save.php',[
- Form::input('goods_name','商品名称')
- ,Form::input('goods_name1','password')->type('password')
- ,Form::input('goods_name2','textarea')->type('textarea')
- ,Form::input('goods_name3','email')->type('email')
- ,Form::input('goods_name4','date')->type('date')
- ,Form::cityArea('address','cityArea',[
- '陕西省','西安市'
- ])
- ,Form::dateRange('limit_time','dateRange',
- strtotime('- 10 day'),
- time()
- )
- ,Form::dateTime('add_time','dateTime')
- ,Form::color('color','color','#ff0000')
- ,Form::checkbox('checkbox','checkbox',[1])->options([['value'=>1,'label'=>'白色'],['value'=>2,'label'=>'红色'],['value'=>31,'label'=>'黑色']])
- ,Form::date('riqi','date','2018-03-1')
- ,Form::dateTimeRange('dateTimeRange','区间时间段')
- ,Form::year('year','year')
- ,Form::month('month','month')
- ,Form::frame('frame','frame','http://baidu.com')
- ,Form::frameInputs('month','frameInputs','http://baidu.com')
- ,Form::frameFiles('month1','frameFiles','http://baidu.com')
- ,Form::frameImages('month2','frameImages','http://baidu.com')
- ,Form::frameInputOne('month3','frameInputOne','http://baidu.com')
- ,Form::frameFileOne('month4','frameFileOne','http://baidu.com')
- ,Form::frameImageOne('month5','frameImageOne','http://baidu.com')
- ,Form::hidden('month6','hidden')
- ,Form::number('month7','number')
-// ,Form::input input输入框,其他type: text类型Form::text,password类型Form::password,textarea类型Form::textarea,url类型Form::url,email类型Form::email,date类型Form::idate
- ,Form::radio('month8','radio')->options([['value'=>1,'label'=>'白色'],['value'=>2,'label'=>'红色'],['value'=>31,'label'=>'黑色']])
- ,Form::rate('month9','rate')
- ,Form::select('month10','select')->options([['value'=>1,'label'=>'白色'],['value'=>2,'label'=>'红色'],['value'=>31,'label'=>'黑色']])
- ,Form::selectMultiple('month11','selectMultiple')
- ,Form::selectOne('month12','selectOne')
- ,Form::slider('month13','slider',2)
- ,Form::sliderRange('month23','sliderRange',2,13)
- ,Form::switches('month14','区间时间段')
- ,Form::timePicker('month15','区间时间段')
- ,Form::time('month16','区间时间段')
- ,Form::timeRange('month17','区间时间段')
-// ,Form::upload('month','区间时间段')
-// ,Form::uploadImages('month','区间时间段')
-// ,Form::uploadFiles('month','区间时间段')
-// ,Form::uploadImageOne('month','区间时间段')
-// ,Form::uploadFileOne('month','区间时间段')
-
- ]);
- $html = $form->setMethod('get')->setTitle('编辑商品')->view();
- echo $html;
-
- }
/**
* 显示资金记录
*/
@@ -126,41 +68,7 @@ class Finance extends AuthController
]);
FinanceModel::SaveExport($where);
}
-// /**
-// * 显示佣金记录
-// */
-// public function commission_list(){
-//
-// //创建form
-// $form = Form::create('/save.php',[
-// Form::input('goods_name','商品名称')
-// ,Form::input('goods_name1','password')->type('password')
-// ,Form::input('goods_name3','email')->type('email')
-// ,Form::input('goods_name4','date')->type('date')
-// ,Form::cityArea('address','cityArea',[
-// '陕西省','西安市'
-// ])
-// ,Form::dateRange('limit_time','dateRange',
-// strtotime('- 10 day'),
-// time()
-// )
-// ,Form::dateTime('add_time','dateTime')
-// ,Form::color('color','color','#ff0000')
-// ,Form::checkbox('checkbox','checkbox',[1])->options([['value'=>1,'label'=>'白色'],['value'=>2,'label'=>'红色'],['value'=>31,'label'=>'黑色']])
-// ,Form::date('riqi','date','2018-03-1')
-// ,Form::dateTimeRange('dateTimeRange','区间时间段')
-// ,Form::year('year','year')
-//
-// ,Form::hidden('month6','hidden')
-// ,Form::number('month7','number')
-//
-//
-// ]);
-// $rule = $form->setMethod('post')->setTitle('编辑商品')->getRules();
-// $action = Url::build('save');
-// $this->assign(compact('form','rule','action'));
-// return $this->fetch();
-// }
+
/**
* 显示佣金记录
*/
@@ -168,6 +76,7 @@ class Finance extends AuthController
$this->assign('is_layui',true);
return $this->fetch();
}
+
/**
* 佣金记录异步获取
*/
@@ -178,24 +87,12 @@ class Finance extends AuthController
['nickname',''],
['price_max',''],
['price_min',''],
- ['order','']
+ ['order',''],
+ ['excel',''],
]);
return Json::successlayui(User::getCommissionList($get));
}
- /**
- * 保存excel表格
- */
- public function save_export(){
- $get=Util::getMore([
- ['page',1],
- ['limit',20],
- ['nickname',''],
- ['price_max',''],
- ['price_min',''],
- ['order','']
- ]);
- User::setUserWhere($get,true);
- }
+
/**
* 显示操作记录
*/
diff --git a/application/admin/controller/finance/UserExtract.php b/application/admin/controller/finance/UserExtract.php
index 8a1115df..572783fb 100644
--- a/application/admin/controller/finance/UserExtract.php
+++ b/application/admin/controller/finance/UserExtract.php
@@ -113,12 +113,14 @@ class UserExtract extends AuthController
UserExtractModel::beginTrans();
$extract=UserExtractModel::get($id);
if(!$extract) return JsonService::fail('操作记录不存!');
- if($extract->status==1) return JsonService::fail('您已提现,请勿重复提现!');
- if($extract->status==-1) return JsonService::fail('您的提现申请已被拒绝!');
+ if($extract->status == 1) return JsonService::fail('您已提现,请勿重复提现!');
+ if($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝!');
$res = UserExtractModel::changeSuccess($id);
if($res){
+ UserExtractModel::commitTrans();
return JsonService::successful('操作成功!');
}else{
+ UserExtractModel::rollbackTrans();
return JsonService::fail('操作失败!');
}
}
diff --git a/application/admin/controller/finance/UserRecharge.php b/application/admin/controller/finance/UserRecharge.php
index 35945433..1bfaadd9 100644
--- a/application/admin/controller/finance/UserRecharge.php
+++ b/application/admin/controller/finance/UserRecharge.php
@@ -1,7 +1,9 @@
getMessage());
}
UserRechargeModel::edit($data,$id);
- WechatTemplateService::sendTemplate(WechatUserWap::uidToOpenid($UserRecharge['uid']),WechatTemplateService::ORDER_REFUND_STATUS, [
- 'first'=>'亲,您充值的金额已退款,本次退款'.
- $data['refund_price'].'金额',
- 'keyword1'=>$UserRecharge['order_id'],
- 'keyword2'=>$UserRecharge['price'],
- 'keyword3'=>date('Y-m-d H:i:s',$UserRecharge['add_time']),
- 'remark'=>'点击查看订单详情'
- ],Url::build('wap/My/balance','',true,true));
+ User::bcDec($UserRecharge['uid'],'now_money',$refund_price,'uid');
+ switch (strtolower($UserRecharge['recharge_type'])){
+ case 'weixin':
+ WechatTemplateService::sendTemplate(WechatUserWap::where('uid',$UserRecharge['uid'])->value('openid'),WechatTemplateService::ORDER_REFUND_STATUS, [
+ 'first'=>'亲,您充值的金额已退款,本次退款'.
+ $data['refund_price'].'金额',
+ 'keyword1'=>$UserRecharge['order_id'],
+ 'keyword2'=>$UserRecharge['price'],
+ 'keyword3'=>date('Y-m-d H:i:s',$UserRecharge['add_time']),
+ 'remark'=>'点击查看订单详情'
+ ],Url::build('wap/My/balance','',true,true));
+ break;
+ case 'routine':
+ RoutineTemplate::sendOut('ORDER_REFUND_SUCCESS',$UserRecharge['uid'],[
+ 'keyword1'=>$UserRecharge['order_id'],
+ 'keyword2'=>date('Y-m-d H:i:s',time()),
+ 'keyword3'=>$UserRecharge['price'],
+ 'keyword4'=>'余额充值退款',
+ 'keyword5'=>'亲,您充值的金额已退款,本次退款'. $data['refund_price'].'金额',
+ ]);
+ break;
+ }
UserBill::expend('系统退款',$UserRecharge['uid'],'now_money','user_recharge_refund',$refund_price,$id,$UserRecharge['price'],'退款给用户'.$refund_price.'元');
return Json::successful('退款成功!');
}
diff --git a/application/admin/controller/order/StoreOrder.php b/application/admin/controller/order/StoreOrder.php
index 75cf6f83..90435059 100644
--- a/application/admin/controller/order/StoreOrder.php
+++ b/application/admin/controller/order/StoreOrder.php
@@ -42,6 +42,7 @@ class StoreOrder extends AuthController
$this->assign([
'year'=>getMonth('y'),
'real_name'=>$this->request->get('real_name',''),
+ 'status'=>$this->request->param('status',''),
'orderCount'=>StoreOrderModel::orderCount(),
]);
return $this->fetch();
@@ -80,6 +81,35 @@ class StoreOrder extends AuthController
]);
return JsonService::successlayui(StoreOrderModel::OrderList($where));
}
+
+ /*
+ * 发送货
+ * @param int $id
+ * @return html
+ * */
+ public function order_goods($id = 0)
+ {
+ $list = Db::name('express')->where('is_show',1)->order('sort DESC')->column('id,name');
+ $this->assign([
+ 'list'=>$list,
+ 'id'=>$id
+ ]);
+ return $this->fetch();
+ }
+ /*
+ * 删除订单
+ * */
+ public function del_order($ids=[])
+ {
+ if(!count($ids)) return JsonService::fail('请选择需要删除的订单');
+ if(StoreOrderModel::where('is_del',0)->where('id','in',$ids)->count()) return JsonService::fail('您选择的的订单存在用户未删除的订单,无法删除用户未删除的订单');
+ $res=StoreOrderModel::where('id','in',$ids)->update(['is_system_del'=>1]);
+ if($res)
+ return JsonService::successful('删除成功');
+ else
+ return JsonService::fail('删除失败');
+ }
+
public function orderchart(){
$where = Util::getMore([
['status',''],
@@ -183,10 +213,12 @@ class StoreOrder extends AuthController
StoreOrderStatus::setStatus($id,'order_edit','修改商品总价为:'.$data['total_price'].' 实际支付金额'.$data['pay_price']);
return Json::successful('修改成功!');
}
+
/**
- * 送货
+ * TODO 填写送货信息
* @param $id
- * send
+ * @return mixed|void
+ * @throws \think\exception\DbException
*/
public function delivery($id){
if(!$id) return $this->failed('数据不存在');
@@ -196,36 +228,72 @@ class StoreOrder extends AuthController
$f = array();
$f[] = Form::input('delivery_name','送货人姓名')->required('送货人姓名不能为空','required:true;');
$f[] = Form::input('delivery_id','送货人电话')->required('请输入正确电话号码','telephone');
- $form = Form::make_post_form('修改订单',$f,Url::build('updateDelivery',array('id'=>$id)),5);
+ $form = Form::make_post_form('修改订单',$f,Url::build('updateDelivery',array('id'=>$id)),7);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
else $this->failedNotice('订单状态错误');
}
- /**送货
+ /**
+ * TODO 送货信息提交
* @param Request $request
* @param $id
*/
- public function updateDelivery(Request $request, $id){
+ public function update_delivery(Request $request, $id){
$data = Util::postMore([
+ ['type',1],
'delivery_name',
'delivery_id',
+ ['sh_delivery_name',''],
+ ['sh_delivery_id',''],
],$request);
- $data['delivery_type'] = 'send';
- if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
- if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
- else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
- $data['status'] = 1;
- StoreOrderModel::edit($data,$id);
- HookService::afterListen('store_product_order_delivery',$data,$id,false,OrderBehavior::class);
- StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']);
+ switch ((int)$data['type']){
+ case 1:
+ //发货
+ $data['delivery_type'] = 'express';
+ if(!$data['delivery_name']) return Json::fail('请选择快递公司');
+ if(!$data['delivery_id']) return Json::fail('请输入快递单号');
+ $data['status'] = 1;
+ StoreOrderModel::edit($data,$id);
+ HookService::afterListen('store_product_order_delivery_goods',$data,$id,false,OrderBehavior::class);
+ StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']);
+ break;
+ case 2:
+ //送货
+ $data['delivery_type'] = 'send';
+ $data['delivery_name'] = $data['sh_delivery_name'];
+ $data['delivery_id'] = $data['sh_delivery_id'];
+ unset($data['sh_delivery_name'],$data['sh_delivery_id']);
+ if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
+ if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
+ else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
+ $data['status'] = 1;
+ StoreOrderModel::edit($data,$id);
+ HookService::afterListen('store_product_order_delivery',$data,$id,false,OrderBehavior::class);
+ StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']);
+ break;
+ case 3:
+ //虚拟发货
+ $data['delivery_type'] = 'fictitious';
+ $data['status'] = 1;
+ StoreOrderModel::edit($data,$id);
+ HookService::afterListen('store_product_order_delivery',$data,$id,false,OrderBehavior::class);
+ StoreOrderStatus::setStatus($id,'delivery_fictitious','已虚拟发货');
+ StoreOrderStatus::setStatus($id,'take_delivery','虚拟物品已收货');
+ break;
+ default:
+ return Json::fail('暂时不支持其他发货类型');
+ break;
+ }
return Json::successful('修改成功!');
}
+
/**
- * 发货
+ * TODO 填写发货信息
* @param $id
- * express
+ * @return mixed|void
+ * @throws \think\exception\DbException
*/
public function deliver_goods($id){
if(!$id) return $this->failed('数据不存在');
@@ -242,14 +310,15 @@ class StoreOrder extends AuthController
return $menus;
})->filterable(1);
$f[] = Form::input('delivery_id','快递单号');
- $form = Form::make_post_form('修改订单',$f,Url::build('updateDeliveryGoods',array('id'=>$id)),5);
+ $form = Form::make_post_form('修改订单',$f,Url::build('updateDeliveryGoods',array('id'=>$id)),7);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
else return $this->failedNotice('订单状态错误');
}
- /**发货保存
+ /**
+ * TODO 发货信息提交
* @param Request $request
* @param $id
*/
@@ -306,7 +375,7 @@ class StoreOrder extends AuthController
$f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1);
$f[] = Form::number('refund_price','退款金额',$product->getData('pay_price'))->precision(2)->min(0.01);
$f[] = Form::radio('type','状态',1)->options([['label'=>'直接退款','value'=>1],['label'=>'退款后,返回原状态','value'=>2]]);
- $form = Form::make_post_form('退款处理',$f,Url::build('updateRefundY',array('id'=>$id)),5);
+ $form = Form::make_post_form('退款处理',$f,Url::build('updateRefundY',array('id'=>$id)),7);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
@@ -373,7 +442,12 @@ class StoreOrder extends AuthController
if($resEdit){
$data['type'] = $type;
if($data['type'] == 1) StorePink::setRefundPink($id);
- HookService::afterListen('store_product_order_refund_y',$data,$id,false,OrderBehavior::class);
+ try{
+ HookService::afterListen('store_product_order_refund_y',$data,$id,false,OrderBehavior::class);
+ }catch (\Exception $e){
+ ModelBasic::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元');
ModelBasic::commitTrans();
return Json::successful('修改成功!');
@@ -444,7 +518,7 @@ class StoreOrder extends AuthController
});
$f[] = Form::input('delivery_id','快递单号',$product->getData('delivery_id'));
}
- $form = Form::make_post_form('配送信息',$f,Url::build('updateDistribution',array('id'=>$id)),5);
+ $form = Form::make_post_form('配送信息',$f,Url::build('updateDistribution',array('id'=>$id)),7);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
@@ -540,7 +614,7 @@ class StoreOrder extends AuthController
$f[] = Form::number('use_integral','使用的积分',$product->getData('use_integral'))->min(0)->disabled(1);
$f[] = Form::number('use_integrals','已退积分',$product->getData('back_integral'))->min(0)->disabled(1);
$f[] = Form::number('back_integral','可退积分',bcsub($product->getData('use_integral'),$product->getData('use_integral')))->min(0);
- $form = Form::make_post_form('退积分',$f,Url::build('updateIntegralBack',array('id'=>$id)));
+ $form = Form::make_post_form('退积分',$f,Url::build('updateIntegralBack',array('id'=>$id)),7);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}else{
diff --git a/application/admin/controller/record/StoreStatistics.php b/application/admin/controller/record/StoreStatistics.php
index 32e89e16..85ff0702 100644
--- a/application/admin/controller/record/StoreStatistics.php
+++ b/application/admin/controller/record/StoreStatistics.php
@@ -75,7 +75,7 @@ class StoreStatistics extends AuthController
];
$this->assign(StatisticsModel::systemTable($where));
- $this->assign(compact('where','trans','orderCount','orderPrice','orderDays','header','Statistic','ordinary','pink','recharge','data','seckill'));
+ $this->assign(compact('where','trans','orderCount','orderDays','header','Statistic','ordinary','pink','recharge','data','seckill'));
$this->assign('price',StatisticsModel::getOrderPrice($where));
return $this->fetch();
diff --git a/application/admin/controller/setting/SystemGroupData.php b/application/admin/controller/setting/SystemGroupData.php
index 931da8fd..b1c35b24 100644
--- a/application/admin/controller/setting/SystemGroupData.php
+++ b/application/admin/controller/setting/SystemGroupData.php
@@ -69,19 +69,19 @@ class SystemGroupData extends AuthController
$f[] = Form::input($value["title"],$value["name"])->type('textarea')->placeholder($value['param']);
break;
case 'radio':
- $f[] = Form::radio($value["title"],$value["name"],$info[0]["value"])->options($info);
+ $f[] = Form::radio($value["title"],$value["name"],isset($info[0]["value"]) ? $info[0]["value"] : '')->options($info);
break;
case 'checkbox':
- $f[] = Form::checkbox($value["title"],$value["name"],$info[0])->options($info);
+ $f[] = Form::checkbox($value["title"],$value["name"],isset($info[0]) ? $info[0] : '')->options($info);
break;
case 'select':
- $f[] = Form::select($value["title"],$value["name"],$info[0])->options($info)->multiple(false);
+ $f[] = Form::select($value["title"],$value["name"],isset($info[0]) ? $info[0] : '')->options($info)->multiple(false);
break;
case 'upload':
- $f[] = Form::frameImageOne($value["title"],$value["name"],Url::build('admin/widget.images/index',array('fodder'=>$value["title"],'big'=>1)))->icon('image');
+ $f[] = Form::formFrameImageOne($value["title"],$value["name"]);
break;
case 'uploads':
- $f[] = Form::frameImages($value["title"],$value["name"],Url::build('admin/widget.images/index',array('fodder'=>$value["title"],'big'=>1)))->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
+ $f[] = Form::formFrameImages($value["title"],$value["name"]);
break;
default:
$f[] = Form::input($value["title"],$value["name"]);
@@ -184,11 +184,11 @@ class SystemGroupData extends AuthController
}else{
$image = '';
}
- $f[] = Form::frameImageOne($value['title'],$value['name'],Url::build('admin/widget.images/index',array('fodder'=>$value['title'],'big'=>1)),$image)->icon('image');
+ $f[] = Form::formFrameImageOne($value['title'],$value['name'],$image);
break;
case 'uploads':
$images = !empty($fvalue) ? $fvalue:[];
- $f[] = Form::frameImages($value['title'],$value['name'],Url::build('admin/widget.images/index', array('fodder' => $value['title'],'big'=>1)),$images)->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
+ $f[] = Form::formFrameImages($value['title'],$value['name'],$images);
break;
case 'select':
$f[] = Form::select($value['title'],$value['name'],$fvalue)->setOptions($info);
@@ -221,7 +221,7 @@ class SystemGroupData extends AuthController
foreach ($params as $key => $param) {
foreach ($Fields['fields'] as $index => $field) {
if($key == $field["title"]){
- if(!$param)
+ if(trim($param) == '')
return Json::fail($field["name"]."不能为空!");
else{
$value[$key]["type"] = $field["type"];
@@ -252,14 +252,8 @@ class SystemGroupData extends AuthController
public function upload()
{
$res = Upload::image('file','common');
- $thumbPath = Upload::thumb($res->dir);
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,6);
-
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
- else
- return Json::fail($res->error);
+ if(!is_array($res)) return Json::fail($res);
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],6,$res['image_type'],$res['time']);
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
}
}
diff --git a/application/admin/controller/setting/SystemMenus.php b/application/admin/controller/setting/SystemMenus.php
index d15166cd..14385d4b 100644
--- a/application/admin/controller/setting/SystemMenus.php
+++ b/application/admin/controller/setting/SystemMenus.php
@@ -51,29 +51,48 @@ class SystemMenus extends AuthController
*/
public function create($cid = 0)
{
- $controller = '';
+ $field = [];
+ $field[] = Form::input('menu_name','按钮名称')->required('按钮名称必填');
+ $field[] = Form::select('pid','父级id',$cid)->setOptions(function(){
+ $list = (Util::sortListTier(MenusModel::all(function($m){
+ $m->order('sort DESC,id ASC');
+ })->toArray(),'顶级','pid','menu_name'));
+ $menus = [['value'=>0,'label'=>'顶级按钮']];
+ foreach ($list as $menu){
+ $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
+ }
+ return $menus;
+ })->filterable(1);
+ $field[] = Form::select('module','模块名')->options([['label'=>'总后台','value'=>'admin']]);
if($cid)$controller = MenusModel::where('id',$cid)->value('controller')?:'';
-// var_dump(MenusModel::order('pid ASC,sort DESC,id DESC')->all()->toArray());
- $field = [
- Form::input('menu_name','按钮名称')->required('按钮名称必填'),
- Form::select('pid','父级id',$cid)->setOptions(function(){
- $list = (Util::sortListTier(MenusModel::all(function($m){
- $m->order('sort DESC,id ASC');
- })->toArray(),'顶级','pid','menu_name'));
- $menus = [['value'=>0,'label'=>'顶级按钮']];
- foreach ($list as $menu){
- $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
- }
- return $menus;
- })->filterable(1),
- Form::select('module','模块名')->options([['label'=>'总后台','value'=>'admin']]),
- Form::input('controller','控制器名',$controller),
- Form::input('action','方法名'),
- Form::input('params','参数')->placeholder('举例:a/123/b/234'),
- Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic'),
- Form::number('sort','排序',0),
- Form::radio('is_show','是否菜单',0)->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']])
- ];
+ else $controller = '';
+ $field[] = Form::input('controller','控制器名',$controller);
+ if (!empty($controller))
+ {
+ $controller = preg_replace_callback('/([.]+([a-z]{1}))/i', function ($matches) {
+ return '\\' . strtoupper($matches[2]);
+ }, $controller);
+ if(class_exists('\app\admin\controller\\' . $controller))
+ {
+ $list = get_this_class_methods('\app\admin\controller\\' . $controller);
+
+ $field[] = Form::select('action','方法名')->setOptions(function()use($list){
+ $menus = [['value'=>0,'label'=>'默认函数']];
+ foreach ($list as $menu){
+ $menus[] = ['value'=>$menu,'label'=>$menu];
+ }
+ return $menus;
+ })->filterable(1);
+ }else{
+ $field[] = Form::input('action','方法名');
+ }
+ }else{
+ $field[] = Form::input('action','方法名');
+ }
+ $field[] = Form::input('params','参数')->placeholder('举例:a/123/b/234');
+ $field[] = Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic');
+ $field[] = Form::number('sort','排序',0);
+ $field[] = Form::radio('is_show','是否菜单',0)->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']]);
$form = Form::make_post_form('添加权限',$field,Url::build('save'),3);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
@@ -91,7 +110,7 @@ class SystemMenus extends AuthController
'menu_name',
'controller',
['module','admin'],
- 'action',
+ ['action',''],
'icon',
'params',
['pid',0],
@@ -112,27 +131,47 @@ class SystemMenus extends AuthController
public function edit($id)
{
$menu = MenusModel::get($id);
- if(!$menu) return Json::fail('数据不存在!');
- $field = [
- Form::input('menu_name','按钮名称',$menu['menu_name']),
- Form::select('pid','父级id',(string)$menu->getData('pid'))->setOptions(function()use($id){
- $list = (Util::sortListTier(MenusModel::all(function($m){
- $m->order('sort DESC,id ASC');
- })->toArray(),'顶级','pid','menu_name'));
- $menus = [['value'=>0,'label'=>'顶级按钮']];
- foreach ($list as $menu){
- $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
- }
- return $menus;
- })->filterable(1),
- Form::select('module','模块名',$menu['module'])->options([['label'=>'总后台','value'=>'admin']]),
- Form::input('controller','控制器名',$menu['controller']),
- Form::input('action','方法名',$menu['action']),
- Form::input('params','参数',MenusModel::paramStr($menu['params']))->placeholder('举例:a/123/b/234'),
- Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic'),
- Form::number('sort','排序',$menu['sort']),
- Form::radio('is_show','是否菜单',$menu['is_show'])->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']])
- ];
+ if (!$menu) return Json::fail('数据不存在!');
+ $field = array();
+ $field[] = Form::input('menu_name','按钮名称',$menu['menu_name']);
+ $field[] = Form::select('pid','父级id',(string)$menu->getData('pid'))->setOptions(function()use($id){
+ $list = (Util::sortListTier(MenusModel::all(function($m){
+ $m->order('sort DESC,id ASC');
+ })->toArray(),'顶级','pid','menu_name'));
+ $menus = [['value'=>0,'label'=>'顶级按钮']];
+ foreach ($list as $menu){
+ $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
+ }
+ return $menus;
+ })->filterable(1);
+ $field[] = Form::select('module','模块名',$menu['module'])->options([['label'=>'总后台','value'=>'admin']]);
+ $field[] = Form::input('controller','控制器名',$menu['controller']);
+ if (!empty($menu['controller']))
+ {
+ $controller = preg_replace_callback('/([.]+([a-z]{1}))/i', function ($matches) {
+ return '\\' . strtoupper($matches[2]);
+ }, $menu['controller']);
+ if(class_exists('\app\admin\controller\\' . $controller))
+ {
+ $list = get_this_class_methods('\app\admin\controller\\' . $controller);
+
+ $field[] = Form::select('action','方法名',(string)$menu->getData('action'))->setOptions(function()use($list){
+ $menus = [['value'=>0,'label'=>'默认函数']];
+ foreach ($list as $menu){
+ $menus[] = ['value'=>$menu,'label'=>$menu];
+ }
+ return $menus;
+ })->filterable(1);
+ }else{
+ $field[] = Form::input('action','方法名',$menu['action']);
+ }
+ }else{
+ $field[] = Form::input('action','方法名');
+ }
+ $field[] = Form::input('params','参数',MenusModel::paramStr($menu['params']))->placeholder('举例:a/123/b/234');
+ $field[] = Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic');
+ $field[] = Form::number('sort','排序',$menu['sort']);
+ $field[] = Form::radio('is_show','是否菜单',$menu['is_show'])->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']]);
$form = Form::make_post_form('添加权限',$field,Url::build('update',array('id'=>$id)),3);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
diff --git a/application/admin/controller/store/CopyTaobao.php b/application/admin/controller/store/CopyTaobao.php
new file mode 100644
index 00000000..596bf38e
--- /dev/null
+++ b/application/admin/controller/store/CopyTaobao.php
@@ -0,0 +1,885 @@
+ 微信:szktor
+ * Date: 2019-04-25
+ */
+namespace app\admin\controller\store;
+
+use service\HttpService;
+use service\UploadService;
+use think\exception\PDOException;
+use app\admin\controller\AuthController;
+use app\admin\model\system\SystemConfig;
+use traits\CurdControllerTrait;
+use service\JsonService;
+use service\UtilService;
+use app\admin\model\store\StoreCategory as CategoryModel;
+use app\admin\model\store\StoreProduct as ProductModel;
+use app\admin\model\system\SystemAttachment;
+use app\admin\model\system\SystemAttachmentCategory;
+
+/**
+ * 产品管理
+ * Class StoreProduct
+ * @package app\admin\controller\store
+ */
+class CopyTaobao extends AuthController
+{
+
+ use CurdControllerTrait;
+
+ protected $bindModel = ProductModel::class;
+ //错误信息
+ protected $errorInfo=true;
+ //产品默认字段
+ protected $productInfo=[
+ 'cate_id'=>'',
+ 'store_name' =>'',
+ 'store_info' => '',
+ 'unit_name' => '件',
+ 'price' => 0,
+ 'keyword' => '',
+ 'ficti' => 0,
+ 'ot_price' => 0,
+ 'give_integral' => 0,
+ 'postage' => 0,
+ 'cost' => 0,
+ 'image' => '',
+ 'slider_image' => '',
+ 'add_time' => 0,
+ 'stock' => 0,
+ 'description' => '',
+ 'soure_link' => ''
+ ];
+ //抓取网站主域名
+ protected $grabName=[
+ 'taobao',
+ '1688',
+ 'tmall',
+ 'jd'
+ ];
+ //远程下载附件图片分类名称
+ protected $AttachmentCategoryName='远程下载';
+ /**
+ * 显示资源
+ * @return html
+ */
+ public function index()
+ {
+ $list = CategoryModel::getTierList();
+ $menus=[];
+ foreach ($list as $menu){
+ $menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name'],'disabled'=>$menu['pid']== 0];//,'disabled'=>$menu['pid']== 0];
+ }
+ $this->assign('menus',$menus);
+ $this->assign('is_layui',1);
+ return $this->fetch();
+ }
+ /*
+ * 设置错误信息
+ * @param string $msg 错误信息
+ * */
+ public function setErrorInfo($msg='')
+ {
+ $this->errorInfo=$msg;
+ return false;
+ }
+ /*
+ * 设置字符串字符集
+ * @param string $str 需要设置字符集的字符串
+ * @return string
+ * */
+ public function Utf8String($str)
+ {
+ $encode=mb_detect_encoding($str, array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));
+ if(strtoupper($encode) != 'UTF-8') $str=mb_convert_encoding($str, 'utf-8',$encode);
+ return $str;
+ }
+ /**
+ * 获取资源,并解析出对应的商品参数
+ * @return json
+ */
+ public function get_request_contents()
+ {
+ list($link)=UtilService::postMore([
+ ['link','']
+ ],$this->request,true);
+ $url=$this->checkurl($link);
+ if($url===false) return JsonService::fail($this->errorInfo);
+ $this->errorInfo=true;
+ $html=$this->curl_Get($url,60);
+ if(!$html) return JsonService::fail('商品HTML信息获取失败');
+ $html=$this->Utf8String($html);
+ preg_match('/
([^<>]*)<\/title>/', $html, $title);
+ //商品标题
+ $this->productInfo['store_name'] = isset($title['1']) ? str_replace(['-淘宝网','-tmall.com天猫',' - 阿里巴巴',' ','-','【图片价格品牌报价】京东','京东','【行情报价价格评测】'],'',trim($title['1'])) :'';
+ $this->productInfo['store_info'] = $this->productInfo['store_name'];
+ try{
+ //获取url信息
+ $pathinfo=pathinfo($url);
+ if(!isset($pathinfo['dirname'])) return JsonService::fail('解析URL失败');
+ //提取域名
+ $parse_url=parse_url($pathinfo['dirname']);
+ if(!isset($parse_url['host'])) return JsonService::fail('获取域名失败');
+ //获取第一次.出现的位置
+ $strLeng=strpos($parse_url['host'],'.')+1;
+ //截取域名中的真实域名不带.com后的
+ $funsuffix=substr($parse_url['host'],$strLeng,strrpos($parse_url['host'],'.')-$strLeng);
+ if(!in_array($funsuffix,$this->grabName)) return JsonService::fail('您输入的地址不在复制范围内!');
+ //设拼接设置产品函数
+ $funName="setProductInfo".ucfirst($funsuffix);
+ //执行方法
+ if(method_exists($this,$funName))
+ $this->$funName($html);
+ else
+ return JsonService::fail('设置产品函数不存在');
+ if(!$this->productInfo['slider_image']) return JsonService::fail('未能获取到商品信息,请确保商品信息有效!');
+ return JsonService::successful($this->productInfo);
+ }catch (\Exception $e){
+ return JsonService::fail('系统错误',['line'=>$e->getLine(),'meass'=>$e->getMessage()]);
+ }
+ }
+
+ /*
+ * 淘宝设置产品
+ * @param string $html 网页内容
+ * */
+ public function setProductInfoTaobao($html)
+ {
+ //获取轮播图
+ $images = $this->getTaobaoImg($html);
+ $images = array_merge($images);
+ $this->productInfo['slider_image']=isset($images['gaoqing']) ? $images['gaoqing'] : (array)$images;
+ //获取产品详情请求链接
+ $link=$this->getTaobaoDesc($html);
+ //获取请求内容
+ $desc_json = HttpService::getRequest($link);
+ //转换字符集
+ $desc_json = $this->Utf8String($desc_json);
+ //截取掉多余字符
+ $this->productInfo['test']=$desc_json;
+ $desc_json = str_replace('var desc=\'','',$desc_json);
+ $desc_json = str_replace(["\n","\t","\r"],'',$desc_json);
+ $content = substr($desc_json,0,-2);
+ $this->productInfo['description']=$content;
+ //获取详情图
+ $description_images=$this->decodedesc($this->productInfo['description']);
+ $this->productInfo['description_images']=is_array($description_images) ? $description_images : [];
+ $this->productInfo['image']=is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
+ }
+
+ /*
+ * 天猫设置产品
+ * @param string $html 网页内容
+ * */
+ public function setProductInfoTmall($html)
+ {
+ //获取轮播图
+ $images = $this->getTianMaoImg($html);
+ $images = array_merge($images);
+ $this->productInfo['slider_image'] = $images;
+ $this->productInfo['image'] = is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
+ //获取产品详情请求链接
+ $link=$this->getTianMaoDesc($html);
+ //获取请求内容
+ $desc_json = HttpService::getRequest($link);
+ //转换字符集
+ $desc_json = $this->Utf8String($desc_json);
+ //截取掉多余字符
+ $desc_json = str_replace('var desc=\'','',$desc_json);
+ $desc_json = str_replace(["\n","\t","\r"],'',$desc_json);
+ $content = substr($desc_json,0,-2);
+ $this->productInfo['description']=$content;
+ //获取详情图
+ $description_images=$this->decodedesc($this->productInfo['description']);
+ $this->productInfo['description_images']=is_array($description_images) ? $description_images : [];
+ }
+ /*
+ * 1688设置产品
+ * @param string $html 网页内容
+ * */
+ public function setProductInfo1688($html)
+ {
+ //获取轮播图
+ $images = $this->get1688Img($html);
+ if(isset($images['gaoqing'])){
+ $images['gaoqing'] = array_merge($images['gaoqing']);
+ $this->productInfo['slider_image'] = $images['gaoqing'];
+ }else
+ $this->productInfo['slider_image'] = $images;
+ $this->productInfo['image'] = is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
+ //获取产品详情请求链接
+ $link = $this->get1688Desc($html);
+ //获取请求内容
+ $desc_json = HttpService::getRequest($link);
+ //转换字符集
+ $desc_json = $this->Utf8String($desc_json);
+ $this->productInfo['test']=$desc_json;
+ //截取掉多余字符
+ $desc_json = str_replace('var offer_details=','',$desc_json);
+ $desc_json = str_replace(["\n","\t","\r"],'',$desc_json);
+ $desc_json = substr($desc_json,0,-1);
+ $descArray = json_decode($desc_json,true);
+ if(!isset($descArray['content'])) $descArray['content'] = '';
+ $this->productInfo['description']=$descArray['content'];
+ //获取详情图
+ $description_images=$this->decodedesc($this->productInfo['description']);
+ $this->productInfo['description_images']=is_array($description_images) ? $description_images : [];
+ }
+ /*
+ * JD设置产品
+ * @param string $html 网页内容
+ * */
+ public function setProductInfoJd($html)
+ {
+ //获取产品详情请求链接
+ $desc_url = $this->getJdDesc($html);
+ //获取请求内容
+ $desc_json=HttpService::getRequest($desc_url);
+ //转换字符集
+ $desc_json = $this->Utf8String($desc_json);
+ //截取掉多余字符
+ if(substr($desc_json,0,8) == 'showdesc') $desc_json = str_replace('showdesc','',$desc_json);
+ $desc_json = str_replace('data-lazyload=','src=',$desc_json);
+ $descArray=json_decode($desc_json,true);
+ if(!$descArray) $descArray=['content'=>''];
+ //获取轮播图
+ $images=$this->getJdImg($html);
+ $images = array_merge($images);
+ $this->productInfo['slider_image']=$images;
+ $this->productInfo['image']=is_array($this->productInfo['slider_image']) ? $this->productInfo['slider_image'][0] : '';
+ $this->productInfo['description']=$descArray['content'];
+ //获取详情图
+ $description_images=$this->decodedesc($descArray['content']);
+ $this->productInfo['description_images']=is_array($description_images) ? $description_images : [];
+ }
+
+ /*
+ * 检查淘宝,天猫,1688的商品链接
+ * @return string
+ */
+ public function checkurl($link)
+ {
+ $link=strtolower($link);
+ if(!$link) return $this->setErrorInfo('请输入链接地址');
+ if(substr($link,0,4)!='http') return $this->setErrorInfo('链接地址必须以http开头');
+ $arrLine=explode('?',$link);
+ if(!count($arrLine)) return $this->setErrorInfo('链接地址有误(ERR:1001)');
+ if(!isset($arrLine[1])){
+ if(strpos($link,'1688')!==false && strpos($link,'offer')!==false) return trim($arrLine[0]);
+ else if(strpos($link,'item.jd')!==false) return trim($arrLine[0]);
+ else return $this->setErrorInfo('链接地址有误(ERR:1002)');
+ }
+ if(strpos($link,'1688')!==false && strpos($link,'offer')!==false) return trim($arrLine[0]);
+ if(strpos($link,'item.jd')!==false) return trim($arrLine[0]);
+ $arrLineValue = explode('&',$arrLine[1]);
+ if(!is_array($arrLineValue)) return $this->setErrorInfo('链接地址有误(ERR:1003)');
+ if(!strpos(trim($arrLine[0]),'item.htm')) $this->setErrorInfo('链接地址有误(ERR:1004)');
+ //链接参数
+ $lastStr='';
+ foreach ($arrLineValue as $k => $v){
+ if(substr(strtolower($v),0,3) == 'id='){
+ $lastStr = trim($v);
+ break;
+ }
+ }
+ if(!$lastStr) return $this->setErrorInfo('链接地址有误(ERR:1005)');
+ return trim($arrLine[0]) . '?' . $lastStr;
+ }
+
+ /*
+ * 保存图片保存产品信息
+ * */
+ public function save_product()
+ {
+ $data=UtilService::postMore([
+ ['cate_id',''],
+ ['store_name',''],
+ ['store_info',''],
+ ['keyword',''],
+ ['unit_name',''],
+ ['image',''],
+ ['slider_image',[]],
+ ['price',''],
+ ['ot_price',''],
+ ['give_integral',''],
+ ['postage',''],
+ ['sales',''],
+ ['ficti',''],
+ ['stock',''],
+ ['cost',''],
+ ['description_images',[]],
+ ['description',''],
+ ['is_show',0],
+ ['soure_link',''],
+ ]);
+ if(!$data['cate_id']) return JsonService::fail('请选择分类!');
+ if(!$data['store_name']) return JsonService::fail('请填写产品名称');
+ if(!$data['unit_name']) return JsonService::fail('请填写产品单位');
+ if(!$data['image']) return JsonService::fail('商品主图暂无,无法保存商品,您可选择其他链接进行复制产品');
+ if($data['price'] == '' || $data['price'] < 0) return JsonService::fail('请输入产品售价');
+ if($data['ot_price'] == '' || $data['ot_price'] < 0) return JsonService::fail('请输入产品市场价');
+ if($data['stock'] == '' || $data['stock'] < 0) return JsonService::fail('请输入库存');
+ //查询附件分类
+ $AttachmentCategory = SystemAttachmentCategory::where(['name' =>$this->AttachmentCategoryName])->find();
+ //不存在则创建
+ if(!$AttachmentCategory) $AttachmentCategory = SystemAttachmentCategory::set(['pid' =>'0','name' =>$this->AttachmentCategoryName,'enname'=>'']);
+ //生成附件目录
+ if(makePathToUrl('attach',3) == '') return JsonService::fail('无法创建文件夹,请检查您的上传目录权限:'.UPLOAD_PATH.'/attach/');
+ ini_set("max_execution_time", 600);
+ //开始图片下载处理
+ ProductModel::beginTrans();
+ try{
+ //放入主图
+ $images=[
+ ['w'=>305, 'h'=>305, 'line'=>$data['image'],'valuename'=>'image']
+ ];
+ //放入轮播图
+ foreach ($data['slider_image'] as $item){
+ $value=['w'=>640, 'h'=>640, 'line'=>$item,'valuename'=>'slider_image','isTwoArray'=>true];
+ array_push($images,$value);
+ }
+ //执行下载
+ $res=$this->uploadImage($images,false,0,$AttachmentCategory['id']);
+ if(!is_array($res)) return JsonService::fail($this->errorInfo ? $this->errorInfo : '保存图片失败');
+ if(isset($res['image'])) $data['image']=$res['image'];
+ if(isset($res['slider_image'])) $data['slider_image']=$res['slider_image'];
+ $data['slider_image']=count($data['slider_image']) ? json_encode($data['slider_image']) : '';
+ //替换并下载详情里面的图片默认下载全部图片
+ $data['description']=preg_replace('##is','',$data['description']);
+ $data['description']=$this->uploadImage($data['description_images'],$data['description'],1,$AttachmentCategory['id']);
+ unset($data['description_images']);
+ $data['add_time']=time();
+ $cate_id = explode(',',$data['cate_id']);
+ //产品存在
+ if($productInfo=ProductModel::where(['soure_link'=>$data['soure_link']])->find()){
+ $productInfo->description=$data['description'];
+ $productInfo->slider_image=$data['slider_image'];
+ $productInfo->image=$data['image'];
+ $productInfo->store_name=$data['store_name'];
+ $productInfo->save();
+ ProductModel::commitTrans();
+ return JsonService::successful('商品存在,信息已被更新成功');
+ }else {
+ //不存在时新增
+ if ($res = ProductModel::set($data)) {
+ foreach ($cate_id as $cid) {
+ \think\Db::name('store_product_cate')->insert(['product_id' => $res['id'], 'cate_id' => $cid, 'add_time' => time()]);
+ }
+ ProductModel::commitTrans();
+ return JsonService::successful('生成产品成功');
+ } else {
+ ProductModel::rollbackTrans();
+ return JsonService::fail('生成产品失败');
+ }
+ }
+ }catch (PDOException $e){
+ ProductModel::rollbackTrans();
+ return JsonService::fail('插入数据库错误',['line'=>$e->getLine(),'messag'=>$e->getMessage()]);
+ }catch (\Exception $e){
+ ProductModel::rollbackTrans();
+ return JsonService::fail('系统错误',['line'=>$e->getLine(),'messag'=>$e->getMessage()]);
+ }
+ }
+ /*
+ * 上传图片处理
+ * @param array $image 图片路径
+ * @param int $uploadType 上传方式 0=远程下载
+ * */
+ public function uploadImage(array $images=[],$html='',$uploadType=0,$AttachmentCategoryId=0)
+ {
+ $uploadImage=[];
+ $siteUrl = SystemConfig::getValue('site_url');
+ switch ($uploadType){
+ case 0:
+ foreach ($images as $item){
+ //下载图片文件
+ if($item['w'] && $item['h'])
+ $uploadValue=$this->downloadImage($item['line'],'',0,30,$item['w'],$item['h']);
+ else
+ $uploadValue=$this->downloadImage($item['line']);
+ //下载成功更新数据库
+ if(is_array($uploadValue)){
+ //TODO 拼接图片地址
+ if($uploadValue['image_type'] == 1) $imagePath=$siteUrl.$uploadValue['path'];
+ else $imagePath = $uploadValue['path'];
+ //写入数据库
+ if(!$uploadValue['is_exists'] && $AttachmentCategoryId) SystemAttachment::attachmentAdd($uploadValue['name'],$uploadValue['size'],$uploadValue['mime'],$imagePath,$imagePath,$AttachmentCategoryId,$uploadValue['image_type'],time(),1);
+ //组装数组
+ if(isset($item['isTwoArray']) && $item['isTwoArray'])
+ $uploadImage[$item['valuename']][]=$imagePath;
+ else
+ $uploadImage[$item['valuename']]=$imagePath;
+ }
+ }
+ break;
+ case 1:
+ preg_match_all('#]*>#i', $html, $match);
+ if(isset($match[1])){
+ foreach ($match[1] as $item){
+ if(is_int(strpos($item, 'http')))
+ $arcurl = $item;
+ else
+ $arcurl = 'http://'.ltrim($item,'\//');
+ $uploadValue=$this->downloadImage($arcurl);
+ //下载成功更新数据库
+ if(is_array($uploadValue)){
+ //TODO 拼接图片地址
+ if($uploadValue['image_type'] == 1) $imagePath=$siteUrl.$uploadValue['path'];
+ else $imagePath = $uploadValue['path'];
+ //写入数据库
+ if(!$uploadValue['is_exists'] && $AttachmentCategoryId) SystemAttachment::attachmentAdd($uploadValue['name'],$uploadValue['size'],$uploadValue['mime'],$imagePath,$imagePath,$AttachmentCategoryId,$uploadValue['image_type'],time(),1);
+ //替换图片
+ $html=str_replace($item,$imagePath,$html);
+ }else{
+ //替换掉没有下载下来的图片
+ $html=preg_replace('##i','',$html);
+ }
+ }
+ }
+ return $html;
+ break;
+ default:
+ return $this->setErrorInfo('上传方式错误');
+ break;
+ }
+ return $uploadImage;
+ }
+
+ //提取商品描述中的所有图片
+ public function decodedesc($desc = '')
+ {
+ $desc =trim($desc);
+ if(!$desc) return '';
+ preg_match_all('/
]*?src="([^"]*?)"[^>]*?>/i',$desc,$match);
+ if(!isset($match[1]) || count($match[1]) <= 0){
+ preg_match_all('/:url(([^"]*?));/i',$desc,$match);
+ if(!isset($match[1]) || count($match[1]) <= 0) return $desc;
+ }else{
+ preg_match_all('/:url(([^"]*?));/i',$desc,$newmatch);
+ if(isset($newmatch[1]) && count($newmatch[1]) > 0) $match[1] = array_merge($match[1],$newmatch[1]);
+ }
+ $match[1] = array_unique($match[1]); //去掉重复
+ foreach($match[1] as $k => &$v) {
+ $_tmp_img = str_replace([')','(',';'],'',$v);
+ $_tmp_img = strpos($_tmp_img,'http') ? $_tmp_img : 'http:' . $_tmp_img;
+ if(strpos($v,'?')) {
+ $_tarr = explode('?',$v);
+ $_tmp_img = trim($_tarr[0]);
+ }
+ $_urls = str_replace(['\'','"'],'',$_tmp_img);
+ if($this->_img_exists($_urls)) $v = $_urls;
+ }
+ return $match[1];
+ }
+ //获取京东商品组图
+ public function getJdImg($html = '')
+ {
+ //获取图片服务器网址
+ preg_match('/
]*>/', $html, $img);
+ if(!isset($img[3])) return '';
+ $info = parse_url(trim($img[3]));
+ if(!$info['host']) return '';
+ if(!$info['path']) return '';
+ $_tmparr = explode('/',trim($info['path']));
+ $url = 'http://' . $info['host'] . '/' . $_tmparr[1] . '/' . str_replace(['jfs',' '],'',trim($_tmparr[2]));
+ preg_match('/imageList:(.*?)"],/is', $html, $img);
+ if(!isset($img[1]))
+ {
+ return '';
+ }
+ $_arr = explode(',',$img[1]);
+ foreach ($_arr as $k => &$v){
+ $_str = $url . str_replace(['"','[',']',' '],'',trim($v));
+ if(strpos($_str,'?'))
+ {
+ $_tarr = explode('?',$_str);
+ $_str = trim($_tarr[0]);
+ }
+ if($this->_img_exists($_str))
+ {
+ $v = $_str;
+ }else{
+ unset($_arr[$k]);
+ }
+ }
+ return array_unique($_arr);
+ }
+ //获取京东商品描述
+ public function getJdDesc($html = '')
+ {
+ preg_match('/,(.*?)desc:([^<>]*)\',/i', $html, $descarr);
+ if(!isset($descarr[1]) && !isset($descarr[2])) return '';
+ $tmpArr = explode(',',$descarr[2]);
+ if(count($tmpArr) > 0)
+ {
+ $descarr[2] = trim($tmpArr[0]);
+ }
+ $replace_arr = ['\'','\',',' ',',','/*','*/'];
+ if(isset($descarr[2]))
+ {
+ $d_url = str_replace($replace_arr,'',$descarr[2]);
+ return $this->formatDescUrl(strpos($d_url,'http') ? $d_url : 'http:' . $d_url);
+ }
+ $d_url = str_replace($replace_arr,'',$descarr[1]);
+ $d_url = $this->formatDescUrl($d_url);
+ $d_url = rtrim(rtrim($d_url,"?"),"&");
+ return substr($d_url,0,4) == 'http' ? $d_url : 'http:' . $d_url;
+ }
+ //处理下京东商品描述网址
+ public function formatDescUrl($url = '')
+ {
+ if(!$url) return '';
+ $url = substr($url,0,4) == 'http' ? $url : 'http:' . $url;
+ if(!strpos($url,'&'))
+ {
+ $_arr = explode('?',$url);
+ if(!is_array($_arr) || count($_arr) <= 0) return $url;
+ return trim($_arr[0]);
+ }else{
+ $_arr = explode('&',$url);
+ }
+ if(!is_array($_arr) || count($_arr) <= 0) return $url;
+ unset($_arr[count($_arr)-1]);
+ $new_url = '';
+ foreach ($_arr as $k => $v) {
+ $new_url .= $v . '&';
+ }
+ return !$new_url ? $url : $new_url;
+ }
+
+ //获取1688商品组图
+ public function get1688Img($html = '')
+ {
+ preg_match('/(.*?)<\/ul>/is', $html, $img);
+ if(!isset($img[0]))
+ {
+ return '';
+ }
+ preg_match_all('/preview":"(.*?)\"\}\'>/is', $img[0], $arrb);
+ if(!isset($arrb[1]) || count($arrb[1]) <= 0)
+ {
+ return '';
+ }
+ $thumb = [];
+ $gaoqing = [];
+ $res = ['thumb' => '', 'gaoqing' => '']; //缩略图片和高清图片
+ foreach($arrb[1] as $k => $v)
+ {
+ $_str = str_replace(['","original":"'],'*',$v);
+ $_arr = explode('*',$_str);
+ if(is_array($_arr) && isset($_arr[0]) && isset($_arr[1]))
+ {
+ if(strpos($_arr[0],'?'))
+ {
+ $_tarr = explode('?',$_arr[0]);
+ $_arr[0] = trim($_tarr[0]);
+ }
+ if(strpos($_arr[1],'?'))
+ {
+ $_tarr = explode('?',$_arr[1]);
+ $_arr[1] = trim($_tarr[0]);
+ }
+ if($this->_img_exists($_arr[0])) $thumb[] = trim($_arr[0]);
+ if($this->_img_exists($_arr[1])) $gaoqing[] = trim($_arr[1]);
+ }
+ }
+ $res = ['thumb' => array_unique($thumb), 'gaoqing' => array_unique($gaoqing)]; //缩略图片和高清图片
+ return $res;
+ }
+ //获取1688商品描述
+ public function get1688Desc($html = '')
+ {
+ preg_match('/data-tfs-url="([^<>]*)data-enable="true"/', $html, $descarr);
+ if(!isset($descarr[1])) return '';
+ return str_replace(['"',' '],'',$descarr[1]);
+ }
+
+ //获取天猫商品组图
+ public function getTianMaoImg($html = '')
+ {
+ $pic_size = '430';
+ preg_match('/
]*id="J_ImgBooth"[^r]*rc=\"([^"]*)\"[^>]*>/', $html, $img);
+ if(isset($img[1]))
+ {
+ $_arr = explode('x',$img[1]);
+ $filename = $_arr[count($_arr)-1];
+ $pic_size = intval(substr($filename,0,3));
+ }
+ preg_match('||isU',$html, $match);
+ preg_match_all('/
&$v)
+ {
+ $tmp_v = trim($v);
+ $_arr = explode('x',$tmp_v);
+ $_fname = $_arr[count($_arr)-1];
+ $_size = intval(substr($_fname,0,3));
+ if(strpos($tmp_v,'://'))
+ {
+ $_arr = explode(':',$tmp_v);
+ $r_url = trim($_arr[1]);
+ }else{
+ $r_url = $tmp_v;
+ }
+ $str = str_replace($_size, $pic_size, $r_url);
+ if(strpos($str,'?'))
+ {
+ $_tarr = explode('?',$str);
+ $str = trim($_tarr[0]);
+ }
+ $_i_url = strpos($str,'http') ? $str : 'http:' . $str;
+ if($this->_img_exists($_i_url))
+ {
+ $v = $_i_url;
+ }else{
+ unset($images[1][$k]);
+ }
+ }
+ return array_unique($images[1]);
+ }
+ //获取天猫商品描述
+ public function getTianMaoDesc($html = '')
+ {
+ preg_match('/descUrl":"([^<>]*)","httpsDescUrl":"/', $html, $descarr);
+ if(!isset($descarr[1]))
+ {
+ preg_match('/httpsDescUrl":"([^<>]*)","fetchDcUrl/', $html, $descarr);
+ if(!isset($descarr[1])) return '';
+ }
+ return strpos($descarr[1],'http') ? $descarr[1] : 'http:' . $descarr[1];
+ }
+
+ //获取淘宝商品组图
+ public function getTaobaoImg($html = '')
+ {
+ preg_match('/auctionImages([^<>]*)"]/', $html, $imgarr);
+ if(!isset($imgarr[1])) return '';
+ $arr = explode(',', $imgarr[1]);
+ foreach($arr as $k => &$v)
+ {
+ $str = trim($v);
+ $str = str_replace(['"',' ','',':['], '', $str);
+ if(strpos($str,'?'))
+ {
+ $_tarr = explode('?',$str);
+ $str = trim($_tarr[0]);
+ }
+ $_i_url = strpos($str,'http') ? $str : 'http:' . $str;
+ if($this->_img_exists($_i_url))
+ {
+ $v = $_i_url;
+ }else{
+ unset($arr[$k]);
+ }
+ }
+ return array_unique($arr);
+ }
+ //获取淘宝商品描述
+ public function getTaobaoDesc($html = '')
+ {
+ preg_match('/descUrl([^<>]*)counterApi/', $html, $descarr);
+ if(!isset($descarr[1])) return '';
+ $arr = explode(':', $descarr[1]);
+ $url = [];
+ foreach($arr as $k => $v)
+ {
+ if(strpos($v,'//'))
+ {
+ $str = str_replace(['\'',',',' ','?',':'], '', $v);
+ $url[] = trim($str);
+ }
+ }
+ if($url)
+ {
+ return strpos($url[0],'http') ? $url[0] : 'http:' . $url[0];
+ }else{
+ return '';
+ }
+ }
+
+ /**
+ * GET 请求
+ * @param string $url
+ */
+ public function curl_Get($url = '',$time_out = 25)
+ {
+ if(!$url) return '';
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
+ if(stripos($url,"https://")!==FALSE)
+ {
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
+ }
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('user-agent:'.$_SERVER['HTTP_USER_AGENT']));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($ch, CURLOPT_TIMEOUT,$time_out);
+ $response = curl_exec($ch);
+ if($error=curl_error($ch)){
+ return false;
+ }
+ curl_close($ch);
+ return mb_convert_encoding($response, 'utf-8','GB2312');
+ }
+ //检测远程文件是否存在
+ public function _img_exists($url = '')
+ {
+ ini_set("max_execution_time", 0);
+ $str = @file_get_contents($url,0,null,0,1);
+ if(strlen($str) <= 0) return false;
+ if($str)
+ return true;
+ else
+ return false;
+ }
+ //TODO 下载图片
+ public function downloadImage($url = '', $name = '', $type = 0, $timeout = 30, $w = 0, $h = 0)
+ {
+ if(!strlen(trim($url))) return '';
+ if(!strlen(trim($name)))
+ {
+ //TODO 获取要下载的文件名称
+ $downloadImageInfo = $this->getImageExtname($url);
+ $name = $downloadImageInfo['file_name'];
+ if(!strlen(trim($name))) return '';
+ }
+ //TODO 获取远程文件所采用的方法
+ if($type){
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //TODO 跳过证书检查
+ if(stripos($url,"https://") !== FALSE) curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //TODO 从证书中检查SSL加密算法是否存在
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('user-agent:'.$_SERVER['HTTP_USER_AGENT']));
+ if(ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);//TODO 是否采集301、302之后的页面
+ $content = curl_exec($ch);
+ curl_close($ch);
+ }else{
+ try{
+ ob_start();
+ readfile($url);
+ $content = ob_get_contents();
+ ob_end_clean();
+ }catch (\Exception $e){
+ return $e->getMessage();
+ }
+ }
+ $size = strlen(trim($content));
+ if(!$content || $size <= 2) return '图片流获取失败';
+ $date_dir = date('Y') . DS . date('m') . DS . date('d');
+ $imageInfo = UploadService::imageStream($name, $content, 'attach' . DS . $date_dir. DS);
+ if(!is_array($imageInfo)) return $imageInfo;
+ $date['path'] = $imageInfo['dir'];
+ $date['name'] = $imageInfo['name'];
+ $date['size'] = $imageInfo['size'];
+ $date['mime'] = $imageInfo['type'];
+ $date['image_type'] = $imageInfo['image_type'];
+ $date['is_exists'] = false;
+ return $date;
+ }
+ //获取即将要下载的图片扩展名
+ public function getImageExtname($url = '', $ex = 'jpg')
+ {
+ $_empty = ['file_name' => '', 'ext_name' => $ex];
+ if(!$url) return $_empty;
+ if(strpos($url,'?'))
+ {
+ $_tarr = explode('?',$url);
+ $url = trim($_tarr[0]);
+ }
+ $arr = explode('.',$url);
+ if(!is_array($arr) || count($arr) <= 1) return $_empty;
+ $ext_name = trim($arr[count($arr)-1]);
+ $ext_name = !$ext_name ? $ex : $ext_name;
+ return ['file_name' => md5($url) . '.' . $ext_name, 'ext_name' => $ext_name];
+ }
+ /*
+ $filepath = 绝对路径,末尾有斜杠 /
+ $name = 图片文件名
+ $maxwidth 定义生成图片的最大宽度(单位:像素)
+ $maxheight 生成图片的最大高度(单位:像素)
+ $filetype 最终生成的图片类型(.jpg/.png/.gif)
+ */
+ public function resizeImage($filepath = '',$name = '', $maxwidth = 0,$maxheight = 0)
+ {
+ $pic_file = $filepath . $name; //图片文件
+ $img_info = getimagesize($pic_file); //索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,
+ if($img_info[2] == 1)
+ {
+ $im = imagecreatefromgif($pic_file); //打开图片
+ $filetype = '.gif';
+ }elseif($img_info[2] == 2){
+ $im = imagecreatefromjpeg($pic_file); //打开图片
+ $filetype = '.jpg';
+ }elseif($img_info[2] == 3){
+ $im = imagecreatefrompng($pic_file); //打开图片
+ $filetype = '.png';
+ }else{
+ return ['path' => $filepath, 'file' => $name, 'mime' => ''];
+ }
+ $file_name = md5('_tmp_' . microtime() . '_' .rand(0,10)) . $filetype;
+ $pic_width = imagesx($im);
+ $pic_height = imagesy($im);
+ $resizewidth_tag = false;
+ $resizeheight_tag = false;
+ if(($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight))
+ {
+ if($maxwidth && $pic_width>$maxwidth)
+ {
+ $widthratio = $maxwidth/$pic_width;
+ $resizewidth_tag = true;
+ }
+ if($maxheight && $pic_height>$maxheight)
+ {
+ $heightratio = $maxheight/$pic_height;
+ $resizeheight_tag = true;
+ }
+ if($resizewidth_tag && $resizeheight_tag)
+ {
+ if($widthratio<$heightratio)
+ $ratio = $widthratio;
+ else
+ $ratio = $heightratio;
+ }
+ if($resizewidth_tag && !$resizeheight_tag)
+ $ratio = $widthratio;
+ if($resizeheight_tag && !$resizewidth_tag)
+ $ratio = $heightratio;
+ $newwidth = $pic_width * $ratio;
+ $newheight = $pic_height * $ratio;
+ if(function_exists("imagecopyresampled"))
+ {
+ $newim = imagecreatetruecolor($newwidth,$newheight);
+ imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
+ }else{
+ $newim = imagecreate($newwidth,$newheight);
+ imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);
+ }
+ if($filetype == '.png')
+ {
+ imagepng($newim,$filepath . $file_name);
+ }else if($filetype == '.gif'){
+ imagegif($newim,$filepath . $file_name);
+ }else{
+ imagejpeg($newim,$filepath . $file_name);
+ }
+ imagedestroy($newim);
+ }else{
+ if($filetype == '.png')
+ {
+ imagepng($im,$filepath . $file_name);
+ }else if($filetype == '.gif'){
+ imagegif($im,$filepath . $file_name);
+ }else{
+ imagejpeg($im,$filepath . $file_name);
+ }
+ imagedestroy($im);
+ }
+ @unlink($pic_file);
+ return ['path' => $filepath, 'file' => $file_name, 'mime' => $img_info['mime']];
+ }
+}
diff --git a/application/admin/controller/store/StoreCategory.php b/application/admin/controller/store/StoreCategory.php
index 782f7eb7..a7a29b69 100644
--- a/application/admin/controller/store/StoreCategory.php
+++ b/application/admin/controller/store/StoreCategory.php
@@ -89,7 +89,7 @@ class StoreCategory extends AuthController
return $menus;
})->filterable(1),
Form::input('cate_name','分类名称'),
- Form::frameImageOne('pic','分类图标',Url::build('admin/widget.images/index',array('fodder'=>'pic')))->icon('image'),
+ Form::formFrameImageOne('pic','分类图标'),
Form::number('sort','排序'),
Form::radio('is_show','状态',1)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
];
@@ -106,17 +106,14 @@ class StoreCategory extends AuthController
public function upload()
{
$res = Upload::image('file','store/category'.date('Ymd'));
- $thumbPath = Upload::thumb($res->dir);
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,1);
-
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
- else
- return Json::fail($res->error);
+ if(is_array($res)){
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
+ }else
+ return Json::fail($res);
}
+
/**
* 保存新建的资源
*
@@ -163,7 +160,9 @@ class StoreCategory extends AuthController
return $menus;
})->filterable(1),
Form::input('cate_name','分类名称',$c->getData('cate_name')),
- Form::frameImageOne('pic','分类图标',Url::build('admin/widget.images/index',array('fodder'=>'pic')),$c->getData('pic'))->icon('image'),
+// Form::frameImageOne('pic','分类图标',Url::build('admin/widget.images/index',array('fodder'=>'pic')),$c->getData('pic'))->icon('image')->width('100%')->height('500px'),
+ Form::formFrameImageOne('pic','分类图标',$c->getData('pic')),
+
Form::number('sort','排序',$c->getData('sort')),
Form::radio('is_show','状态',$c->getData('is_show'))->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
];
diff --git a/application/admin/controller/store/StoreProduct.php b/application/admin/controller/store/StoreProduct.php
index c120501a..9e3564d4 100644
--- a/application/admin/controller/store/StoreProduct.php
+++ b/application/admin/controller/store/StoreProduct.php
@@ -145,8 +145,8 @@ class StoreProduct extends AuthController
Form::input('store_info','产品简介')->type('textarea'),
Form::input('keyword','产品关键字')->placeholder('多个用英文状态下的逗号隔开'),
Form::input('unit_name','产品单位','件'),
- Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')))->icon('image')->width('100%')->height('500px'),
- Form::frameImages('slider_image','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0),
+ Form::formFrameImageOne('image','产品主图片(305*305px)'),
+ Form::formFrameImages('slider_image','产品轮播图(640*640px)'),
Form::number('price','产品售价')->min(0)->col(8),
Form::number('ot_price','产品市场价')->min(0)->col(8),
Form::number('give_integral','赠送积分')->min(0)->precision(0)->col(8),
@@ -175,16 +175,12 @@ class StoreProduct extends AuthController
public function upload()
{
$res = Upload::image('file','store/product/'.date('Ymd'));
- $thumbPath = Upload::thumb($res->dir);
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,1);
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
+ if(is_array($res))
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
else
- return Json::fail($res->error);
+ return Json::fail($res);
}
-
/**
* 保存新建的资源
*
@@ -275,8 +271,10 @@ class StoreProduct extends AuthController
Form::input('store_info','产品简介',$product->getData('store_info'))->type('textarea'),
Form::input('keyword','产品关键字',$product->getData('keyword'))->placeholder('多个用英文状态下的逗号隔开'),
Form::input('unit_name','产品单位',$product->getData('unit_name')),
- Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px'),
- Form::frameImages('slider_image','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'slider_image')),json_decode($product->getData('slider_image'),1) ? : [])->maxLength(5)->icon('images')->width('100%')->height('500px'),
+// Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('80%')->height('500px'),
+ Form::formFrameImageOne('image','产品主图片(305*305px)',$product->getData('image')),
+// Form::frameImages('slider_image','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'slider_image')),json_decode($product->getData('slider_image'),1) ? : [])->maxLength(5)->icon('images')->width('945px')->height('600px'),
+ Form::formFrameImages('slider_image','产品轮播图(640*640px)',json_decode($product->getData('slider_image'),1) ? : []),
Form::number('price','产品售价',$product->getData('price'))->min(0)->precision(2)->col(8),
Form::number('ot_price','产品市场价',$product->getData('ot_price'))->min(0)->col(8),
Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(8),
@@ -339,7 +337,7 @@ class StoreProduct extends AuthController
if(!$data['store_name']) return Json::fail('请输入产品名称');
if(count($data['image'])<1) return Json::fail('请上传产品图片');
if(count($data['slider_image'])<1) return Json::fail('请上传产品轮播图');
- if(count($data['slider_image'])>5) return Json::fail('轮播图最多5张图');
+ // if(count($data['slider_image'])>8) return Json::fail('轮播图最多5张图');
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
diff --git a/application/admin/controller/system/SystemAttachment.php b/application/admin/controller/system/SystemAttachment.php
index cae82ff1..57296bc1 100755
--- a/application/admin/controller/system/SystemAttachment.php
+++ b/application/admin/controller/system/SystemAttachment.php
@@ -4,6 +4,7 @@ namespace app\admin\controller\system;
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
use app\admin\controller\AuthController;
+use app\core\util\SystemConfigService;
use service\UploadService as Upload;
/**
* 附件管理控制器
@@ -14,25 +15,27 @@ use service\UploadService as Upload;
class SystemAttachment extends AuthController
{
+
/**
- * 编辑器上传图片
- * @return \think\response\Json
+ * TODO 编辑器上传图片
*/
public function upload()
{
$res = Upload::image('upfile','editor/'.date('Ymd'));
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- $thumbPath = Upload::thumb($res->dir);
- SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,0);
- $info = array(
- "originalName" => $fileInfo['name'],
- "name" => $res->fileInfo->getSaveName(),
- "url" => '.'.$res->dir,
- "size" => $fileInfo['size'],
- "type" => $fileInfo['type'],
- "state" => "SUCCESS"
- );
+ if(is_array($res)){
+ SystemAttachmentModel::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
+ $info["originalName"] = $res['name'];
+ $info["name"] = $res['name'];
+ $info["url"] = $res['dir'];
+ $info["size"] = $res['size'];
+ $info["type"] = $res['type'];
+ $info["state"] = "SUCCESS";
+ if(strstr($info['url'],'http') === false) $info['url'] = SystemConfigService::get('site_url').str_replace('\\','/',$res['dir']);
+ }else
+ $info = array(
+ "msg" => $res,
+ "state" => "ERROR"
+ );
echo json_encode($info);
}
}
diff --git a/application/admin/controller/system/SystemDatabackup.php b/application/admin/controller/system/SystemDatabackup.php
index 36ba5f71..023f7740 100644
--- a/application/admin/controller/system/SystemDatabackup.php
+++ b/application/admin/controller/system/SystemDatabackup.php
@@ -1,5 +1,6 @@
'.'.PUBILC_PATH.'backup/data/',
//数据库备份路径
diff --git a/application/admin/controller/ump/StoreSeckill.php b/application/admin/controller/ump/StoreSeckill.php
index 46158f99..cfacb66d 100644
--- a/application/admin/controller/ump/StoreSeckill.php
+++ b/application/admin/controller/ump/StoreSeckill.php
@@ -79,8 +79,8 @@ class StoreSeckill extends AuthController
$f[] = Form::input('info','秒杀活动简介')->type('textarea');
$f[] = Form::input('unit_name','单位')->placeholder('个、位');
$f[] = Form::dateTimeRange('section_time','活动时间');
- $f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')))->icon('image');
- $f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'images')))->maxLength(5)->icon('images');
+ $f[] = Form::formFrameImageOne('image','产品主图片(305*305px)');
+ $f[] = Form::formFrameImages('images','产品轮播图(640*640px)');
$f[] = Form::number('price','秒杀价')->min(0)->col(12);
$f[] = Form::number('ot_price','原价')->min(0)->col(12);
$f[] = Form::number('cost','成本价')->min(0)->col(12);
@@ -141,7 +141,6 @@ class StoreSeckill extends AuthController
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品原售价');
if($data['cost'] == '' || $data['cost'] < 0) return Json::fail('请输入产品成本价');
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
- $data['add_time'] = time();
if($data['num']<1) return Json::fail('请输入单次秒杀个数');
if($id){
$product = StoreSeckillModel::get($id);
@@ -149,6 +148,7 @@ class StoreSeckill extends AuthController
StoreSeckillModel::edit($data,$id);
return Json::successful('编辑成功!');
}else{
+ $data['add_time'] = time();
StoreSeckillModel::set($data);
return Json::successful('添加成功!');
}
@@ -168,8 +168,8 @@ class StoreSeckill extends AuthController
$f[] = Form::input('info','秒杀活动简介',$product->getData('store_info'))->type('textarea');
$f[] = Form::input('unit_name','单位',$product->getData('unit_name'))->placeholder('个、位');
$f[] = Form::dateTimeRange('section_time','活动时间');
- $f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image');
- $f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('slider_image')))->maxLength(5)->icon('images');
+ $f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px');
+ $f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
$f[] = Form::number('price','秒杀价')->min(0)->col(12);
$f[] = Form::number('ot_price','原价',$product->getData('price'))->min(0)->col(12);
$f[] = Form::number('cost','成本价',$product->getData('cost'))->min(0)->col(12);
@@ -193,16 +193,12 @@ class StoreSeckill extends AuthController
*/
public function upload()
{
- $res = Upload::image('file','store/seckill/'.date('Ymd'));
- $thumbPath = Upload::thumb($res->dir);
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- SystemAttachment::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,4);
-
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
- else
- return Json::fail($res->error);
+ $res = Upload::image('file','store/product/'.date('Ymd'));
+ if(is_array($res)){
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],4,$res['image_type'],$res['time']);
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
+ }else
+ return Json::fail($res);
}
@@ -223,8 +219,8 @@ class StoreSeckill extends AuthController
$f[] = Form::input('info','秒杀活动简介',$product->getData('info'))->type('textarea');
$f[] = Form::input('unit_name','单位',$product->getData('unit_name'))->placeholder('个、位');
$f[] = Form::dateTimeRange('section_time','活动时间',$product->getData('start_time'),$product->getData('stop_time'));
- $f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image');
- $f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('images')))->maxLength(5)->icon('images');
+ $f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::build('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px');
+ $f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
$f[] = Form::number('price','秒杀价',$product->getData('price'))->min(0)->col(12);
$f[] = Form::number('ot_price','原价',$product->getData('ot_price'))->min(0)->col(12);
$f[] = Form::number('cost','成本价',$product->getData('cost'))->min(0)->col(12);
@@ -251,6 +247,9 @@ class StoreSeckill extends AuthController
public function delete($id)
{
if(!$id) return $this->failed('数据不存在');
+ $product = StoreSeckillModel::get($id);
+ if(!$product) return Json::fail('数据不存在!');
+ if($product['is_del']) return Json::fail('已删除!');
$data['is_del'] = 1;
if(!StoreSeckillModel::edit($data,$id))
return Json::fail(StoreSeckillModel::getErrorInfo('删除失败,请稍候再试!'));
diff --git a/application/admin/controller/user/User.php b/application/admin/controller/user/User.php
index d750733a..2c19de81 100644
--- a/application/admin/controller/user/User.php
+++ b/application/admin/controller/user/User.php
@@ -5,8 +5,12 @@
* @day: 2017/11/11
*/
namespace app\admin\controller\user;
+
use app\admin\controller\AuthController;
+use app\admin\model\system\SystemUserLevel;
use service\FormBuilder as Form;
+use service\JsonService;
+use think\Db;
use traits\CurdControllerTrait;
use service\UtilService as Util;
use service\JsonService as Json;
@@ -16,11 +20,13 @@ use app\admin\model\user\User as UserModel;
use app\admin\model\user\UserBill AS UserBillAdmin;
use basic\ModelBasic;
use service\HookService;
+use app\admin\model\user\UserLevel;
use behavior\user\UserBehavior;
use app\admin\model\store\StoreVisit;
use app\admin\model\wechat\WechatMessage;
use app\admin\model\order\StoreOrder;
use app\admin\model\store\StoreCouponUser;
+
/**
* 用户管理控制器
* Class User
@@ -36,8 +42,106 @@ class User extends AuthController
*/
public function index(){
$this->assign('count_user',UserModel::getcount());
+ $this->assign('level_list',SystemUserLevel::where(['is_show'=>1,'is_del'=>0])->field(['id','name'])->select());
return $this->fetch();
}
+
+ /*
+ * 赠送会员等级
+ * @paran int $uid
+ * */
+ public function give_level($uid=0)
+ {
+ if(!$uid) return $this->failed('缺少参数');
+ $level=\app\core\model\user\UserLevel::getUserLevel($uid);
+ //获取当前会员等级
+ if($level===false)
+ $grade=0;
+ else
+ $grade=\app\core\model\user\UserLevel::getUserLevelInfo($level,'grade');
+ //查询高于当前会员的所有会员等级
+ $systemLevelList=SystemUserLevel::where('grade','>',$grade)->where(['is_show'=>1,'is_del'=>0])->field(['name','id'])->select();
+ $field[]=Form::select('level_id','会员等级')->setOptions(function() use($systemLevelList) {
+ $menus=[];
+ foreach ($systemLevelList as $menu){
+ $menus[] = ['value'=>$menu['id'],'label'=>$menu['name']];
+ }
+ return $menus;
+ })->filterable(1);
+ $form = Form::make_post_form('赠送会员',$field,Url::build('save_give_level',['uid'=>$uid]),2);
+ $this->assign(compact('form'));
+ return $this->fetch('public/form-builder');
+ }
+
+ /*
+ * 赠送会员等级
+ * @paran int $uid
+ * @return json
+ * */
+ public function save_give_level($uid=0)
+ {
+ if(!$uid) return JsonService::fail('缺少参数');
+ list($level_id)=Util::postMore([
+ ['level_id',0],
+ ],$this->request,true);
+ //查询当前选择的会员等级
+ $systemLevel=SystemUserLevel::where(['is_show'=>1,'is_del'=>0,'id'=>$level_id])->find();
+ if(!$systemLevel) return JsonService::fail('您选择赠送的会员等级不存在!');
+ //检查是否拥有此会员等级
+ $level=UserLevel::where(['uid'=>$uid,'level_id'=>$level_id,'is_del'=>0])->field('valid_time,is_forever')->find();
+ if($level) if(!$level['is_forever'] && time() < $level['valid_time']) return JsonService::fail('此用户已有该会员等级,无法再次赠送');
+ //设置会员过期时间
+ $add_valid_time=(int)$systemLevel->valid_date*86400;
+ UserModel::commitTrans();
+ try{
+ //保存会员信息
+ $res=UserLevel::set([
+ 'is_forever'=>$systemLevel->is_forever,
+ 'status'=>1,
+ 'is_del'=>0,
+ 'grade'=>$systemLevel->grade,
+ 'uid'=>$uid,
+ 'add_time'=>time(),
+ 'level_id'=>$level_id,
+ 'discount'=>$systemLevel->discount,
+ 'valid_time'=>$systemLevel->discount ? $add_valid_time : 0,
+ 'mark'=>'尊敬的用户【'.UserModel::where('uid',$uid)->value('nickname').'】在'.date('Y-m-d H:i:s',time()).'赠送会员等级成为'.$systemLevel['name'].'会员',
+ ]);
+ //提取等级任务并记录完成情况
+ $levelIds=[$level_id];
+ $lowGradeLevelIds=SystemUserLevel::where('grade','<',$systemLevel->grade)->where(['is_show'=>1,'is_del'=>0])->column('id');
+ if(count($lowGradeLevelIds)) $levelIds=array_merge($levelIds,$lowGradeLevelIds);
+ $taskIds=Db::name('system_user_task')->where('level_id','in',$levelIds)->column('id');
+ $inserValue=[];
+ foreach ($taskIds as $id){
+ $inserValue[]=['uid'=>$uid,'task_id'=>$id,'status'=>1,'add_time'=>time()];
+ }
+ $res=$res && Db::name('user_task_finish')->insertAll($inserValue);
+ if($res){
+ UserModel::commitTrans();
+ return JsonService::successful('赠送成功');
+ }else{
+ UserModel::rollbackTrans();
+ return JsonService::successful('赠送失败');
+ }
+ }catch (\Exception $e){
+ UserModel::rollbackTrans();
+ return JsonService::fail('赠送失败');
+ }
+ }
+ /*
+ * 清除会员等级
+ * @param int $uid
+ * @return json
+ * */
+ public function del_level($uid=0)
+ {
+ if(!$uid) return JsonService::fail('缺少参数');
+ if(UserLevel::cleanUpLevel($uid))
+ return JsonService::successful('清除成功');
+ else
+ return JsonService::fail('清除失败');
+ }
/**
* 修改user表状态
*
@@ -77,6 +181,8 @@ class User extends AuthController
['user_time_type',''],
['user_time',''],
['sex',''],
+ ['level_id',''],
+ ['birthday',''],
]);
return Json::successlayui(UserModel::getUserList($where));
}
@@ -92,23 +198,111 @@ class User extends AuthController
if(!$user) return Json::fail('数据不存在!');
$f = array();
$f[] = Form::input('uid','用户编号',$user->getData('uid'))->disabled(1);
- $f[] = Form::input('nickname','用户姓名',$user->getData('nickname'));
+ $f[] = Form::input('real_name','真实姓名',$user->getData('real_name'));
+ $f[] = Form::date('birthday','生日',$user->getData('birthday') ? date('Y-m-d',$user->getData('birthday')) : 0);
+ $f[] = Form::input('card_id','身份证号',$user->getData('card_id'));
+ $f[] = Form::textarea('mark','用户备注',$user->getData('mark'));
+ $f[] = Form::radio('is_promoter','推广员',$user->getData('is_promoter'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
+ $f[] = Form::radio('status','状态',$user->getData('status'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'锁定']]);
+ $form = Form::make_post_form('添加用户通知',$f,Url::build('update',array('uid'=>$uid)),5);
+ $this->assign(compact('form'));
+ return $this->fetch('public/form-builder');
+ }
+
+ public function edit_other($uid)
+ {
+ if(!$uid) return $this->failed('数据不存在');
+ $user = UserModel::get($uid);
+ if(!$user) return Json::fail('数据不存在!');
+ $f = array();
$f[] = Form::radio('money_status','修改余额',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
$f[] = Form::number('money','余额')->min(0);
$f[] = Form::radio('integration_status','修改积分',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
$f[] = Form::number('integration','积分')->min(0);
- $f[] = Form::radio('status','状态',$user->getData('status'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'锁定']]);
- $f[] = Form::radio('is_promoter','推广员',$user->getData('is_promoter'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
- $form = Form::make_post_form('添加用户通知',$f,Url::build('update',array('id'=>$uid)),5);
+ $form = Form::make_post_form('修改其他',$f,Url::build('update_other',array('uid'=>$uid)),5);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
+ public function update_other($uid=0)
+ {
+ $data = Util::postMore([
+ ['money_status',0],
+ ['money',0],
+ ['integration_status',0],
+ ['integration',0],
+ ],$this->request);
+ if(!$uid) return $this->failed('数据不存在');
+ $user = UserModel::get($uid);
+ if(!$user) return Json::fail('数据不存在!');
+ ModelBasic::beginTrans();
+ $res1 = false;
+ $res2 = false;
+ $edit = array();
+ if($data['money_status'] && $data['money']){//余额增加或者减少
+ if($data['money_status'] == 1){//增加
+ $edit['now_money'] = bcadd($user['now_money'],$data['money'],2);
+ $res1 = UserBillAdmin::income('系统增加余额',$user['uid'],'now_money','system_add',$data['money'],$this->adminId,$edit['now_money'],'系统增加了'.floatval($data['money']).'余额');
+ try{
+ HookService::listen('admin_add_money',$user,$data['money'],false,UserBehavior::class);
+ }catch (\Exception $e){
+ ModelBasic::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ }else if($data['money_status'] == 2){//减少
+ $edit['now_money'] = bcsub($user['now_money'],$data['money'],2);
+ $res1 = UserBillAdmin::expend('系统减少余额',$user['uid'],'now_money','system_sub',$data['money'],$this->adminId,$edit['now_money'],'系统扣除了'.floatval($data['money']).'余额');
+ try{
+ HookService::listen('admin_sub_money',$user,$data['money'],false,UserBehavior::class);
+ }catch (\Exception $e){
+ ModelBasic::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ }
+ }else{
+ $res1 = true;
+ }
+ if($data['integration_status'] && $data['integration']){//积分增加或者减少
+ if($data['integration_status'] == 1){//增加
+ $edit['integral'] = bcadd($user['integral'],$data['integration'],2);
+ $res2 = UserBillAdmin::income('系统增加积分',$user['uid'],'integral','system_add',$data['integration'],$this->adminId,$edit['integral'],'系统增加了'.floatval($data['integration']).'积分');
+ try{
+ HookService::listen('admin_add_integral',$user,$data['integration'],false,UserBehavior::class);
+ }catch (\Exception $e){
+ ModelBasic::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ }else if($data['integration_status'] == 2){//减少
+ $edit['integral'] = bcsub($user['integral'],$data['integration'],2);
+ $res2 = UserBillAdmin::expend('系统减少积分',$user['uid'],'integral','system_sub',$data['integration'],$this->adminId,$edit['integral'],'系统扣除了'.floatval($data['integration']).'积分');
+ try{
+ HookService::listen('admin_sub_integral',$user,$data['integration'],false,UserBehavior::class);
+ }catch (\Exception $e){
+ ModelBasic::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ }
+ }else{
+ $res2 = true;
+ }
+ if($edit) $res3 = UserModel::edit($edit,$uid);
+ else $res3 = true;
+ if($res1 && $res2 && $res3) $res =true;
+ else $res = false;
+ ModelBasic::checkTrans($res);
+ if($res) return Json::successful('修改成功!');
+ else return Json::fail('修改失败');
+ }
+
public function update(Request $request, $uid)
{
$data = Util::postMore([
['money_status',0],
['is_promoter',1],
+ ['real_name',''],
+ ['card_id',''],
+ ['birthday',''],
+ ['mark',''],
['money',0],
['integration_status',0],
['integration',0],
@@ -117,6 +311,8 @@ class User extends AuthController
if(!$uid) return $this->failed('数据不存在');
$user = UserModel::get($uid);
if(!$user) return Json::fail('数据不存在!');
+ $data['birthday'] = strtotime($data['birthday']);
+ if($data['card_id'] && !Util::setCard($data['card_id'])) return JsonService::successful('输入正确的身份证号码');
ModelBasic::beginTrans();
$res1 = false;
$res2 = false;
@@ -168,6 +364,10 @@ class User extends AuthController
$res2 = true;
}
$edit['status'] = $data['status'];
+ $edit['real_name'] = $data['real_name'];
+ $edit['card_id'] = $data['card_id'];
+ $edit['birthday'] = $data['birthday'];
+ $edit['mark'] = $data['mark'];
$edit['is_promoter'] = $data['is_promoter'];
if($edit) $res3 = UserModel::edit($edit,$uid);
else $res3 = true;
diff --git a/application/admin/controller/user/UserLevel.php b/application/admin/controller/user/UserLevel.php
index 27fd7608..04b34eea 100644
--- a/application/admin/controller/user/UserLevel.php
+++ b/application/admin/controller/user/UserLevel.php
@@ -41,8 +41,8 @@ class UserLevel extends AuthController
$field[]= Form::number('valid_date','有效时间(天)',isset($vipinfo) ? $vipinfo->valid_date : 0)->min(0)->col(8);
$field[]= Form::number('grade','等级',isset($vipinfo) ? $vipinfo->grade : 0)->min(0)->col(8);
$field[]= Form::number('discount','享受折扣',isset($vipinfo) ? $vipinfo->discount : 0)->min(0)->col(8);
- $field[]= Form::frameImageOne('icon','图标',Url::build('admin/widget.images/index',array('fodder'=>'icon')),isset($vipinfo) ? $vipinfo->icon : '')->icon('image')->width('100%')->height('500px');
- $field[]= Form::frameImageOne('image','会员背景',Url::build('admin/widget.images/index',array('fodder'=>'image')),isset($vipinfo) ? $vipinfo->image : '')->icon('image')->width('100%')->height('500px');
+ $field[]= Form::formFrameImageOne('icon','图标',isset($vipinfo) ? $vipinfo->icon : '');
+ $field[]= Form::formFrameImageOne('image','会员背景',isset($vipinfo) ? $vipinfo->image : '');
$field[]= Form::radio('is_show','是否显示',isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])->col(8);
$field[]= Form::textarea('explain','等级说明',isset($vipinfo) ? $vipinfo->explain : '');
$form = Form::make_post_form('添加等级设置',$field,Url::build('save',['id'=>$id]),2);
@@ -74,9 +74,11 @@ class UserLevel extends AuthController
if(!$data['grade']) return JsonService::fail('请输入等级');
if(!$data['explain']) return JsonService::fail('请输入等级说明');
if($data['is_forever']==0 && !$data['valid_date']) return JsonService::fail('请输入有效时间(天)');
+ if($data['is_pay']) return JsonService::fail('会员等级购买功能正在开发中,暂时关闭可购买功能!');
if($data['is_pay'] && !$data['money']) return JsonService::fail('请输入购买金额');
if(!$data['icon']) return JsonService::fail('请上传等级图标');
if(!$data['image']) return JsonService::fail('请上传等级背景图标');
+ if(!$id && SystemUserLevel::be(['is_del'=>0,'grade'=>$data['grade']])) return JsonService::fail('已检测到您设置过的会员等级,此等级不可重复');
SystemUserLevel::beginTrans();
try{
//修改
@@ -86,7 +88,7 @@ class UserLevel extends AuthController
return JsonService::successful('修改成功');
}else{
SystemUserLevel::rollbackTrans();
- return JsonService::fail('添加失败');
+ return JsonService::fail('修改失败');
}
}else{
//新增
diff --git a/application/admin/controller/user/UserNotice.php b/application/admin/controller/user/UserNotice.php
index 6e0db1a5..0a8dc347 100644
--- a/application/admin/controller/user/UserNotice.php
+++ b/application/admin/controller/user/UserNotice.php
@@ -59,6 +59,7 @@ class UserNotice extends AuthController
* @return \think\Response
*/
public function save(Request $request){
+ return Json::fail('站内消息暂不可用');
$params = $request->post();
if(!$params["user"])return Json::fail('请输入发送人!');
if(!$params["title"])return Json::fail('请输入通知标题!');
diff --git a/application/admin/controller/wechat/Reply.php b/application/admin/controller/wechat/Reply.php
index 9e0af259..73b4ef47 100644
--- a/application/admin/controller/wechat/Reply.php
+++ b/application/admin/controller/wechat/Reply.php
@@ -3,6 +3,7 @@
namespace app\admin\controller\wechat;
use app\admin\controller\AuthController;
+use app\admin\model\system\SystemAttachment;
use app\admin\model\wechat\WechatReply;
use service\UtilService as Util;
use service\JsonService as Json;
@@ -86,8 +87,10 @@ class Reply extends AuthController
{
$name = $request->post('file');
if(!$name) return Json::fail('请上传图片');
- $res = Upload::image($name,'wechat/image');
- return $res->status === true ? Json::successful('上传成功',$res->filePath) : Json::fail($res->error);
+ $res = Upload::image($name,'wechat/image',true,true,null,'uniqid',1);
+ if(!is_array($res)) return Json::fail($res);
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
+ return Json::successful('上传成功',$res['dir']);
}
public function upload_file(Request $request)
diff --git a/application/admin/controller/wechat/StoreService.php b/application/admin/controller/wechat/StoreService.php
index f4f27b32..9edf0123 100644
--- a/application/admin/controller/wechat/StoreService.php
+++ b/application/admin/controller/wechat/StoreService.php
@@ -1,6 +1,7 @@
'avatar')),$service['avatar'])->icon('image');
+ $f[] = Form::formFrameImageOne('avatar','客服头像',$service['avatar']);
$f[] = Form::input('nickname','客服名称',$service["nickname"]);
$f[] = Form::switches('notify','订单通知',$service["notify"])->trueValue(1)->falseValue(0)->openStr('开启')->closeStr('关闭');
$f[] = Form::radio('status','客服状态',$service['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
@@ -135,12 +136,12 @@ class StoreService extends AuthController
*/
public function upload()
{
- $res = Upload::image('file','store/service');
- $thumbPath = Upload::thumb($res->dir);
- if($res->status == 200)
- return Json::successful('图片上传成功!',['name'=>$res->fileInfo->getSaveName(),'url'=>Upload::pathToUrl($thumbPath)]);
- else
- return Json::fail($res->error);
+ $res = Upload::image('file','store/product/'.date('Ymd'));
+ if(is_array($res)){
+ SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
+ return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
+ }else
+ return Json::fail($res);
}
/**
diff --git a/application/admin/controller/widget/Images.php b/application/admin/controller/widget/Images.php
index d5c407ae..2ad91b91 100644
--- a/application/admin/controller/widget/Images.php
+++ b/application/admin/controller/widget/Images.php
@@ -1,6 +1,9 @@
request->param('pid');
+ if($pid === NULL)
+ {
+ $pid = session('pid') ? session('pid') : 0;
}
+ session('pid',$pid);
$this->assign('pid',$pid);
- //分类标题
- $typearray = Category::getAll();
- $this->assign(compact('typearray'));
-// $typearray = self::dir;
-// $this->assign(compact('typearray'));
- $this->assign(SystemAttachmentModel::getAll($pid));
return $this->fetch('widget/images');
}
+
+ public function get_image_list()
+ {
+ $where = Util::getMore([
+ ['page',1],
+ ['limit',18],
+ ['pid',0]
+ ]);
+ return Json::successful(SystemAttachmentModel::getImageList($where));
+ }
+
+ public function get_image_cate($name = '')
+ {
+ return Json::successful(Category::getAll($name));
+ }
/**
* 图片管理上传图片
* @return \think\response\Json
@@ -48,26 +58,36 @@ class Images extends AuthController
public function upload()
{
$pid = input('pid')!= NULL ?input('pid'):session('pid');
- $res = Upload::image('file','attach'.DS.date('Y').DS.date('m').DS.date('d'));
- $thumbPath = Upload::thumb($res->dir);
- //产品图片上传记录
- $fileInfo = $res->fileInfo->getinfo();
- //入口是public需要替换图片路径
- if(strpos(PUBILC_PATH,'public') == false){
- $res->dir = str_replace('public/','',$res->dir);
+ $upload_type = $this->request->get('upload_type',0);
+ if(!$pid) {
+ $info =['code'=>400,'msg'=>'请选择分类,再进行上传!','src'=>''];
+ }else{
+ try{
+ $res = Upload::image('file','attach'.DS.date('Y').DS.date('m').DS.date('d'),true,true,null,'uniqid',$upload_type);
+ if(is_object($res) && $res->status === false){
+ $info = array(
+ 'code' =>400,
+ 'msg' =>'上传失败:'.$res->error,
+ 'src' =>''
+ );
+ }else if(is_string($res)){
+ $info = array(
+ 'code' =>400,
+ 'msg' =>'上传失败:'.$res,
+ 'src' =>''
+ );
+ }else if(is_array($res)){
+ SystemAttachmentModel::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],$pid,$res['image_type'],$res['time']);
+ $info = array(
+ 'code' =>200,
+ 'msg' =>'上传成功',
+ 'src' =>$res['dir']
+ );
+ }
+ }catch (\Exception $e){
+ $info = ['code'=>400,'msg'=>$e->getMessage(),'src'=>''];
+ }
}
- SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,$pid);
- $info = array(
-// "originalName" => $fileInfo['name'],
-// "name" => $res->fileInfo->getSaveName(),
-// "url" => '.'.$res->dir,
-// "size" => $fileInfo['size'],
-// "type" => $fileInfo['type'],
-// "state" => "SUCCESS"
- 'code' =>200,
- 'msg' =>'上传成功',
- 'src' =>$res->dir
- );
echo json_encode($info);
}
@@ -91,8 +111,16 @@ class Images extends AuthController
public function deleteimganddata($att_id){
$attinfo = SystemAttachmentModel::get($att_id)->toArray();
if($attinfo){
- @unlink(ROOT_PATH.ltrim($attinfo['att_dir'],'.'));
- @unlink(ROOT_PATH.ltrim($attinfo['satt_dir'],'.'));
+ if($attinfo['image_type'] == 1){
+ @unlink(ROOT_PATH.ltrim($attinfo['att_dir'],'.'));
+ @unlink(ROOT_PATH.ltrim($attinfo['satt_dir'],'.'));
+ }else if($attinfo['image_type'] == 2){
+ Qiniu::delete($attinfo['name']);
+ }else if($attinfo['image_type'] == 3){
+ OSS::delete($attinfo['name']);
+ }else if($attinfo['image_type'] == 4){
+ COS::delete($attinfo['name']);
+ }
SystemAttachmentModel::where(['att_id'=>$att_id])->delete();
}
}
@@ -137,10 +165,9 @@ class Images extends AuthController
/**
* ajax 添加分类
*/
- public function addcate($id){
- $id = $id || 0;
+ public function addcate($id=0){
$formbuider = [];
- $formbuider[] = Form::select('pid','上级分类','0')->setOptions(function (){
+ $formbuider[] = Form::selectOne('pid','上级分类',$id)->setOptions(function (){
$list = Category::getCateList(0);
$options = [['value'=>0,'label'=>'所有分类']];
foreach ($list as $id=>$cateName){
@@ -149,7 +176,11 @@ class Images extends AuthController
return $options;
})->filterable(1);
$formbuider[] = Form::input('name','分类名称');
- $form = Form::make_post_form('添加分类',$formbuider,Url::build('saveCate'));
+ $jsContent = <<
-
-
-
-
-
-
-
{/block}
{block name="content"}
-