diff --git a/crmeb/app/admin/controller/article/Article.php b/crmeb/app/admin/controller/article/Article.php index 155f0faf..51a936ac 100644 --- a/crmeb/app/admin/controller/article/Article.php +++ b/crmeb/app/admin/controller/article/Article.php @@ -4,7 +4,6 @@ namespace app\admin\controller\article; use app\admin\controller\AuthController; use crmeb\services\UtilService as Util; -use crmeb\services\PHPTreeService as Phptree; use crmeb\services\JsonService as Json; use crmeb\services\UploadService as Upload; use app\admin\model\article\ArticleCategory as ArticleCategoryModel; @@ -28,22 +27,12 @@ class Article extends AuthController public function index() { $where = Util::getMore([ - ['title',''], - ['cid',''] - ],$this->request); - $pid = $this->request->param('pid'); - $this->assign('where',$where); + ['title', ''], + ['cid', $this->request->param('pid', '')] + ], $this->request); + $this->assign('where', $where); $where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1 - $cateList = ArticleCategoryModel::getArticleCategoryList(); - $tree = []; - //获取分类列表 - if(count($cateList)){ - $tree = Phptree::makeTreeForHtml($cateList); - if($pid){ - $pids = Util::getChildrenPid($tree,$pid); - $where['cid'] = ltrim($pid.$pids); - } - } + $tree = sort_list_tier(ArticleCategoryModel::getArticleCategoryList()); $this->assign(compact('tree')); $this->assign(ArticleModel::getAll($where)); return $this->fetch(); @@ -56,7 +45,8 @@ class Article extends AuthController * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ - public function create(){ + public function create() + { $id = $this->request->param('id'); $cid = $this->request->param('cid'); $news = []; @@ -71,26 +61,26 @@ class Article extends AuthController $news['synopsis'] = ''; $news['url'] = ''; $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','left')->find(); - if(!$news) return $this->failed('数据不存在!'); - $news['cid'] = explode(',',$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', 'left')->find(); + if (!$news) return $this->failed('数据不存在!'); + $news['cid'] = explode(',', $news['cid']); } - if($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0,'id'))){ + if ($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0, 'id'))) { $all = ArticleCategoryModel::getArticleCategoryInfo($cid); $select = 1; } - if(!$select){ + if (!$select) { $list = ArticleCategoryModel::getTierList(); - foreach ($list as $menu){ - $all[$menu['id']] = $menu['html'].$menu['title']; + foreach ($list as $menu) { + $all[$menu['id']] = $menu['html'] . $menu['title']; } } - $this->assign('all',$all); - $this->assign('news',$news); - $this->assign('cid',$cid); - $this->assign('select',$select); + $this->assign('all', $all); + $this->assign('news', $news); + $this->assign('cid', $cid); + $this->assign('select', $select); return $this->fetch(); } @@ -98,20 +88,22 @@ class Article extends AuthController * 上传图文图片 * @return \think\response\Json */ - public function upload_image(){ - $res = Upload::instance()->setUploadPath('wechat/image/'.date('Ymd'))->image($_POST['file']); - 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']]); + public function upload_image() + { + $res = Upload::instance()->setUploadPath('wechat/image/' . date('Ymd'))->image($_POST['file']); + 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']]); } /** * 添加和修改图文 */ - public function add_new(){ + public function add_new() + { $data = Util::postMore([ - ['id',0], - ['cid',[]], + ['id', 0], + ['cid', []], 'title', 'author', 'image_input', @@ -119,47 +111,47 @@ class Article extends AuthController 'synopsis', 'share_title', 'share_synopsis', - ['visit',0], - ['sort',0], + ['visit', 0], + ['sort', 0], 'url', - ['is_banner',0], - ['is_hot',0], - ['status',1],]); - $data['cid'] = implode(',',$data['cid']); + ['is_banner', 0], + ['is_hot', 0], + ['status', 1],]); + $data['cid'] = implode(',', $data['cid']); $content = $data['content']; unset($data['content']); - if($data['id']){ + 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){ + $res1 = ArticleModel::edit($data, $id, 'id'); + $res2 = ArticleModel::setContent($id, $content); + if ($res1 && $res2) { $res = true; } ArticleModel::checkTrans($res); - if($res) - return Json::successful('修改图文成功!',$id); + if ($res) + return Json::successful('修改图文成功!', $id); else - return Json::fail('修改图文失败,您并没有修改什么!',$id); - }else{ + return Json::fail('修改图文失败,您并没有修改什么!', $id); + } else { $data['add_time'] = time(); $data['admin_id'] = $this->adminId; $res = false; ArticleModel::beginTrans(); $res1 = ArticleModel::create($data); $res2 = false; - if($res1) - $res2 = ArticleModel::setContent($res1->id,$content); - if($res1 && $res2){ + if ($res1) + $res2 = ArticleModel::setContent($res1->id, $content); + if ($res1 && $res2) { $res = true; } ArticleModel::checkTrans($res); - if($res) - return Json::successful('添加图文成功!',$res1->id); + if ($res) + return Json::successful('添加图文成功!', $res1->id); else - return Json::successful('添加图文失败!',$res1->id); + return Json::successful('添加图文失败!', $res1->id); } } @@ -171,17 +163,18 @@ class Article extends AuthController public function delete($id) { $res = ArticleModel::del($id); - if(!$res) + if (!$res) return Json::fail('删除失败,请稍候再试!'); else return Json::successful('删除成功!'); } - public function merchantIndex(){ + public function merchantIndex() + { $where = Util::getMore([ - ['title',''] - ],$this->request); - $this->assign('where',$where); + ['title', ''] + ], $this->request); + $this->assign('where', $where); $where['cid'] = input('cid'); $where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1 $this->assign(ArticleModel::getAll($where)); @@ -194,7 +187,7 @@ class Article extends AuthController */ public function relation($id = 0) { - $this->assign('id',$id); + $this->assign('id', $id); return $this->fetch(); } @@ -204,23 +197,24 @@ class Article extends AuthController */ public function edit_article($id = 0) { - if(!$id) return Json::fail('缺少参数'); + if (!$id) return Json::fail('缺少参数'); list($product_id) = Util::postMore([ - ['product_id',0] - ],$this->request,true); - if(ArticleModel::edit(['product_id'=>$product_id],['id'=>$id])) + ['product_id', 0] + ], $this->request, true); + if (ArticleModel::edit(['product_id' => $product_id], ['id' => $id])) return Json::successful('保存成功'); else return Json::fail('保存失败'); } + /** * 取消绑定的产品id * @param int $id */ public function unrelation($id = 0) { - if(!$id) return Json::fail('缺少参数'); - if(ArticleModel::edit(['product_id'=>0],$id)) + if (!$id) return Json::fail('缺少参数'); + if (ArticleModel::edit(['product_id' => 0], $id)) return Json::successful('取消关联成功!'); else return Json::fail('取消失败'); diff --git a/crmeb/crmeb/repositories/NoticeRepositories.php b/crmeb/crmeb/repositories/NoticeRepositories.php index 76377563..b095f65b 100644 --- a/crmeb/crmeb/repositories/NoticeRepositories.php +++ b/crmeb/crmeb/repositories/NoticeRepositories.php @@ -15,6 +15,7 @@ use app\models\routine\RoutineTemplate; use app\models\store\StoreOrderCartInfo; use app\models\user\User; use crmeb\services\YLYService; +use think\facade\Log; use think\facade\Route; /** 消息通知静态类 diff --git a/crmeb/crmeb/services/ApiErrorCode.php b/crmeb/crmeb/services/ApiErrorCode.php deleted file mode 100644 index cebb94d4..00000000 --- a/crmeb/crmeb/services/ApiErrorCode.php +++ /dev/null @@ -1,26 +0,0 @@ -getConstants(); - if($code) return isset($stants[$code]) ? $stants[$code] : ''; - else return $stants; - } - - /* - * 错误日志记录 - * - * */ - public static function recodeErrorLog(Exception $exception) - { - $data=[ - 'code'=>$exception->getCode(), - 'msg'=>$exception->getMessage(), - 'file'=>$exception->getFile(), - 'line'=>$exception->getLine(), - ]; - $log="[{$data['code']}] {$data['msg']} [{$data['file']} : {$data['line']}]"; - self::writeLog($log,'e'); - } - /* - * 记录日志 - * $param string $contentlog 日志内容 - * $param string $typeLog 日志类型 - * $param string $dirLog 日志目录 - * */ - public static function writeLog($contentlog='',$typeLog='',$dirLog='ebapi') - { - Log::init([ - 'type' => 'File', - 'path' => LOG_PATH.($dirLog ? $dirLog.'/' : '') - ]); - if($contentlog==='') $contentlog=self::$logInfo; - if($contentlog===null) return false; - if(is_array($contentlog)) $contentlog=var_export($contentlog,true); - if(is_object($contentlog)) $contentlog=var_export($contentlog,true); - switch (strtoupper($typeLog)){ - case 'SQL':case 'S': - Log::sql($contentlog); - break; - case 'ERROR':case 'E': - Log::error($contentlog); - break; - case 'INFO':case 'I': - Log::info($contentlog); - break; - case 'NOTICE':case 'N': - Log::notice($contentlog); - break; - case 'ALERT':case 'A': - Log::alert($contentlog); - break; - case 'LOG':case 'L': - Log::log($contentlog); - break; - } - } - -} \ No newline at end of file diff --git a/crmeb/crmeb/services/CustomerService.php b/crmeb/crmeb/services/CustomerService.php deleted file mode 100644 index d08cfa8e..00000000 --- a/crmeb/crmeb/services/CustomerService.php +++ /dev/null @@ -1,85 +0,0 @@ - &$item) { - $userInfo = WechatUser::get($item); - if ($userInfo) { - $userInfo = $userInfo->toArray(); - if ($userInfo['subscribe'] && $userInfo['openid']) { - $orderStatus = StoreService::orderServiceStatus($userInfo['uid']); - if ($orderStatus) { - // 统计管理开启 推送图文消息 - $head = '订单提醒 订单号:' . $order['order_id']; - $url = SystemConfigService::get('site_url') . '/customer/orderdetail/' . $order['order_id']; - $description = ''; - $image = SystemConfigService::get('site_logo'); - if (isset($order['seckill_id']) && $order['seckill_id'] > 0) { - $description .= '秒杀产品:' . StoreSeckill::getProductField($order['seckill_id'], 'title'); - $image = StoreSeckill::getProductField($order['seckill_id'], 'image'); - } else if (isset($order['combination_id']) && $order['combination_id'] > 0) { - $description .= '拼团产品:' . StoreCombination::getCombinationField($order['combination_id'], 'title'); - $image = StoreCombination::getCombinationField($order['combination_id'], 'image'); - } else if (isset($order['bargain_id']) && $order['bargain_id'] > 0) { - $description .= '砍价产品:' . StoreBargain::getBargainField($order['bargain_id'], 'title'); - $image = StoreBargain::getBargainField($order['bargain_id'], 'image'); - } else { - $productIds = StoreCart::getCartIdsProduct((array)$order['cart_id']); - $storeProduct = StoreProduct::getProductStoreNameOrImage($productIds); - if (count($storeProduct)) { - foreach ($storeProduct as $value) { - $description .= $value['store_name'] . ' '; - $image = $value['image']; - } - } - } - $message = WechatService::newsMessage($head, $description, $url, $image); - try { - WechatService::staffService()->message($message)->to($userInfo['openid'])->send(); - } catch (\Exception $e) { - Log::error($userInfo['nickname'] . '发送失败' . $e->getMessage()); - } - } else { - // 推送文字消息 - $head = "客服提醒:亲,您有一个新订单 \r\n订单单号:{$order['order_id']}\r\n支付金额:¥{$order['pay_price']}\r\n备注信息:{$order['mark']}\r\n订单来源:小程序"; - if ($type) $head = "客服提醒:亲,您有一个新订单 \r\n订单单号:{$order['order_id']}\r\n支付金额:¥{$order['pay_price']}\r\n备注信息:{$order['mark']}\r\n订单来源:公众号"; - try { - WechatService::staffService()->message($head)->to($userInfo['openid'])->send(); - } catch (\Exception $e) { - Log::error($userInfo['nickname'] . '发送失败' . $e->getMessage()); - } - } - } - } - - } - } - } -} \ No newline at end of file diff --git a/crmeb/crmeb/services/ExportService.php b/crmeb/crmeb/services/ExportService.php deleted file mode 100644 index 56143472..00000000 --- a/crmeb/crmeb/services/ExportService.php +++ /dev/null @@ -1,58 +0,0 @@ - - * @day: 2018/01/23 - */ - -namespace crmeb\services; - - -class ExportService -{ - public static function exportCsv($list,$filename,$header = [],$br = '_'){ - $tableStr = count($header) > 0 ? '"'.implode('","',$header).'"'.PHP_EOL : ''; - $tableStr .= self::tidyCsvStr($list,str_repeat($br,99)); - ob_end_clean(); - ob_start(); - header("Content-type:application/vnd.ms-excel"); - header("Content-Disposition:filename=".$filename.".csv"); - header('Content-Type:application/download'); - exit(iconv('UTF-8',"GB2312//IGNORE",$tableStr)); - } - - private static function tidyCsvStr($list,$br = '') - { - $tableStr = ''; - foreach ($list as $row){ - if(is_array($row)){ - $max = 1; - foreach ($row as $k=>$item){ - if(is_array($item)){ - if($max < ($l = count($item))) $max = $l; - } else - $row[$k] = [$item]; - } - for($i = 0; $i<=$max; $i++){ - $exportRow = []; - if($max == $i){ - if($br == '') - continue; - else - $exportRow = array_fill(0,count($row),$br); - }else{ - foreach ($row as $item){ - $exportRow[] = isset($item[$i]) && !empty($item[$i]) ? $item[$i] : ' '; - } - } - $tableStr .= '"'.implode('","',$exportRow).'"," "'.PHP_EOL; - } - $tableStr = rtrim($tableStr,PHP_EOL); - }else{ - $tableStr .= implode('',['"',$row,'"',',']); - } - $tableStr .= PHP_EOL; - } - return $tableStr; - } -} \ No newline at end of file diff --git a/crmeb/crmeb/services/HookService.php b/crmeb/crmeb/services/HookService.php deleted file mode 100644 index 072c13e9..00000000 --- a/crmeb/crmeb/services/HookService.php +++ /dev/null @@ -1,94 +0,0 @@ - - * @day: 2017/11/24 - */ - -namespace crmeb\services; - -class HookService -{ - - /** - * 监听有返回结果的行为 - * @param $tag - * @param $params - * @param null $extra - * @param bool $once - * @return mixed - */ - public static function resultListen($tag, $params, $extra = null, $once = false,$behavior = null) - { - self::beforeListen($tag,$params,$extra,false,$behavior); - return self::listen($tag,$params,$extra,$once,$behavior); - } - - /** - * 监听后置行为 - * @param $tag - * @param $params - * @param null $extra - */ - public static function afterListen($tag, $params, $extra = null, $once = false, $behavior = null) - { - try{ - return self::listen($tag.'_after',$params,$extra,$once,$behavior); - }catch (\Exception $e){} - } - - public static function beforeListen($tag,$params,$extra = null, $once = false, $behavior = null) - { - try{ - return self::listen($tag.'_before',$params,$extra,$once,$behavior); - }catch (\Exception $e){} - } - - /** - * 监听行为 - * @param $tag - * @param $params - * @param null $extra - * @param bool $once - * @return mixed - */ - public static function listen($tag, $params, $extra = null, $once = false, $behavior = null) - { -// if($behavior && method_exists($behavior,Loader::parseName($tag,1,false))) self::add($tag,$behavior); -// return Hook::listen($tag,$params,$extra,$once); - } - - /** - * 添加前置行为 - * @param $tag - * @param $behavior - * @param bool $first - */ - public static function addBefore($tag, $behavior, $first = false) - { - self::add($tag.'_before',$behavior,$first); - } - - /** - * 添加后置行为 - * @param $tag - * @param $behavior - * @param bool $first - */ - public static function addAfter($tag, $behavior, $first = false) - { - self::add($tag.'_after',$behavior,$first); - } - - /** - * 添加行为 - * @param $tag - * @param $behavior - * @param bool $first - */ - public static function add($tag, $behavior, $first = false) - { - Hook::add($tag,$behavior,$first); - } - -} \ No newline at end of file diff --git a/crmeb/crmeb/services/PHPTreeService.php b/crmeb/crmeb/services/PHPTreeService.php deleted file mode 100644 index 7da7921c..00000000 --- a/crmeb/crmeb/services/PHPTreeService.php +++ /dev/null @@ -1,104 +0,0 @@ - - * @des PHP生成树形结构,无限多级分类 - * @version 1.2.0 - * @Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) - * @updated 2015-08-26 - */ -class PHPTreeService -{ - protected static $config = array( - /* 主键 */ - 'primary_key' => 'id', - /* 父键 */ - 'parent_key' => 'pid', - /* 展开属性 */ - 'expanded_key' => 'expanded', - /* 叶子节点属性 */ - 'leaf_key' => 'leaf', - /* 孩子节点属性 */ - 'children_key' => 'children', - /* 是否展开子节点 */ - 'expanded' => false - ); - - /* 结果集 */ - protected static $result = array(); - - /* 层次暂存 */ - protected static $level = array(); - - /** - * @name 生成树形结构 - * @param array 二维数组 - * @return mixed 多维数组 - */ - public static function makeTree($data, $options = array()) - { - $dataset = self::buildData($data, $options); - $r = self::makeTreeCore(0, $dataset, 'normal'); - return $r; - } - - /* 生成线性结构, 便于HTML输出, 参数同上 */ - public static function makeTreeForHtml($data, $options = array()) - { - - $dataset = self::buildData($data, $options); - $r = self::makeTreeCore(0, $dataset, 'linear'); - return $r; - } - - /* 格式化数据, 私有方法 */ - private static function buildData($data, $options) - { - $config = array_merge(self::$config, $options); - self::$config = $config; - extract($config); - - $r = array(); - foreach ($data as $item) { - $id = $item[$primary_key]; - $parent_id = $item[$parent_key]; - $r[$parent_id][$id] = $item; - } - - return $r; - } - - /* 生成树核心, 私有方法 */ - private static function makeTreeCore($index, $data, $type = 'linear') - { - extract(self::$config); - foreach ($data[$index] as $id => $item) { - if ($type == 'normal') { - if (isset($data[$id])) { - $item[$expanded_key] = self::$config['expanded']; - $item[$children_key] = self::makeTreeCore($id, $data, $type); - } else { - $item[$leaf_key] = true; - } - $r[] = $item; - } else if ($type == 'linear') { - $parent_id = $item[$parent_key]; - self::$level[$id] = $index == 0 ? 0 : self::$level[$parent_id] + 1; - $item['level'] = self::$level[$id]; - self::$result[] = $item; - if (isset($data[$id])) { - self::makeTreeCore($id, $data, $type); - } - - $r = self::$result; - } - } - return $r; - } -} - - -?> \ No newline at end of file diff --git a/crmeb/crmeb/services/Template.php b/crmeb/crmeb/services/Template.php deleted file mode 100644 index dd21df6b..00000000 --- a/crmeb/crmeb/services/Template.php +++ /dev/null @@ -1,25 +0,0 @@ - - * Date: 2019/4/3 16:36 - */ - -namespace crmeb\services; - -use crmeb\traits\LogicTrait; - -/** 模版消息类 - * Class Template - * @package crmeb\services - */ -class Template -{ - use LogicTrait; - - protected $providers=[ - 'routine_two'=>ProgramTemplateService::class, - ]; - -} \ No newline at end of file