mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-03-19 04:04:08 +00:00
上传主体文件
This commit is contained in:
parent
bcc1c1f763
commit
87cf7d5388
1
application/.htaccess
Normal file
1
application/.htaccess
Normal file
@ -0,0 +1 @@
|
||||
deny from all
|
||||
120
application/admin/common.php
Normal file
120
application/admin/common.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
/**
|
||||
* 获取用户名称
|
||||
* @param $uid
|
||||
* @return mixed
|
||||
*/
|
||||
function getUserNickname($uid){
|
||||
return \app\admin\model\user\User::where('uid',$uid)->value('nickname');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品名称
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
function getProductName($id){
|
||||
return \app\admin\model\store\StoreProduct::where('id',$id)->value('store_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取拼团名称
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
function getCombinationTitle($id){
|
||||
return \app\admin\model\store\StoreCombination::where('id',$id)->value('title');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单编号
|
||||
* @param $id
|
||||
*/
|
||||
function getOrderId($id){
|
||||
return \app\admin\model\order\StoreOrder::where('id',$id)->value('order_id');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据用户uid获取订单数
|
||||
* @param $uid
|
||||
* @return int|string
|
||||
*/
|
||||
function getOrderCount($uid){
|
||||
return \app\admin\model\order\StoreOrder::where('uid',$uid)->where('paid',1)->where('refund_status',0)->where('status',2)->count();
|
||||
}
|
||||
/**
|
||||
* 格式化属性
|
||||
* @param $arr
|
||||
* @return array
|
||||
*/
|
||||
function attrFormat($arr){
|
||||
$data = [];
|
||||
$res = [];
|
||||
if(count($arr) > 1){
|
||||
for ($i=0; $i < count($arr)-1; $i++) {
|
||||
if($i == 0) $data = $arr[$i]['detail'];
|
||||
//替代变量1
|
||||
$rep1 = [];
|
||||
foreach ($data as $v) {
|
||||
foreach ($arr[$i+1]['detail'] as $g) {
|
||||
//替代变量2
|
||||
$rep2 = ($i!=0?'':$arr[$i]['value']."_").$v."-".$arr[$i+1]['value']."_".$g;
|
||||
$tmp[] = $rep2;
|
||||
if($i==count($arr)-2){
|
||||
foreach (explode('-', $rep2) as $k => $h) {
|
||||
//替代变量3
|
||||
$rep3 = explode('_', $h);
|
||||
//替代变量4
|
||||
$rep4['detail'][$rep3[0]] = $rep3[1];
|
||||
}
|
||||
$res[] = $rep4;
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = $tmp;
|
||||
}
|
||||
}else{
|
||||
$dataArr = [];
|
||||
foreach ($arr as $k=>$v){
|
||||
foreach ($v['detail'] as $kk=>$vv){
|
||||
$dataArr[$kk] = $v['value'].'_'.$vv;
|
||||
$res[$kk]['detail'][$v['value']] = $vv;
|
||||
}
|
||||
}
|
||||
$data[] = implode('-',$dataArr);
|
||||
}
|
||||
return [$data,$res];
|
||||
}
|
||||
|
||||
function getMonth($time='',$ceil=0){
|
||||
if(empty($time)){
|
||||
$firstday = date("Y-m-01",time());
|
||||
$lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
|
||||
}else if($time=='n'){
|
||||
if($ceil!=0)
|
||||
$season = ceil(date('n') /3)-$ceil;
|
||||
else
|
||||
$season = ceil(date('n') /3);
|
||||
$firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
|
||||
$lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
|
||||
}else if($time=='y'){
|
||||
$firstday=date('Y-01-01');
|
||||
$lastday=date('Y-12-31');
|
||||
}else if($time=='h'){
|
||||
$firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00';
|
||||
$lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59';
|
||||
}
|
||||
return array($firstday,$lastday);
|
||||
}
|
||||
23
application/admin/config.php
Normal file
23
application/admin/config.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
return [
|
||||
'session' => [
|
||||
// SESSION 前缀
|
||||
'prefix' => 'admin',
|
||||
// 驱动方式 支持redis memcache memcached
|
||||
'type' => '',
|
||||
// 是否自动开启 SESSION
|
||||
'auto_start' => true,
|
||||
],
|
||||
'system_wechat_tag' => '_system_wechat'
|
||||
];
|
||||
111
application/admin/controller/AuthApi.php
Normal file
111
application/admin/controller/AuthApi.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\ump\StoreBargain;
|
||||
use app\admin\model\ump\StoreCombination;
|
||||
use app\admin\model\ump\StoreSeckill;
|
||||
use basic\SystemBasic;
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use service\JsonService;
|
||||
use service\UtilService;
|
||||
|
||||
/**
|
||||
* 异步请求控制器
|
||||
* Class AuthApi
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class AuthApi extends SystemBasic
|
||||
{
|
||||
/**
|
||||
* 获取砍价产品曲线图数据
|
||||
*/
|
||||
public function get_echarts_product($type='',$data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getChatrdata($type,$data));
|
||||
if($model) return JsonService::successful(StoreSeckill::getChatrdata($type,$data));
|
||||
}
|
||||
/**
|
||||
* 获取销量
|
||||
*/
|
||||
public function get_echarts_maxlist($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getMaxList(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::getMaxList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取利润
|
||||
*/
|
||||
public function get_echarts_profity($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::ProfityTop10(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::ProfityTop10(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取补货的砍价产品
|
||||
*/
|
||||
public function getLackList($model = 0){
|
||||
$where = UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getLackList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getLackList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的评论
|
||||
*/
|
||||
public function getnegativelist($model = 0){
|
||||
$where = UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getNegativeList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getNegativeList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的退货
|
||||
*/
|
||||
public function get_bargain_refund_list($model = 0){
|
||||
$where = UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getBargainRefundList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getBargainRefundList($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改拼团状态
|
||||
* @param $status
|
||||
* @param int $idd
|
||||
*/
|
||||
public function set_combination_status($status,$id = 0){
|
||||
if(!$id) return JsonService::fail('参数错误');
|
||||
$res = StoreCombination::edit(['is_show'=>$status],$id);
|
||||
if($res) return JsonService::successful('修改成功');
|
||||
else return JsonService::fail('修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改砍价状态
|
||||
* @param $status
|
||||
* @param int $id
|
||||
*/
|
||||
public function set_bargain_status($status,$id = 0){
|
||||
if(!$id) return JsonService::fail('参数错误');
|
||||
$res = StoreBargain::edit(['status'=>$status],$id);
|
||||
if($res) return JsonService::successful('修改成功');
|
||||
else return JsonService::fail('修改失败');
|
||||
}
|
||||
/**
|
||||
* 修改秒杀产品状态
|
||||
* @param $status
|
||||
* @param int $id
|
||||
*/
|
||||
public function set_seckill_status($status,$id = 0){
|
||||
if(!$id) return JsonService::fail('参数错误');
|
||||
$res = StoreSeckill::edit(['status'=>$status],$id);
|
||||
if($res) return JsonService::successful('修改成功');
|
||||
else return JsonService::fail('修改失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
89
application/admin/controller/AuthController.php
Normal file
89
application/admin/controller/AuthController.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use basic\SystemBasic;
|
||||
use behavior\system\SystemBehavior;
|
||||
use service\HookService;
|
||||
use think\Url;
|
||||
|
||||
/**
|
||||
* 基类 所有控制器继承的类
|
||||
* Class AuthController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class AuthController extends SystemBasic
|
||||
{
|
||||
/**
|
||||
* 当前登陆管理员信息
|
||||
* @var
|
||||
*/
|
||||
protected $adminInfo;
|
||||
|
||||
/**
|
||||
* 当前登陆管理员ID
|
||||
* @var
|
||||
*/
|
||||
protected $adminId;
|
||||
|
||||
/**
|
||||
* 当前管理员权限
|
||||
* @var array
|
||||
*/
|
||||
protected $auth = [];
|
||||
|
||||
protected $skipLogController = ['index','common'];
|
||||
|
||||
protected function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
if(!SystemAdmin::hasActiveAdmin()) return $this->redirect('Login/index');
|
||||
try{
|
||||
$adminInfo = SystemAdmin::activeAdminInfoOrFail();
|
||||
}catch (\Exception $e){
|
||||
return $this->failed(SystemAdmin::getErrorInfo($e->getMessage()),Url::build('Login/index'));
|
||||
}
|
||||
$this->adminInfo = $adminInfo;
|
||||
$this->adminId = $adminInfo['id'];
|
||||
$this->getActiveAdminInfo();
|
||||
$this->auth = SystemAdmin::activeAdminAuthOrFail();
|
||||
$this->adminInfo->level === 0 || $this->checkAuth();
|
||||
$this->assign('_admin',$this->adminInfo);
|
||||
HookService::listen('admin_visit',$this->adminInfo,'system',false,SystemBehavior::class);
|
||||
}
|
||||
|
||||
|
||||
protected function checkAuth($action = null,$controller = null,$module = null,array $route = [])
|
||||
{
|
||||
static $allAuth = null;
|
||||
if($allAuth === null) $allAuth = SystemRole::getAllAuth();
|
||||
if($module === null) $module = $this->request->module();
|
||||
if($controller === null) $controller = $this->request->controller();
|
||||
if($action === null) $action = $this->request->action();
|
||||
if(!count($route)) $route = $this->request->route();
|
||||
if(in_array(strtolower($controller),$this->skipLogController,true)) return true;
|
||||
$nowAuthName = SystemMenus::getAuthName($action,$controller,$module,$route);
|
||||
$baseNowAuthName = SystemMenus::getAuthName($action,$controller,$module,[]);
|
||||
if((in_array($nowAuthName,$allAuth) && !in_array($nowAuthName,$this->auth)) || (in_array($baseNowAuthName,$allAuth) && !in_array($baseNowAuthName,$this->auth)))
|
||||
exit($this->failed('没有权限访问!'));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得当前用户最新信息
|
||||
* @return SystemAdmin
|
||||
*/
|
||||
protected function getActiveAdminInfo()
|
||||
{
|
||||
$adminId = $this->adminId;
|
||||
$adminInfo = SystemAdmin::getValidAdminInfoOrFail($adminId);
|
||||
if(!$adminInfo) $this->failed(SystemAdmin::getErrorInfo('请登陆!'));
|
||||
$this->adminInfo = $adminInfo;
|
||||
SystemAdmin::setLoginInfo($adminInfo);
|
||||
return $adminInfo;
|
||||
}
|
||||
}
|
||||
23
application/admin/controller/Common.php
Normal file
23
application/admin/controller/Common.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/07
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use service\UtilService;
|
||||
|
||||
class Common extends AuthController
|
||||
{
|
||||
public function rmPublicResource($url)
|
||||
{
|
||||
$res = UtilService::rmPublicResource($url);
|
||||
if($res->status)
|
||||
return $this->successful('删除成功!');
|
||||
else
|
||||
return $this->failed($res->msg);
|
||||
}
|
||||
}
|
||||
169
application/admin/controller/Index.php
Normal file
169
application/admin/controller/Index.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use app\admin\model\system\SystemNotice as NoticeModel;
|
||||
use app\admin\model\system\SystemNotice;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\user\UserExtract;
|
||||
use service\CacheService;
|
||||
use service\UpgradeService;
|
||||
use service\UpgradeApi;
|
||||
use think\DB;
|
||||
|
||||
/**
|
||||
* 首页控制器
|
||||
* Class Index
|
||||
* @package app\admin\controller
|
||||
*
|
||||
*/
|
||||
class Index extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
//获取当前登录后台的管理员信息
|
||||
$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),
|
||||
'role_name'=>SystemRole::where('id',$roles[0])->field('role_name')->find()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//后台首页内容
|
||||
public function main()
|
||||
{
|
||||
/*首页第一行统计*/
|
||||
$now_month = strtotime(date('Y-m'));
|
||||
$pre_month = strtotime(date('Y-m',strtotime('-1 month')));
|
||||
$now_day = strtotime(date('Y-m-d'));
|
||||
$pre_day = strtotime(date('Y-m-d',strtotime('-1 day')));//昨天时间戳
|
||||
$day = strtotime(date('Y-m-d',strtotime('0 day')));//今天时间戳
|
||||
//昨天待发货数量
|
||||
$topData['orderDeliveryNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)
|
||||
->where('status',0)
|
||||
->where('paid',1)
|
||||
->where('refund_status',0)
|
||||
->count();
|
||||
//昨天退换货订单数
|
||||
$topData['orderRefundNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)
|
||||
->where('paid',1)
|
||||
->where('refund_status','IN','1,2')
|
||||
->count();
|
||||
//库存预警
|
||||
$replenishment_num = SystemConfig::getValue('store_stock') > 0 ? SystemConfig::getValue('store_stock') : 20;//库存预警界限
|
||||
$topData['stockProduct'] = StoreProduct::where('stock','<=',$replenishment_num)->where('is_del',0)->count();
|
||||
//待处理提现
|
||||
$topData['treatedExtract'] = UserExtract::where('status',0)->count();
|
||||
//昨日订单数
|
||||
$topData['orderNum'] = StoreOrder::isMainYesterdayCount($pre_day,$day)->count();
|
||||
//昨日交易额
|
||||
$orderPriceNum = StoreOrder::isMainYesterdayCount($pre_day,$day)->field('sum(pay_price) as pay_price')->find()['pay_price'];
|
||||
$topData['orderPriceNum'] = $orderPriceNum ? $orderPriceNum : 0;
|
||||
//总收入->日
|
||||
$now_day_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$now_day)->value('sum(pay_price)');
|
||||
$pre_day_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_day)->where('pay_time','lt',$now_day)->value('sum(pay_price)');
|
||||
$first_line['d_price'] = [
|
||||
'data' => $now_day_order_p ? $now_day_order_p : 0,
|
||||
'percent' => abs($now_day_order_p - $pre_day_order_p),
|
||||
'is_plus' => $now_day_order_p - $pre_day_order_p > 0 ? 1 : ($now_day_order_p - $pre_day_order_p == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//总收入->月
|
||||
$now_month_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$now_month)->value('sum(pay_price)');
|
||||
$pre_month_order_p = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_month)->where('pay_time','lt',$now_month)->value('sum(pay_price)');
|
||||
$first_line['m_price'] = [
|
||||
'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
|
||||
'percent' => abs($now_month_order_p - $pre_month_order_p),
|
||||
'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//新粉丝->日
|
||||
$now_day_user = DB::name('User')->where('add_time','gt',$now_day)->count();
|
||||
$pre_day_user = DB::name('User')->where('add_time','gt',$pre_day)->where('add_time','lt',$now_day)->count();
|
||||
$pre_day_user = $pre_day_user ? $pre_day_user : 0;
|
||||
$first_line['day'] = [
|
||||
'data' => $now_day_user ? $now_day_user : 0,
|
||||
'percent' => abs($now_day_user - $pre_day_user),
|
||||
'is_plus' => $now_day_user - $pre_day_user > 0 ? 1 : ($now_day_user - $pre_day_user == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//新粉丝->月
|
||||
$now_month_user = DB::name('User')->where('add_time','gt',$now_month)->count();
|
||||
$pre_month_user = DB::name('User')->where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
|
||||
$first_line['month'] = [
|
||||
'data' => $now_month_user ? $now_month_user : 0,
|
||||
'percent' => abs($now_month_user - $pre_month_user),
|
||||
'is_plus' => $now_month_user - $pre_month_user > 0 ? 1 : ($now_month_user - $pre_month_user == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
/*首页第二行统计*/
|
||||
$second_line['order_count_max'] = 50; //max最小为100
|
||||
for ($i=0; $i < 7; $i++) {
|
||||
$time = strtotime('-'.$i.' day');
|
||||
$now_day_info = strtotime(date('Y-m-d',strtotime('-'.($i-1).' day')));
|
||||
$pre_day_info = strtotime(date('Y-m-d',strtotime('-'.$i.' day')));
|
||||
$order_count[$i]['y'] = date('Y',$time);
|
||||
$order_count[$i]['m'] = date('m',$time);
|
||||
$order_count[$i]['d'] = date('d',$time);
|
||||
$order_count[$i]['count'] = StoreOrder::where('add_time','gt',$pre_day_info)->where('add_time','lt',$now_day_info)->count();
|
||||
$second_line['order_count_max'] = $second_line['order_count_max'] > $order_count[$i]['count'] ? $second_line['order_count_max'] : $order_count[$i]['count'];
|
||||
}
|
||||
$second_line['order_count'] = $order_count;
|
||||
|
||||
//本月订单总数
|
||||
$now_order_info_c = StoreOrder::where('add_time','gt',$now_month)->count();
|
||||
$pre_order_info_c = StoreOrder::where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
|
||||
$order_info['first'] = [
|
||||
'data' => $now_order_info_c ? $now_order_info_c : 0,
|
||||
'percent' => abs($now_order_info_c - $pre_order_info_c),
|
||||
'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//上月订单总数
|
||||
$second_now_month = strtotime(date('Y-m',strtotime('-1 month')));
|
||||
$second_pre_month = strtotime(date('Y-m',strtotime('-2 month')));
|
||||
$now_order_info_c = StoreOrder::where('add_time','gt',$pre_month)->where('add_time','lt',$now_month)->count();
|
||||
$pre_order_info_c = StoreOrder::where('add_time','gt',$second_pre_month)->where('add_time','lt',$second_now_month)->count();
|
||||
$order_info["second"] = [
|
||||
'data' => $now_order_info_c ? $now_order_info_c : 0,
|
||||
'percent' => abs($now_order_info_c - $pre_order_info_c),
|
||||
'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
|
||||
];
|
||||
$second_line['order_info'] = $order_info;
|
||||
|
||||
/*首页第三行统计*/
|
||||
$third_line['order_count_max'] = 100; //max最小为100
|
||||
for ($x=0; $x < 30; $x++) {
|
||||
$time = strtotime('-'.$x.' day');
|
||||
$now_day_info = strtotime(date('Y-m-d',strtotime('-'.($x-1).' day')));
|
||||
$pre_day_info = strtotime(date('Y-m-d',strtotime('-'.$x.' day')));
|
||||
$price_count[$x]['y'] = date('Y',$time);
|
||||
$price_count[$x]['m'] = date('m',$time);
|
||||
$price_count[$x]['d'] = date('d',$time);
|
||||
$price_count[$x]['count'] = StoreOrder::where('paid',1)->where('pay_time','gt',$pre_day_info)->where('pay_time','lt',$now_day_info)->value('sum(pay_price)');
|
||||
$third_line['order_count_max'] = $third_line['order_count_max'] > $price_count[$x]['count'] ? $third_line['order_count_max'] : $price_count[$x]['count'];
|
||||
}
|
||||
$third_line['price_count'] = $price_count;
|
||||
$this->assign([
|
||||
'first_line' => $first_line,
|
||||
'second_line' => $second_line,
|
||||
'third_line' => $third_line,
|
||||
'topData' => $topData,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function test(){
|
||||
UpgradeService::start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
73
application/admin/controller/Login.php
Normal file
73
application/admin/controller/Login.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use basic\SystemBasic;
|
||||
use service\CacheService;
|
||||
use service\UtilService;
|
||||
use think\Request;
|
||||
use think\Response;
|
||||
use think\Session;
|
||||
use think\Url;
|
||||
|
||||
/**
|
||||
* 登录验证控制器
|
||||
* Class Login
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Login extends SystemBasic
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录验证 + 验证码验证
|
||||
*/
|
||||
public function verify(Request $request)
|
||||
{
|
||||
if(!$request->isPost()) return $this->failed('请登陆!');
|
||||
list($account,$pwd,$verify) = UtilService::postMore([
|
||||
'account','pwd','verify'
|
||||
],$request,true);
|
||||
//检验验证码
|
||||
if(!captcha_check($verify)) return $this->failed('验证码错误,请重新输入');
|
||||
$error = Session::get('login_error')?:['num'=>0,'time'=>time()];
|
||||
if($error['num'] >=5 && $error['time'] < strtotime('+ 5 minutes'))
|
||||
return $this->failed('错误次数过多,请稍候再试!');
|
||||
//检验帐号密码
|
||||
$res = SystemAdmin::login($account,$pwd);
|
||||
if($res){
|
||||
Session::set('login_error',null);
|
||||
return $this->redirect(Url::build('Index/index'));
|
||||
}else{
|
||||
$error['num'] += 1;
|
||||
$error['time'] = time();
|
||||
Session::set('login_error',$error);
|
||||
return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
|
||||
}
|
||||
}
|
||||
|
||||
public function captcha()
|
||||
{
|
||||
ob_clean();
|
||||
$captcha = new \think\captcha\Captcha([
|
||||
'codeSet'=>'0123456789',
|
||||
'length'=>4,
|
||||
'fontSize'=>30
|
||||
]);
|
||||
return $captcha->entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登陆
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
SystemAdmin::clearLoginInfo();
|
||||
$this->redirect('Login/index');
|
||||
}
|
||||
}
|
||||
96
application/admin/controller/agent/AgentManage.php
Normal file
96
application/admin/controller/agent/AgentManage.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\agent;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use app\admin\library\FormBuilder;
|
||||
use app\wap\model\user\UserBill;
|
||||
use service\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 分销商管理控制器
|
||||
* Class AgentManage
|
||||
* @package app\admin\controller\agent
|
||||
*/
|
||||
class AgentManage extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
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::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 一级推荐人页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function stair($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$list = User::alias('u')
|
||||
->where('u.spread_uid',$uid)
|
||||
->field('u.avatar,u.nickname,u.now_money,u.add_time,u.uid')
|
||||
->where('u.status',1)
|
||||
->order('u.add_time DESC')
|
||||
->select()
|
||||
->toArray();
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人资金详情页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function now_money($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$list = UserBill::where('uid',$uid)->where('category','now_money')
|
||||
->field('mark,pm,number,add_time')
|
||||
->where('status',1)->order('add_time DESC')->select()->toArray();
|
||||
foreach ($list as &$v){
|
||||
$v['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
|
||||
}
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
192
application/admin/controller/article/Article.php
Normal file
192
application/admin/controller/article/Article.php
Normal file
@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\article;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 图文管理
|
||||
* Class WechatNews
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Article extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示后台管理员添加的图文
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($cid = 0)
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
if($cid)
|
||||
$where['cid'] = $cid;
|
||||
else
|
||||
$where['cid'] = '';
|
||||
$this->assign('where',$where);
|
||||
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign('cate',ArticleCategoryModel::getTierList());
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示页面 添加和删除
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(){
|
||||
$id = input('id');
|
||||
$cid = input('cid');
|
||||
$news = array();
|
||||
$news['id'] = '';
|
||||
$news['image_input'] = '';
|
||||
$news['title'] = '';
|
||||
$news['author'] = '';
|
||||
$news['is_banner'] = '';
|
||||
$news['is_hot'] = '';
|
||||
$news['content'] = '';
|
||||
$news['synopsis'] = '';
|
||||
$news['url'] = '';
|
||||
$news['cid'] = array();
|
||||
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(empty($all)){
|
||||
$select = 0;
|
||||
$list = ArticleCategoryModel::getTierList();
|
||||
$all = [];
|
||||
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);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图文图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加和修改图文
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function add_new(Request $request){
|
||||
$post = $request->post();
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['cid',[]],
|
||||
'title',
|
||||
'author',
|
||||
'image_input',
|
||||
'content',
|
||||
'synopsis',
|
||||
'share_title',
|
||||
'share_synopsis',
|
||||
['visit',0],
|
||||
['sort',0],
|
||||
'url',
|
||||
['status',1],],$request);
|
||||
$data['cid'] = implode(',',$data['cid']);
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
if($data['id']){
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::edit($data,$id,'id');
|
||||
$res2 = ArticleModel::setContent($id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
// dump($res);
|
||||
// exit();
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('修改图文成功!',$id);
|
||||
else
|
||||
return Json::fail('修改图文失败!',$id);
|
||||
}else{
|
||||
$data['add_time'] = time();
|
||||
$data['admin_id'] = $this->adminId;
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::set($data);
|
||||
$res2 = false;
|
||||
if($res1)
|
||||
$res2 = ArticleModel::setContent($res1->id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('添加图文成功!',$res1->id);
|
||||
else
|
||||
return Json::successful('添加图文失败!',$res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图文
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$res = ArticleModel::del($id);
|
||||
if(!$res)
|
||||
return Json::fail('删除失败,请稍候再试!');
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function merchantIndex(){
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$where['cid'] = input('cid');
|
||||
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/article/ArticleCategory.php
Normal file
1
application/admin/controller/article/ArticleCategory.php
Normal file
File diff suppressed because one or more lines are too long
230
application/admin/controller/finance/Finance.php
Normal file
230
application/admin/controller/finance/Finance.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2018/6/14 下午5:25
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\finance;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\UserBill;
|
||||
use service\JsonService as Json;
|
||||
use app\admin\model\finance\FinanceModel;
|
||||
use service\UtilService as Util;
|
||||
use service\FormBuilder as Form;
|
||||
//use FormBuilder\Form;
|
||||
use service\HookService;
|
||||
use think\Url;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserExtract;
|
||||
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
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;
|
||||
|
||||
}
|
||||
/**
|
||||
* 显示资金记录
|
||||
*/
|
||||
public function bill(){
|
||||
$list=UserBill::where('type','not in',['gain','system_sub','deduction','sign'])
|
||||
->where('category','not in','integral')
|
||||
->field(['title','type'])
|
||||
->group('type')
|
||||
->distinct(true)
|
||||
->select()
|
||||
->toArray();
|
||||
$this->assign('selectList',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示资金记录ajax列表
|
||||
*/
|
||||
public function billlist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['limit',20],
|
||||
['page',1],
|
||||
['type',''],
|
||||
]);
|
||||
return Json::successlayui(FinanceModel::getBillList($where));
|
||||
}
|
||||
/**
|
||||
*保存资金监控的excel表格
|
||||
*/
|
||||
public function save_bell_export(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['type',''],
|
||||
]);
|
||||
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();
|
||||
// }
|
||||
/**
|
||||
* 显示佣金记录
|
||||
*/
|
||||
public function commission_list(){
|
||||
$this->assign('is_layui',true);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 佣金记录异步获取
|
||||
*/
|
||||
public function get_commission_list(){
|
||||
$get=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['nickname',''],
|
||||
['price_max',''],
|
||||
['price_min',''],
|
||||
['order','']
|
||||
]);
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index3(){
|
||||
|
||||
}
|
||||
/**
|
||||
* 佣金详情
|
||||
*/
|
||||
public function content_info($uid=''){
|
||||
if($uid=='') return $this->failed('缺少参数');
|
||||
$this->assign('userinfo',User::getUserinfo($uid));
|
||||
$this->assign('uid',$uid);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 佣金提现记录个人列表
|
||||
*/
|
||||
public function get_extract_list($uid=''){
|
||||
if($uid=='') return Json::fail('缺少参数');
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname','']
|
||||
]);
|
||||
return Json::successlayui(UserBill::getExtrctOneList($where,$uid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
105
application/admin/controller/finance/UserExtract.php
Normal file
105
application/admin/controller/finance/UserExtract.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lianghuan
|
||||
* Date: 2018-03-03
|
||||
* Time: 16:37
|
||||
*/
|
||||
namespace app\admin\controller\finance;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use app\admin\model\user\UserExtract as UserExtractModel;
|
||||
use service\JsonService;
|
||||
use think\Request;
|
||||
use service\UtilService as Util;
|
||||
use think\Url;
|
||||
/* 用户提现管理
|
||||
* */
|
||||
class UserExtract extends AuthController
|
||||
{
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['nickname',''],
|
||||
['extract_type',''],
|
||||
['nireid',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserExtractModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function edit($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserExtract = UserExtractModel::get($id);
|
||||
if(!$UserExtract) return JsonService::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('real_name','姓名',$UserExtract['real_name']);
|
||||
$f[] = Form::number('extract_price','提现金额',$UserExtract['extract_price'])->precision(2);
|
||||
if($UserExtract['extract_type']=='alipay'){
|
||||
$f[] = Form::input('alipay_code','支付宝账号',$UserExtract['alipay_code']);
|
||||
}else{
|
||||
$f[] = Form::input('bank_code','银行卡号',$UserExtract['bank_code']);
|
||||
$f[] = Form::input('bank_address','开户行',$UserExtract['bank_address']);
|
||||
}
|
||||
$f[] = Form::input('mark','备注',$UserExtract['mark'])->type('textarea');
|
||||
$form = Form::make_post_form('编辑',$f,Url::build('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
}
|
||||
public function update(Request $request,$id)
|
||||
{
|
||||
$UserExtract = UserExtractModel::get($id);
|
||||
if(!$UserExtract) return JsonService::fail('数据不存在!');
|
||||
if($UserExtract['extract_type']=='alipay'){
|
||||
$data = Util::postMore([
|
||||
'real_name',
|
||||
'mark',
|
||||
'extract_price',
|
||||
'alipay_code',
|
||||
],$request);
|
||||
if(!$data['real_name']) return JsonService::fail('请输入姓名');
|
||||
if($data['extract_price']<=-1) return JsonService::fail('请输入提现金额');
|
||||
if(!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
|
||||
}else{
|
||||
$data = Util::postMore([
|
||||
'real_name',
|
||||
'extract_price',
|
||||
'mark',
|
||||
'bank_code',
|
||||
'bank_address',
|
||||
],$request);
|
||||
if(!$data['real_name']) return JsonService::fail('请输入姓名');
|
||||
if($data['extract_price']<=-1) return JsonService::fail('请输入提现金额');
|
||||
if(!$data['bank_code']) return JsonService::fail('请输入银行卡号');
|
||||
if(!$data['bank_address']) return JsonService::fail('请输入开户行');
|
||||
}
|
||||
if(!UserExtractModel::edit($data,$id))
|
||||
return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
|
||||
else
|
||||
return JsonService::successful('修改成功!');
|
||||
}
|
||||
public function fail(Request $request,$id)
|
||||
{
|
||||
if(!UserExtractModel::be(['id'=>$id,'status'=>0])) return JsonService::fail('操作记录不存在或状态错误!');
|
||||
$fail_msg =$request->post();
|
||||
$res = UserExtractModel::changeFail($id,$fail_msg['message']);
|
||||
if($res){
|
||||
return JsonService::successful('操作成功!');
|
||||
}else{
|
||||
return JsonService::fail('操作失败!');
|
||||
}
|
||||
}
|
||||
public function succ($id)
|
||||
{
|
||||
if(!UserExtractModel::be(['id'=>$id,'status'=>0]))
|
||||
return JsonService::fail('操作记录不存在或状态错误!');
|
||||
UserExtractModel::beginTrans();
|
||||
$res = UserExtractModel::changeSuccess($id);
|
||||
if($res){
|
||||
return JsonService::successful('操作成功!');
|
||||
}else{
|
||||
return JsonService::fail('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
89
application/admin/controller/finance/UserRecharge.php
Normal file
89
application/admin/controller/finance/UserRecharge.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
namespace app\admin\controller\finance;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\UserRecharge as UserRechargeModel;
|
||||
use app\wap\model\user\UserBill;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use think\Url;
|
||||
use service\FormBuilder as Form;
|
||||
use think\Request;
|
||||
use service\HookService;
|
||||
use behavior\wechat\PaymentBehavior;
|
||||
use service\WechatTemplateService;
|
||||
use app\wap\model\user\WechatUser as WechatUserWap;
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class UserRecharge extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['order_id',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserRechargeModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**退款
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function edit($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserRecharge = UserRechargeModel::get($id);
|
||||
if(!$UserRecharge) return Json::fail('数据不存在!');
|
||||
if($UserRecharge['paid'] == 1){
|
||||
$f = array();
|
||||
$f[] = Form::input('order_id','退款单号',$UserRecharge->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::number('refund_price','退款金额',$UserRecharge->getData('price'))->precision(2)->min(0)->max($UserRecharge->getData('price'));
|
||||
$form = Form::make_post_form('编辑',$f,Url::build('updateRefundY',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
|
||||
/**退款更新
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function updateRefundY(Request $request, $id){
|
||||
$data = Util::postMore([
|
||||
'refund_price',
|
||||
],$request);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserRecharge = UserRechargeModel::get($id);
|
||||
if(!$UserRecharge) return Json::fail('数据不存在!');
|
||||
if($UserRecharge['price'] == $UserRecharge['refund_price']) return Json::fail('已退完支付金额!不能再退款了');
|
||||
if(!$data['refund_price']) return Json::fail('请输入退款金额');
|
||||
$refund_price = $data['refund_price'];
|
||||
$data['refund_price'] = bcadd($data['refund_price'],$UserRecharge['refund_price'],2);
|
||||
$bj = bccomp((float)$UserRecharge['price'],(float)$data['refund_price'],2);
|
||||
if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额');
|
||||
$refund_data['pay_price'] = $UserRecharge['price'];
|
||||
$refund_data['refund_price'] = $refund_price;
|
||||
try{
|
||||
HookService::listen('user_recharge_refund',$UserRecharge['order_id'],$refund_data,true,PaymentBehavior::class);
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->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));
|
||||
UserBill::expend('系统退款',$UserRecharge['uid'],'now_money','user_recharge_refund',$refund_price,$id,$UserRecharge['price'],'退款给用户'.$refund_price.'元');
|
||||
return Json::successful('退款成功!');
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/order/StoreOrder.php
Normal file
1
application/admin/controller/order/StoreOrder.php
Normal file
File diff suppressed because one or more lines are too long
1
application/admin/controller/order/StoreOrderPink.php
Normal file
1
application/admin/controller/order/StoreOrderPink.php
Normal file
File diff suppressed because one or more lines are too long
604
application/admin/controller/record/Record.php
Normal file
604
application/admin/controller/record/Record.php
Normal file
@ -0,0 +1,604 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2018/6/14 下午5:25
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\record;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\ump\StoreBargain;
|
||||
use app\admin\model\ump\StoreSeckill;
|
||||
use app\admin\model\ump\StoreCombination;
|
||||
use service\JsonService;
|
||||
use service\UtilService as Util;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
use app\admin\model\user\UserExtract;
|
||||
use app\admin\model\store\StoreCouponUser;
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class Record extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 显示订单记录
|
||||
*/
|
||||
public function chart_order(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function get_echarts_order(){
|
||||
$where=Util::getMore([
|
||||
['type',''],
|
||||
['status',''],
|
||||
['data',''],
|
||||
]);
|
||||
return JsonService::successful(StoreOrder::getEchartsOrder($where));
|
||||
}
|
||||
/**
|
||||
* 显示产品记录
|
||||
*/
|
||||
public function chart_product(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取产品曲线图数据
|
||||
*/
|
||||
public function get_echarts_product($type='',$data=''){
|
||||
return JsonService::successful(StoreProduct::getChatrdata($type,$data));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取销量
|
||||
*/
|
||||
public function get_echarts_maxlist($data=''){
|
||||
return JsonService::successful(StoreProduct::getMaxList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取利润
|
||||
*/
|
||||
public function get_echarts_profity($data=''){
|
||||
return JsonService::successful(StoreProduct::ProfityTop10(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取缺货列表
|
||||
*/
|
||||
public function getLackList(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(StoreProduct::getLackList($where));
|
||||
}
|
||||
/**
|
||||
* 表单快速修改
|
||||
*/
|
||||
public function editField($id=''){
|
||||
$post=$this->request->post();
|
||||
StoreProduct::beginTrans();
|
||||
try{
|
||||
StoreProduct::edit($post,$id);
|
||||
StoreProduct::commitTrans();
|
||||
return JsonService::successful('修改成功');
|
||||
}catch (\Exception $e){
|
||||
StoreProduct::rollbackTrans();
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
//获取差评
|
||||
public function getnegativelist(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',10],
|
||||
]);
|
||||
return JsonService::successful(StoreProduct::getnegativelist($where));
|
||||
}
|
||||
/**
|
||||
* 获取退货
|
||||
*/
|
||||
public function getTuiPriesList(){
|
||||
return JsonService::successful(StoreProduct::TuiProductList());
|
||||
}
|
||||
//营销统计
|
||||
/**
|
||||
* 显示积分统计
|
||||
*/
|
||||
public function chart_score(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取积分头部信息
|
||||
*/
|
||||
public function getScoreBadgeList($data=''){
|
||||
return JsonService::successful(UserBill::getScoreBadgeList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取积分曲线图和柱状图
|
||||
*/
|
||||
public function getScoreCurve($data='',$limit=20){
|
||||
return JsonService::successful(UserBill::getScoreCurve(compact('data','limit')));
|
||||
}
|
||||
/**
|
||||
* 显示优惠券统计
|
||||
*/
|
||||
public function chart_coupon(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取优惠劵头部信息
|
||||
*/
|
||||
public function getCouponBadgeList($data=''){
|
||||
return JsonService::successful(StoreCouponUser::getCouponBadgeList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取优惠劵数据图表
|
||||
*/
|
||||
public function getConponCurve($data=''){
|
||||
return JsonService::successful(StoreCouponUser::getConponCurve(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示拼团统计
|
||||
*/
|
||||
public function chart_combination(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示砍价统计
|
||||
*/
|
||||
public function chart_bargain(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示秒杀统计
|
||||
*/
|
||||
public function chart_seckill(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//财务统计
|
||||
/**
|
||||
* 显示反佣统计
|
||||
*/
|
||||
public function chart_rebate(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取用户返佣柱状图
|
||||
public function getUserBillBrokerage($data=''){
|
||||
return JsonService::successful(UserBill::getUserBillChart(compact('data')));
|
||||
}
|
||||
//获取用户返佣头部信息
|
||||
public function getRebateBadge($data=''){
|
||||
return JsonService::successful(UserBill::getRebateBadge(compact('data')));
|
||||
}
|
||||
//获得 返佣列表,带分页
|
||||
public function getFanList($page=1,$limit=20){
|
||||
return JsonService::successful(UserBill::getFanList(compact('page','limit')));
|
||||
}
|
||||
//获得 返佣总次数
|
||||
public function getFanCount(){
|
||||
return JsonService::successful(UserBill::getFanCount());
|
||||
}
|
||||
/**
|
||||
* 显示充值统计
|
||||
*/
|
||||
public function chart_recharge(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取用户充值柱状图和曲线图
|
||||
*/
|
||||
public function getEchartsRecharge($data=''){
|
||||
return JsonService::successful(UserBill::getEchartsRecharge(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示提现统计
|
||||
*/
|
||||
public function chart_cash(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取提现头部信息
|
||||
public function getExtractHead($data=''){
|
||||
return JsonService::successful(UserExtract::getExtractHead(compact('data')));
|
||||
}
|
||||
//会员统计
|
||||
/**
|
||||
* 显示用户统计
|
||||
*/
|
||||
public function user_chart(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取头部信息
|
||||
*
|
||||
* 人数 增长 分销人数 分销增长
|
||||
*/
|
||||
public function getBadgeList($data='',$is_promoter='',$status=''){
|
||||
return JsonService::successful(User::getBadgeList(compact('data','is_promoter','status')));
|
||||
}
|
||||
/*
|
||||
* 获取用户增长曲线图
|
||||
*
|
||||
*/
|
||||
public function getUserChartList($data='',$is_promoter='',$status=''){
|
||||
return JsonService::successful(User::getUserChartList(compact('data','is_promoter','status')));
|
||||
}
|
||||
/*
|
||||
* 获取提现分布图和提现人数金额曲线图
|
||||
*
|
||||
*/
|
||||
public function getExtractData($data=''){
|
||||
return JsonService::successful(UserExtract::getExtractList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 分销会员统计
|
||||
*
|
||||
*/
|
||||
public function user_distribution_chart(){
|
||||
$limit=10;
|
||||
$top10list=User::getUserDistributionTop10List($limit);
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'limit'=>$limit,
|
||||
'year'=>getMonth('y'),
|
||||
'commissionList'=>$top10list['commission'],
|
||||
'extractList'=>$top10list['extract'],
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 获取分销会员统计会员头部详情
|
||||
*
|
||||
*/
|
||||
public function getDistributionBadgeList($data=''){
|
||||
return JsonService::successful(User::getDistributionBadgeList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 获取分销会员统计图表数据
|
||||
*
|
||||
* $data 时间范围
|
||||
*
|
||||
*/
|
||||
public function getUserDistributionChart($data=''){
|
||||
return JsonService::successful(User::getUserDistributionChart(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 会员业务
|
||||
*/
|
||||
public function user_business_chart(){
|
||||
$limit=10;
|
||||
$top10list=User::getUserTop10List($limit);
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'limit'=>$limit,
|
||||
'year'=>getMonth('y'),
|
||||
'integralList'=>$top10list['integral'],
|
||||
'moneyList'=>$top10list['now_money'],
|
||||
'shopcountList'=>$top10list['shopcount'],
|
||||
'orderList'=>$top10list['order'],
|
||||
'lastorderList'=>$top10list['lastorder']
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 获取 会员业务的
|
||||
* 购物会员统计
|
||||
* 分销商业务人数和提现人数统计
|
||||
* 分销商业务佣金和提现金额统计
|
||||
* 曲线图
|
||||
* $data 时间
|
||||
*/
|
||||
public function getUserBusinessChart($data=''){
|
||||
return JsonService::successful(User::getUserBusinessChart(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 获取 会员业务
|
||||
* 会员总余额 分销商总佣金 分销商总佣金余额 分销商总提现佣金 本月分销商业务佣金 本月分销商佣金提现金额
|
||||
* 上月分销商业务佣金 上月分销商佣金提现金额
|
||||
* $where 查询条件
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function getUserBusinesHeade($data){
|
||||
return JsonService::successful(User::getUserBusinesHeade(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示用户属性统计
|
||||
*/
|
||||
public function user_attr(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取用户属性统计
|
||||
*/
|
||||
public function getEchartsData($data=''){
|
||||
return JsonService::successful(User::getEchartsData(compact('data')));
|
||||
}
|
||||
//排行榜
|
||||
/**
|
||||
* 显示产品排行榜
|
||||
*/
|
||||
public function ranking_saleslists(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
*获取产品排行 带分页
|
||||
*/
|
||||
public function getSaleslists($start_time='',$end_time='',$title='',$page=1,$limit=20){
|
||||
return JsonService::successlayui(StoreProduct::getSaleslists(compact('start_time','end_time','title','page','limit')));
|
||||
}
|
||||
/*
|
||||
*生成表格,并下载
|
||||
*/
|
||||
public function save_product_export($start_time='',$end_time='',$title=''){
|
||||
return JsonService::successlayui(StoreProduct::SaveProductExport(compact('start_time','end_time','title')));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的详情
|
||||
*/
|
||||
public function product_info($id=''){
|
||||
if($id=='') $this->failed('缺少商品id');
|
||||
if(!StoreProduct::be(['id'=>$id])) return $this->failed('商品不存在!');
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y'),
|
||||
'id'=>$id,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
*获取单个商品的详情头部信息
|
||||
*/
|
||||
public function getProductBadgeList($id='',$data=''){
|
||||
return JsonService::successful(StoreProduct::getProductBadgeList($id,$data));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售曲线图
|
||||
*/
|
||||
public function getProductCurve($id='',$data='',$limit=20){
|
||||
return JsonService::successful(StoreProduct::getProductCurve(compact('id','data','limit')));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售总条数
|
||||
*/
|
||||
public function getProductCount($id,$data=''){
|
||||
return JsonService::successful(StoreProduct::setWhere(compact('data'))
|
||||
->where('a.product_id',$id)
|
||||
->join('user c','c.uid=a.uid')
|
||||
->where('a.is_pay',1)
|
||||
->count());
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售列表
|
||||
*/
|
||||
public function getSalelList($data='',$id=0,$page=1,$limit=20){
|
||||
return JsonService::successful(StoreProduct::getSalelList(compact('data','id','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 显示反佣排行榜
|
||||
*/
|
||||
public function ranking_commission(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function getcommissionlist($page=1,$limit=20){
|
||||
return JsonService::successful(UserExtract::where('status',1)
|
||||
->field(['real_name','extract_price','balance'])
|
||||
->order('extract_price desc')
|
||||
->page($page,$limit)
|
||||
->select());
|
||||
}
|
||||
public function getmonthcommissionlist($page=1,$limit=20){
|
||||
return JsonService::successful(UserExtract::where('status',1)
|
||||
->whereTime('add_time','month')
|
||||
->field(['real_name','extract_price','balance'])
|
||||
->order('extract_price desc')
|
||||
->page($page,$limit)
|
||||
->select());
|
||||
}
|
||||
//获取佣金返现总条数
|
||||
public function getCommissonCount(){
|
||||
return JsonService::successful(UserExtract::where('status',1)->count());
|
||||
}
|
||||
//获取本月佣金返现条数
|
||||
public function getMonthCommissonCount(){
|
||||
return JsonService::successful(UserExtract::where('status',1)->whereTime('add_time','month')->count());
|
||||
}
|
||||
/**
|
||||
* 显示积分排行榜
|
||||
*/
|
||||
public function ranking_point(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y')
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取所有积分排行总人数
|
||||
public function getPountCount(){
|
||||
return JsonService::successful(User::where(['status'=>1])->where('integral','neq',0)->count());
|
||||
}
|
||||
//获取积分排行列表
|
||||
public function getpointList($page=1,$limit=20){
|
||||
return JsonService::successful(($list=User::where(['status'=>1])
|
||||
->where('integral','neq',0)
|
||||
->field(['nickname','integral'])
|
||||
->order('integral desc')
|
||||
->page($page,$limit)
|
||||
->select()) && count($list) ? $list->toArray():[]);
|
||||
}
|
||||
//获取本月积分排行别表
|
||||
public function getMonthpountList($page=1,$limit=20){
|
||||
return JsonService::successful(($list=User::where('status',1)
|
||||
->where('integral','neq',0)
|
||||
->whereTime('add_time','month')
|
||||
->order('integral desc')
|
||||
->field(['nickname','integral'])
|
||||
->page($page,$limit)
|
||||
->select()) && count($list) ? $list->toArray():[]);
|
||||
}
|
||||
public function getMonthPountCount(){
|
||||
return JsonService::successful(User::where('status',1)->where('integral','neq',0)->whereTime('add_time','month')->count());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 显示下级会员排行榜
|
||||
*/
|
||||
public function ranking_lower(){
|
||||
echo " 复购率 复购增长率 活跃度 活跃率 分销总金额 增长率 消费会员 非消费会员 消费排行榜 积分排行榜 余额排行榜 分销总金额排行榜 分销人数排行榜 分销余额排行榜 购物金额排行榜 购物次数排行榜 提现排行榜 ";
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品曲线图数据
|
||||
*/
|
||||
public function get_mark_echarts_product($type='',$data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getChatrdata($type,$data));
|
||||
if($model) return JsonService::successful(StoreSeckill::getChatrdata($type,$data));
|
||||
}
|
||||
/**
|
||||
* 获取拼团产品曲线图数据
|
||||
*/
|
||||
public function get_combination_echarts_product($type='',$data=''){
|
||||
return JsonService::successful(StoreCombination::getChatrdata($type,$data));
|
||||
}
|
||||
/*
|
||||
* 获取拼团销量
|
||||
*/
|
||||
public function get_combination_maxlist($data=''){
|
||||
return JsonService::successful(StoreCombination::getMaxList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 拼团盈利
|
||||
*/
|
||||
public function get_combination_profity($data=''){
|
||||
return JsonService::successful(StoreCombination::ProfityTop10(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 拼团退货
|
||||
*/
|
||||
public function get_combination_refund_list(){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(StoreCombination::getBargainRefundList($where));
|
||||
}
|
||||
/**
|
||||
* 获取销量
|
||||
*/
|
||||
public function get_mark_echarts_maxlist($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getMaxList(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::getMaxList(compact('data')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取利润
|
||||
*/
|
||||
public function get_mark_echarts_profity($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::ProfityTop10(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::ProfityTop10(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取补货的砍价产品
|
||||
*/
|
||||
public function get_mark_lack_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getLackList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getLackList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的评论
|
||||
*/
|
||||
public function get_mark_negative_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getNegativeList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getNegativeList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的退货
|
||||
*/
|
||||
public function get_mark_bargain_refund_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getBargainRefundList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getBargainRefundList($where));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
83
application/admin/controller/record/StoreStatistics.php
Normal file
83
application/admin/controller/record/StoreStatistics.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/16 0016
|
||||
* Time: 10:39
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\record;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UtilService as Util;
|
||||
use app\admin\model\record\StoreStatistics as StatisticsModel;
|
||||
|
||||
|
||||
class StoreStatistics extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['date',''],
|
||||
['export',''],
|
||||
['data','']
|
||||
],$this->request);
|
||||
$where['date']=$this->request->param('date');
|
||||
$where['data']=$this->request->param('data');
|
||||
$where['export']=$this->request->param('export');
|
||||
$trans=StatisticsModel::trans();//最近交易
|
||||
$seckill=StatisticsModel::getSeckill($where);//秒杀商品
|
||||
$ordinary=StatisticsModel::getOrdinary($where);//普通商品
|
||||
$pink=StatisticsModel::getPink($where);//拼团商品
|
||||
$recharge=StatisticsModel::getRecharge($where);//充值
|
||||
$extension=StatisticsModel::getExtension($where);//推广金
|
||||
$orderCount = [
|
||||
urlencode('微信支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('weixin'))->count(),
|
||||
urlencode('余额支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('yue'))->count(),
|
||||
urlencode('线下支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('offline'))->count(),
|
||||
];
|
||||
$Statistic = [
|
||||
['name'=>'营业额','type'=>'line','data'=>[]],
|
||||
['name'=>'支出','type'=>'line','data'=>[]],
|
||||
['name'=>'盈利','type'=>'line','data'=>[]],
|
||||
];
|
||||
$orderinfos=StatisticsModel::getOrderInfo($where);
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
$orderDays=[];
|
||||
if (empty($orderinfo)){
|
||||
$orderDays[]=date('Y-m-d',time());
|
||||
$Statistic[0]['data'][] = 0;
|
||||
$Statistic[1]['data'][] = 0;
|
||||
$Statistic[2]['data'][] = 0;
|
||||
}
|
||||
foreach($orderinfo as $info){
|
||||
$orderDays[]=$info['pay_time'];
|
||||
$Statistic[0]['data'][] = $info['total_price']+$info['pay_postage'];
|
||||
$Statistic[1]['data'][] = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$Statistic[2]['data'][] = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
}
|
||||
$price=$orderinfos['price']+$orderinfos['postage'];
|
||||
$cost=$orderinfos['deduction']+$orderinfos['coupon']+$orderinfos['cost'];
|
||||
$Consumption=StatisticsModel::getConsumption($where)['number'];
|
||||
$header=[
|
||||
['name'=>'总营业额', 'class'=>'fa-line-chart', 'value'=>'¥'.$price, 'color'=>'red'],
|
||||
['name'=>'总支出', 'class'=>'fa-area-chart', 'value'=>'¥'.($cost+$extension), 'color'=>'lazur'],
|
||||
['name'=>'总盈利', 'class'=>'fa-bar-chart', 'value'=>'¥'.bcsub($price,$cost,0), 'color'=>'navy'],
|
||||
['name'=>'新增消费', 'class'=>'fa-pie-chart', 'value'=>'¥'.($Consumption==0?0:$Consumption), 'color'=>'yellow']
|
||||
];
|
||||
$data=[
|
||||
['value'=>$orderinfos['cost'], 'name'=>'商品成本'],
|
||||
['value'=>$orderinfos['coupon'], 'name'=>'优惠券抵扣'],
|
||||
['value'=>$orderinfos['deduction'], 'name'=>'积分抵扣'],
|
||||
['value'=>$extension, 'name'=>'推广人佣金']
|
||||
];
|
||||
|
||||
$this->assign(StatisticsModel::systemTable($where));
|
||||
$this->assign(compact('where','trans','orderCount','orderPrice','orderDays','header','Statistic','ordinary','pink','recharge','data','seckill'));
|
||||
$this->assign('price',StatisticsModel::getOrderPrice($where));
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
116
application/admin/controller/routine/RoutineTemplate.php
Normal file
116
application/admin/controller/routine/RoutineTemplate.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\routine;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\routine\RoutineTemplate as RoutineTemplateModel;
|
||||
|
||||
/**
|
||||
* 小程序模板消息控制器
|
||||
* Class RoutineTemplate
|
||||
* @package app\admin\controller\routine
|
||||
*/
|
||||
class RoutineTemplate extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['status','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(RoutineTemplateModel::SystemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板消息
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号');
|
||||
$f[] = Form::input('tempid','模板ID');
|
||||
$f[] = Form::input('name','模板名');
|
||||
$f[] = Form::input('content','回复内容')->type('textarea');
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加模板消息',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempkey',
|
||||
'tempid',
|
||||
'name',
|
||||
'content',
|
||||
['status',0]
|
||||
],$request);
|
||||
if($data['tempkey'] == '') return Json::fail('请输入模板编号');
|
||||
if($data['tempkey'] != '' && RoutineTemplateModel::be($data['tempkey'],'tempkey'))
|
||||
return Json::fail('请输入模板编号已存在,请重新输入');
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if($data['name'] == '') return Json::fail('请输入模板名');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$data['add_time'] = time();
|
||||
RoutineTemplateModel::set($data);
|
||||
return Json::successful('添加模板消息成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑模板消息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = RoutineTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号',$product->getData('tempkey'))->disabled(1);
|
||||
$f[] = Form::input('name','模板名',$product->getData('name'))->disabled(1);
|
||||
$f[] = Form::input('tempid','模板ID',$product->getData('tempid'));
|
||||
$f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑模板消息',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempid',
|
||||
['status',0]
|
||||
],$request);
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = RoutineTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
RoutineTemplateModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板消息
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!RoutineTemplateModel::del($id))
|
||||
return Json::fail(RoutineTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
212
application/admin/controller/setting/SystemAdmin.php
Normal file
212
application/admin/controller/setting/SystemAdmin.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\JsonService;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use think\Request;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemAdmin as AdminModel;
|
||||
|
||||
/**
|
||||
* 管理员列表控制器
|
||||
* Class SystemAdmin
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemAdmin extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$admin = $this->adminInfo;
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['roles',''],
|
||||
['level',bcadd($admin->level,1,0)]
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('role',SystemRole::getRole(bcadd($admin->level,1,0)));
|
||||
$this->assign(AdminModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$admin = $this->adminInfo;
|
||||
$f = array();
|
||||
$f[] = Form::input('account','管理员账号');
|
||||
$f[] = Form::input('pwd','管理员密码')->type('password');
|
||||
$f[] = Form::input('conf_pwd','确认密码')->type('password');
|
||||
$f[] = Form::input('real_name','管理员姓名');
|
||||
$f[] = Form::select('roles','管理员身份')->setOptions(function ()use($admin){
|
||||
$list = SystemRole::getRole(bcadd($admin->level,1,0));
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加管理员',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'account',
|
||||
'conf_pwd',
|
||||
'pwd',
|
||||
'real_name',
|
||||
['roles',[]],
|
||||
['status',0]
|
||||
],$request);
|
||||
if(!$data['account']) return Json::fail('请输入管理员账号');
|
||||
if(!$data['roles']) return Json::fail('请选择至少一个管理员身份');
|
||||
if(!$data['pwd']) return Json::fail('请输入管理员登陆密码');
|
||||
if($data['pwd'] != $data['conf_pwd']) return Json::fail('两次输入密码不想同');
|
||||
if(AdminModel::be($data['account'],'account')) return Json::fail('管理员账号已存在');
|
||||
$data['pwd'] = md5($data['pwd']);
|
||||
unset($data['conf_pwd']);
|
||||
$data['level'] = $this->adminInfo['level'] + 1;
|
||||
AdminModel::set($data);
|
||||
return Json::successful('添加管理员成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('参数错误');
|
||||
$admin = AdminModel::get($id);
|
||||
if(!$admin) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('account','管理员账号',$admin->account);
|
||||
$f[] = Form::input('pwd','管理员密码')->type('password');
|
||||
$f[] = Form::input('conf_pwd','确认密码')->type('password');
|
||||
$f[] = Form::input('real_name','管理员姓名',$admin->real_name);
|
||||
$f[] = Form::select('roles','管理员身份',explode(',',$admin->roles))->setOptions(function ()use($admin){
|
||||
$list = SystemRole::getRole($admin->level);
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑管理员',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'account',
|
||||
'conf_pwd',
|
||||
'pwd',
|
||||
'real_name',
|
||||
['roles',[]],
|
||||
['status',0]
|
||||
],$request);
|
||||
if(!$data['account']) return Json::fail('请输入管理员账号');
|
||||
if(!$data['roles']) return Json::fail('请选择至少一个管理员身份');
|
||||
if(!$data['pwd'])
|
||||
unset($data['pwd']);
|
||||
else{
|
||||
if(isset($data['pwd']) && $data['pwd'] != $data['conf_pwd']) return Json::fail('两次输入密码不想同');
|
||||
$data['pwd'] = md5($data['pwd']);
|
||||
}
|
||||
if(AdminModel::where('account',$data['account'])->where('id','<>',$id)->count()) return Json::fail('管理员账号已存在');
|
||||
unset($data['conf_pwd']);
|
||||
AdminModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id)
|
||||
return JsonService::fail('删除失败!');
|
||||
if(AdminModel::edit(['is_del'=>1,'status'=>0],$id,'id'))
|
||||
return JsonService::successful('删除成功!');
|
||||
else
|
||||
return JsonService::fail('删除失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人资料 展示
|
||||
* */
|
||||
public function adminInfo(){
|
||||
$adminInfo = $this->adminInfo;//获取当前登录的管理员
|
||||
$this->assign('adminInfo',$adminInfo);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function setAdminInfo(Request $request){
|
||||
$adminInfo = $this->adminInfo;//获取当前登录的管理员
|
||||
if($request->isPost()){
|
||||
$data = Util::postMore([
|
||||
['new_pwd',''],
|
||||
['new_pwd_ok',''],
|
||||
['pwd',''],
|
||||
'real_name',
|
||||
],$request);
|
||||
// if ($data['pwd'] == '') unset($data['pwd']);
|
||||
if($data['pwd'] != ''){
|
||||
$pwd = md5($data['pwd']);
|
||||
if($adminInfo['pwd'] != $pwd) return Json::fail('原始密码错误');
|
||||
}
|
||||
if($data['new_pwd'] != ''){
|
||||
if(!$data['new_pwd_ok']) return Json::fail('请输入确认新密码');
|
||||
if($data['new_pwd'] != $data['new_pwd_ok']) return Json::fail('俩次密码不一样');
|
||||
}
|
||||
if($data['pwd'] != '' && $data['new_pwd'] != ''){
|
||||
$data['pwd'] = md5($data['new_pwd']);
|
||||
}else{
|
||||
unset($data['pwd']);
|
||||
}
|
||||
unset($data['new_pwd']);
|
||||
unset($data['new_pwd_ok']);
|
||||
AdminModel::edit($data,$adminInfo['id']);
|
||||
return Json::successful('修改成功!,请重新登录');
|
||||
}
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/setting/SystemConfig.php
Normal file
1
application/admin/controller/setting/SystemConfig.php
Normal file
File diff suppressed because one or more lines are too long
1
application/admin/controller/setting/SystemConfigTab.php
Normal file
1
application/admin/controller/setting/SystemConfigTab.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
namespace app\admin\controller\setting;
use think\Url;
use service\FormBuilder as Form;
use think\Request;
use service\UtilService as Util;
use service\JsonService as Json;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemConfigTab as ConfigTabModel;
use app\admin\model\system\SystemConfig as ConfigModel;
/**
* 配置分类控制器
* Class SystemConfigTab
* @package app\admin\controller\system
*/
class SystemConfigTab extends AuthController
{
/**
* 子子段
* @return mixed|\think\response\Json
*/
public function sonConfigTab(){
$tab_id = input('tab_id');
if(!$tab_id) return Json::fail('参数错误');
$this->assign('tab_id',$tab_id);
$list = ConfigModel::getAll($tab_id);
foreach ($list as $k=>$v){
$list[$k]['value'] = json_decode($v['value'],true);
if($v['type'] == 'radio' || $v['type'] == 'checkbox'){
$list[$k]['value'] = ConfigTabModel::getRadioOrCheckboxValueInfo($v['menu_name'],$v['value']);
}
if($v['type'] == 'upload' && !empty($v['value'])){
if($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = explode(',',$v['value']);
}
}
$this->assign('list',$list);
return $this->fetch();
}
/**
* 基础配置
* @return mixed
*/
public function index(){
$where = Util::getMore([
['status',''],
['title',''],
],$this->request);
$this->assign('where',$where);
$this->assign(ConfigTabModel::getSystemConfigTabPage($where));
return $this->fetch();
}
/**
* 添加配置分类
* @return mixed
*/
public function create(){
$form = Form::create(Url::build('save'),[
Form::input('title','分类昵称'),
Form::input('eng_title','分类字段'),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic'),
Form::radio('type','类型',0)->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* 保存分类名称
* @param Request $request
* @return \think\response\Json
*/
public function save(Request $request){
$data = Util::postMore([
'eng_title',
'status',
'title',
'icon',
'type'],$request);
if(!$data['title']) return Json::fail('请输入按钮名称');
ConfigTabModel::set($data);
return Json::successful('添加菜单成功!');
}
/**
* 修改分类
* @param $id
* @return mixed
*/
public function edit($id){
$menu = ConfigTabModel::get($id)->getData();
if(!$menu) return Json::fail('数据不存在!');
$form = Form::create(Url::build('update',array('id'=>$id)),[
Form::input('title','分类昵称',$menu['title']),
Form::input('eng_title','分类字段',$menu['eng_title']),
Form::frameInputOne('icon','图标',Url::build('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic'),
Form::radio('type','类型',$menu['type'])->options([['value'=>0,'label'=>'系统'],['value'=>1,'label'=>'公众号'],['value'=>2,'label'=>'小程序'],['value'=>3,'label'=>'其它']]),
Form::radio('status','状态',$menu['status'])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
]);
$form->setMethod('post')->setTitle('添加分类配置');
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
/**
* @param Request $request
* @param $id
* @return \think\response\Json
*/
public function update(Request $request, $id)
{
$data = Util::postMore(['title','status','eng_title','icon','type'],$request);
if(!$data['title']) return Json::fail('请输入分类昵称');
if(!$data['eng_title']) return Json::fail('请输入分类字段');
if(!ConfigTabModel::get($id)) return Json::fail('编辑的记录不存在!');
ConfigTabModel::edit($data,$id);
return Json::successful('修改成功!');
}
/**
* @param $id
* @return \think\response\Json
*/
public function delete($id){
if(!ConfigTabModel::del($id))
return Json::fail(ConfigTabModel::getErrorInfo('删除失败,请稍候再试!'));
else
return Json::successful('删除成功!');
}
}
|
||||
106
application/admin/controller/setting/SystemGroup.php
Normal file
106
application/admin/controller/setting/SystemGroup.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use EasyWeChat\ShakeAround\Group;
|
||||
use service\UtilService as Util;
|
||||
|
||||
use service\JsonService as Json;
|
||||
|
||||
use think\Request;
|
||||
|
||||
use think\Url;
|
||||
|
||||
use app\admin\model\system\SystemGroup as GroupModel;
|
||||
|
||||
use app\admin\model\system\SystemGroupData as GroupDataModel;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
|
||||
/**
|
||||
* 组合数据控制器
|
||||
* Class SystemGroup
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemGroup extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign(GroupModel::page());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->assign(['title'=>'添加数据组','save'=>Url::build('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = Util::postMore([
|
||||
['name',''],
|
||||
['config_name',''],
|
||||
['info',''],
|
||||
['typelist',[]],
|
||||
],$this->request);
|
||||
|
||||
//数据组名称判断
|
||||
if(!$params['name'])return Json::fail('请输入数据组名称!');
|
||||
if(!$params['config_name'])return Json::fail('请输入配置名称!');
|
||||
if(GroupModel::be($params['config_name'],'config_name')) return Json::fail('数据关键字已存在!');
|
||||
$data["name"] = $params['name'];
|
||||
$data["config_name"] = $params['config_name'];
|
||||
$data["info"] = $params['info'];
|
||||
//字段信息判断
|
||||
if(!count($params['typelist']))
|
||||
return Json::fail('字段至少存在一个!');
|
||||
else{
|
||||
$validate = ["name","type","title","description"];
|
||||
foreach ($params["typelist"] as $key => $value) {
|
||||
foreach ($value as $name => $field) {
|
||||
if(empty($field["value"]) && in_array($name,$validate))
|
||||
return Json::fail("字段".($key + 1).":".$field["placeholder"]."不能为空!");
|
||||
else
|
||||
$data["fields"][$key][$name] = $field["value"];
|
||||
}
|
||||
}
|
||||
}
|
||||
$data["fields"] = json_encode($data["fields"]);
|
||||
GroupModel::set($data);
|
||||
return Json::successful('添加数据组成功!');
|
||||
}
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!GroupModel::del($id))
|
||||
return Json::fail(GroupModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else{
|
||||
GroupDataModel::del(["gid"=>$id]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
}
|
||||
220
application/admin/controller/setting/SystemGroupData.php
Normal file
220
application/admin/controller/setting/SystemGroupData.php
Normal file
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
use app\admin\common\Error;
|
||||
use service\FormBuilder as Form;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use service\UtilService as Util;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemGroup as GroupModel;
|
||||
use app\admin\model\system\SystemGroupData as GroupDataModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
/**
|
||||
* 数据列表控制器 在组合数据中
|
||||
* Class SystemGroupData
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemGroupData extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index($gid)
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(compact("gid"));
|
||||
$this->assign(GroupModel::getField($gid));
|
||||
$where['gid'] = $gid;
|
||||
$this->assign(GroupDataModel::getList($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create($gid)
|
||||
{
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$f = array();
|
||||
foreach ($Fields["fields"] as $key => $value) {
|
||||
if($value["type"] == "input")
|
||||
$f[] = Form::input($value["title"],$value["name"]);
|
||||
else if($value["type"] == "textarea")
|
||||
$f[] = Form::input($value["title"],$value["name"])->type('textarea')->placeholder($value['param']);
|
||||
else if($value["type"] == "radio") {
|
||||
$params = explode("-", $value["param"]);
|
||||
foreach ($params as $index => $param) {
|
||||
$info[$index]["value"] = $param;
|
||||
$info[$index]["label"] = $param;
|
||||
}
|
||||
$f[] = Form::radio($value["title"],$value["name"],$info[0]["value"])->options($info);
|
||||
}else if($value["type"] == "checkbox"){
|
||||
$params = explode("-",$value["param"]);
|
||||
foreach ($params as $index => $param) {
|
||||
$info[$index]["value"] = $param;
|
||||
$info[$index]["label"] = $param;
|
||||
}
|
||||
$f[] = Form::checkbox($value["title"],$value["name"],$info[0])->options($info);
|
||||
}else if($value["type"] == "upload")
|
||||
$f[] = Form::frameImageOne($value["title"],$value["name"],Url::build('admin/widget.images/index',array('fodder'=>$value["title"])))->icon('image');
|
||||
else if($value['type'] == 'uploads')
|
||||
$f[] = Form::frameImages($value["title"],$value["name"],Url::build('admin/widget.images/index',array('fodder'=>$value["title"])))->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
|
||||
}
|
||||
$f[] = Form::number('sort','排序',1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('添加数据',$f,Url::build('save',compact('gid')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request,$gid)
|
||||
{
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$params = $request->post();
|
||||
foreach ($params as $key => $param) {
|
||||
foreach ($Fields['fields'] as $index => $field) {
|
||||
if($key == $field["title"]){
|
||||
if($param == "" || count($param) == 0)
|
||||
return Json::fail($field["name"]."不能为空!");
|
||||
else{
|
||||
$value[$key]["type"] = $field["type"];
|
||||
$value[$key]["value"] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = array("gid"=>$gid,"add_time"=>time(),"value"=>json_encode($value),"sort"=>$params["sort"],"status"=>$params["status"]);
|
||||
GroupDataModel::set($data);
|
||||
return Json::successful('添加数据成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($gid,$id)
|
||||
{
|
||||
$GroupData = GroupDataModel::get($id);
|
||||
$GroupDataValue = json_decode($GroupData["value"],true);
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$f = array();
|
||||
foreach ($Fields["fields"] as $key => $value) {
|
||||
if($value["type"] == "input") $f[] = Form::input($value["title"],$value["name"],$GroupDataValue[$value["title"]]["value"]);
|
||||
if($value["type"] == "textarea") $f[] = Form::input($value["title"],$value["name"],$GroupDataValue[$value["title"]]["value"])->type('textarea');
|
||||
if($value["type"] == "radio"){
|
||||
$params = explode("-",$value["param"]);
|
||||
foreach ($params as $index => $param) {
|
||||
$info[$index]["value"] = $param;
|
||||
$info[$index]["label"] = $param;
|
||||
}
|
||||
$f[] = Form::radio($value["title"],$value["name"],$GroupDataValue[$value["title"]]["value"])->options($info);
|
||||
}
|
||||
if($value["type"] == "checkbox"){
|
||||
$params = explode("-",$value["param"]);
|
||||
foreach ($params as $index => $param) {
|
||||
$info[$index]["value"] = $param;
|
||||
$info[$index]["label"] = $param;
|
||||
}
|
||||
$f[] = Form::checkbox($value["title"],$value["name"],$GroupDataValue[$value["title"]]["value"])->options($info);
|
||||
}
|
||||
if($value["type"] == "upload"){
|
||||
$image = is_string($GroupDataValue[$value["title"]]["value"])?$GroupDataValue[$value["title"]]["value"]:$GroupDataValue[$value["title"]]["value"][0];
|
||||
$f[] = Form::frameImageOne($value["title"],$value["name"],Url::build('admin/widget.images/index',array('fodder'=>$value["title"])),$image)->icon('image');
|
||||
}
|
||||
else if($value['type'] == 'uploads') {
|
||||
$f[] = Form::frameImages($value["title"], $value["name"], Url::build('admin/widget.images/index', array('fodder' => $value["title"])), $GroupDataValue[$value["title"]]["value"])->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
|
||||
}
|
||||
}
|
||||
$f[] = Form::input('sort','排序',$GroupData["sort"]);
|
||||
$f[] = Form::radio('status','状态',$GroupData["status"])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$GroupData = GroupDataModel::get($id);
|
||||
$Fields = GroupModel::getField($GroupData["gid"]);
|
||||
$params = $request->post();
|
||||
foreach ($params as $key => $param) {
|
||||
foreach ($Fields['fields'] as $index => $field) {
|
||||
if($key == $field["title"]){
|
||||
if($param == "" || count($param) == 0)
|
||||
return Json::fail($field["name"]."不能为空!");
|
||||
else{
|
||||
$value[$key]["type"] = $field["type"];
|
||||
$value[$key]["value"] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = array("value"=>json_encode($value),"sort"=>$params["sort"],"status"=>$params["status"]);
|
||||
GroupDataModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!GroupDataModel::del($id))
|
||||
return Json::fail(GroupDataModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
175
application/admin/controller/setting/SystemMenus.php
Normal file
175
application/admin/controller/setting/SystemMenus.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use service\FormBuilder as Form;
|
||||
use traits\CurdControllerTrait;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemMenus as MenusModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/**
|
||||
* 菜单管理控制器
|
||||
* Class SystemMenus
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemMenus extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
|
||||
public $bindModel = MenusModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pid = $this->request->param('pid')?$this->request->param('pid'):0;
|
||||
$params = Util::getMore([
|
||||
['is_show',''],
|
||||
// ['access',''],
|
||||
['keyword',''],
|
||||
['pid',$pid]
|
||||
],$this->request);
|
||||
$this->assign(MenusModel::getAdminPage($params));
|
||||
$this->assign(compact('params'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create($cid = 0)
|
||||
{
|
||||
$form = Form::create(Url::build('save'),[
|
||||
Form::input('menu_name','按钮名称')->required('按钮名称必填'),
|
||||
Form::select('pid','父级id',$cid)->setOptions(function(){
|
||||
$list = (Util::sortListTier(MenusModel::all()->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','控制器名'),
|
||||
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','是否菜单',1)->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']]),
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('添加权限');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'menu_name',
|
||||
'controller',
|
||||
['module','admin'],
|
||||
'action',
|
||||
'icon',
|
||||
'params',
|
||||
['pid',0],
|
||||
['sort',0],
|
||||
['is_show',0],
|
||||
['access',1]],$request);
|
||||
if(!$data['menu_name']) return Json::fail('请输入按钮名称');
|
||||
MenusModel::set($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$menu = MenusModel::get($id);
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$form = Form::create(Url::build('update',array('id'=>$id)),[
|
||||
Form::input('menu_name','按钮名称',$menu['menu_name']),
|
||||
Form::select('pid','父级id',(string)$menu->getData('pid'))->setOptions(function()use($id){
|
||||
$list = (Util::sortListTier(MenusModel::where('id','<>',$id)->select()->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'],['label'=>'总后台1','value'=>'admin1']]),
|
||||
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'=>'显示(菜单只显示三级)']])
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('编辑权限');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'menu_name',
|
||||
'controller',
|
||||
['module','admin'],
|
||||
'action',
|
||||
'params',
|
||||
'icon',
|
||||
['sort',0],
|
||||
['pid',0],
|
||||
['is_show',0],
|
||||
['access',1]],$request);
|
||||
if(!$data['menu_name']) return Json::fail('请输入按钮名称');
|
||||
if(!MenusModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
MenusModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('参数错误,请重新打开');
|
||||
$res = MenusModel::delMenu($id);
|
||||
if(!$res)
|
||||
return Json::fail(MenusModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
}
|
||||
1
application/admin/controller/setting/SystemNotice.php
Normal file
1
application/admin/controller/setting/SystemNotice.php
Normal file
File diff suppressed because one or more lines are too long
145
application/admin/controller/setting/SystemRole.php
Normal file
145
application/admin/controller/setting/SystemRole.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemRole as RoleModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/*
|
||||
* 身份管理 控制器
|
||||
* */
|
||||
class SystemRole extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['role_name',''],
|
||||
],$this->request);
|
||||
$where['level'] = $this->adminInfo['level'];
|
||||
$this->assign('where',$where);
|
||||
$this->assign(RoleModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
|
||||
// if(0 == 0){
|
||||
// }else{
|
||||
// dump($this->adminInfo['level']);
|
||||
// }
|
||||
$menus = $this->adminInfo['level'] == 0 ? SystemMenus::ruleList() : SystemMenus::rolesByRuleList($this->adminInfo['roles']);
|
||||
$this->assign(['menus'=>json($menus)->getContent(),'saveUrl'=>Url::build('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'role_name',
|
||||
['status',0],
|
||||
['checked_menus',[],'','rules']
|
||||
],$request);
|
||||
if(!$data['role_name']) return Json::fail('请输入身份名称');
|
||||
if(!is_array($data['rules']) || !count($data['rules']) )
|
||||
return Json::fail('请选择最少一个权限');
|
||||
foreach ($data['rules'] as $v){
|
||||
$pid = SystemMenus::where('id',$v)->value('pid');
|
||||
if(!in_array($pid,$data['rules'])) $data['rules'][] = $pid;
|
||||
}
|
||||
$data['rules'] = implode(',',$data['rules']);
|
||||
$data['level'] = $this->adminInfo['level']+1;
|
||||
RoleModel::set($data);
|
||||
return Json::successful('添加身份成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
$role = RoleModel::get($id);
|
||||
$menus = $this->adminInfo['level'] == 0 ? SystemMenus::ruleList() : SystemMenus::rolesByRuleList($this->adminInfo['roles']);
|
||||
$this->assign(['role'=>$role->toJson(),'menus'=>json($menus)->getContent(),'updateUrl'=>Url::build('update',array('id'=>$id))]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'role_name',
|
||||
['status',0],
|
||||
['checked_menus',[],'','rules']
|
||||
],$request);
|
||||
if(!$data['role_name']) return Json::fail('请输入身份名称');
|
||||
if(!is_array($data['rules']) || !count($data['rules']) )
|
||||
return Json::fail('请选择最少一个权限');
|
||||
foreach ($data['rules'] as $v){
|
||||
$pid = SystemMenus::where('id',$v)->value('pid');
|
||||
if(!in_array($pid,$data['rules'])) $data['rules'][] = $pid;
|
||||
}
|
||||
$data['rules'] = implode(',',$data['rules']);
|
||||
RoleModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!RoleModel::del($id))
|
||||
return Json::fail(RoleModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
180
application/admin/controller/store/StoreCategory.php
Normal file
180
application/admin/controller/store/StoreCategory.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 产品分类控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCategory extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pid = $this->request->param('pid')?$this->request->param('pid'):0;
|
||||
$where = Util::getMore([
|
||||
['is_show',''],
|
||||
['pid',$pid],
|
||||
['cate_name',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('cate',CategoryModel::getTierList());
|
||||
$this->assign(CategoryModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$form = Form::create(Url::build('save'),[
|
||||
Form::select('pid','父级')->setOptions(function(){
|
||||
$list = CategoryModel::getTierList();
|
||||
$menus = [['value'=>0,'label'=>'顶级菜单']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1),
|
||||
Form::input('cate_name','分类名称'),
|
||||
Form::frameImageOne('pic','分类图标',Url::build('admin/widget.images/index',array('fodder'=>'pic')))->icon('image'),
|
||||
Form::number('sort','排序'),
|
||||
Form::radio('is_show','状态',1)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('添加分类');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'cate_name',
|
||||
['pic',[]],
|
||||
'sort',
|
||||
['is_show',0]
|
||||
],$request);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['cate_name']) return Json::fail('请输入分类名称');
|
||||
if(count($data['pic'])<1) return Json::fail('请上传分类图标');
|
||||
if($data['sort'] <0 ) $data['sort'] = 0;
|
||||
$data['pic'] = $data['pic'][0];
|
||||
$data['add_time'] = time();
|
||||
CategoryModel::set($data);
|
||||
return Json::successful('添加分类成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$c = CategoryModel::get($id);
|
||||
if(!$c) return Json::fail('数据不存在!');
|
||||
$form = Form::create(Url::build('update',array('id'=>$id)),[
|
||||
Form::select('pid','父级',(string)$c->getData('pid'))->setOptions(function() use($id){
|
||||
$list = CategoryModel::getTierList(CategoryModel::where('id','<>',$id));
|
||||
// $list = (Util::sortListTier(CategoryModel::where('id','<>',$id)->select()->toArray(),'顶级','pid','cate_name'));
|
||||
$menus = [['value'=>0,'label'=>'顶级菜单']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name']];
|
||||
}
|
||||
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::number('sort','排序',$c->getData('sort')),
|
||||
Form::radio('is_show','状态',$c->getData('is_show'))->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('添加分类');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'cate_name',
|
||||
['pic',[]],
|
||||
'sort',
|
||||
['is_show',0]
|
||||
],$request);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['cate_name']) return Json::fail('请输入分类名称');
|
||||
if(count($data['pic'])<1) return Json::fail('请上传分类图标');
|
||||
if($data['sort'] <0 ) $data['sort'] = 0;
|
||||
$data['pic'] = $data['pic'][0];
|
||||
CategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!CategoryModel::delCategory($id))
|
||||
return Json::fail(CategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/store/StoreInfoMana.php
Normal file
1
application/admin/controller/store/StoreInfoMana.php
Normal file
File diff suppressed because one or more lines are too long
466
application/admin/controller/store/StoreProduct.php
Normal file
466
application/admin/controller/store/StoreProduct.php
Normal file
@ -0,0 +1,466 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use app\admin\model\store\StoreProductAttr;
|
||||
use app\admin\model\store\StoreProductAttrResult;
|
||||
use app\admin\model\store\StoreProductRelation;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use traits\CurdControllerTrait;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use app\admin\model\store\StoreProduct as ProductModel;
|
||||
use think\Url;
|
||||
use app\admin\model\ump\StoreSeckill as StoreSeckillModel;
|
||||
use app\admin\model\order\StoreOrder as StoreOrderModel;
|
||||
use app\admin\model\ump\StoreBargain as StoreBargainModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
|
||||
/**
|
||||
* 产品管理
|
||||
* Class StoreProduct
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreProduct extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = ProductModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['type',$this->request->param('type')],
|
||||
['cate_id',''],
|
||||
['is_show',''],
|
||||
['store_name',''],
|
||||
['sales',''],
|
||||
['export',0]
|
||||
],$this->request);
|
||||
$this->assign('cate',CategoryModel::getTierList());
|
||||
|
||||
//出售中产品
|
||||
$data = ['is_show'=>1,'is_del'=>0];
|
||||
$onsale = ProductModel::where($data)->count();
|
||||
//待上架产品
|
||||
$data = ['is_show'=>0,'is_del'=>0];
|
||||
$forsale = ProductModel::where($data)->count();
|
||||
//仓库中产品
|
||||
$data = ['is_del'=>0];
|
||||
$warehouse = ProductModel::where($data)->count();
|
||||
//已经售馨产品
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>0];
|
||||
$outofstock = ProductModel::alias('p')
|
||||
->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT')
|
||||
->where($data)->count();
|
||||
//警戒库存
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>['elt',1]];
|
||||
$policeforce = ProductModel::alias('p')
|
||||
->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT')
|
||||
->where($data)->count();
|
||||
//回收站
|
||||
$data = ['is_del'=>1];
|
||||
$recycle = ProductModel::where($data)->count();
|
||||
$this->assign(compact('where','onsale','forsale','warehouse','outofstock','policeforce','recycle'));
|
||||
$this->assign(ProductModel::systemPage($where,$this->adminInfo));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// $this->assign(['title'=>'添加产品','action'=>Url::build('save'),'rules'=>$this->rules()->getContent()]);
|
||||
// return $this->fetch('public/common_form');
|
||||
$field = [
|
||||
Form::select('cate_id','产品分类')->setOptions(function(){
|
||||
$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];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1)->multiple(1),
|
||||
Form::input('store_name','产品名称')->col(Form::col(24)),
|
||||
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('550px'),
|
||||
Form::frameImages('slider_image','产品轮播图(640*640px)',Url::build('admin/widget.images/index',array('fodder'=>'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0),
|
||||
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),
|
||||
Form::number('postage','邮费')->min(0)->col(Form::col(8)),
|
||||
Form::number('sales','销量')->min(0)->precision(0)->col(8),
|
||||
Form::number('ficti','虚拟销量')->min(0)->precision(0)->col(8),
|
||||
Form::number('stock','库存')->min(0)->precision(0)->col(8),
|
||||
Form::number('cost','产品成本价')->min(0)->col(8),
|
||||
Form::number('sort','排序')->col(8),
|
||||
Form::radio('is_show','产品状态',0)->options([['label'=>'上架','value'=>1],['label'=>'下架','value'=>0]])->col(8),
|
||||
Form::radio('is_hot','热卖单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_benefit','促销单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_best','精品推荐',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_new','首发新品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_postage','是否包邮',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8)
|
||||
];
|
||||
$form = Form::create(Url::build('save'));
|
||||
$form->setMethod('post')->setTitle('添加产品')->components($field)->setSuccessScript('parent.$(".J_iframe:visible")[0].contentWindow.location.reload();');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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)]);
|
||||
else
|
||||
return Json::fail($res->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['cate_id',[]],
|
||||
'store_name',
|
||||
'store_info',
|
||||
'keyword',
|
||||
['unit_name','件'],
|
||||
['image',[]],
|
||||
['slider_image',[]],
|
||||
'postage',
|
||||
'ot_price',
|
||||
'price',
|
||||
'sort',
|
||||
'stock',
|
||||
'sales',
|
||||
'ficti',
|
||||
['give_integral',0],
|
||||
['is_show',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['is_benefit',0],
|
||||
['is_best',0],
|
||||
['is_new',0],
|
||||
['mer_use',0],
|
||||
['is_postage',0],
|
||||
],$request);
|
||||
if(count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
||||
$data['cate_id'] = implode(',',$data['cate_id']);
|
||||
if(!$data['store_name']) return Json::fail('请输入产品名称');
|
||||
// if(!$data['store_info']) return Json::fail('请输入产品简介');
|
||||
// if(!$data['keyword']) return Json::fail('请输入产品关键字');
|
||||
if(count($data['image'])<1) return Json::fail('请上传产品图片');
|
||||
if(count($data['slider_image'])<1) return Json::fail('请上传产品轮播图');
|
||||
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
|
||||
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
|
||||
if($data['postage'] == '' || $data['postage'] < 0) return Json::fail('请输入邮费');
|
||||
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
||||
if($data['cost'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品成本价');
|
||||
if($data['sales'] == '' || $data['sales'] < 0) return Json::fail('请输入销量');
|
||||
if($data['give_integral'] < 0) return Json::fail('请输入赠送积分');
|
||||
$data['image'] = $data['image'][0];
|
||||
$data['slider_image'] = json_encode($data['slider_image']);
|
||||
$data['add_time'] = time();
|
||||
$data['description'] = '';
|
||||
ProductModel::set($data);
|
||||
return Json::successful('添加产品成功!');
|
||||
}
|
||||
|
||||
|
||||
public function edit_content($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'content'=>ProductModel::where('id',$id)->value('description'),
|
||||
'field'=>'description',
|
||||
'action'=>Url::build('change_field',['id'=>$id,'field'=>'description'])
|
||||
]);
|
||||
return $this->fetch('public/edit_content');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$form = Form::create(Url::build('update',array('id'=>$id)),[
|
||||
Form::select('cate_id','产品分类',explode(',',$product->getData('cate_id')))->setOptions(function(){
|
||||
$list = CategoryModel::getTierList();
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name'],'disabled'=>$menu['pid']== 0];//,'disabled'=>$menu['pid']== 0];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1)->multiple(1),
|
||||
Form::input('store_name','产品名称',$product->getData('store_name')),
|
||||
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('550px'),
|
||||
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'),
|
||||
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),
|
||||
Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(8),
|
||||
Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(8),
|
||||
Form::number('ficti','虚拟销量',$product->getData('ficti'))->min(0)->precision(0)->col(8),
|
||||
Form::number('stock','库存',ProductModel::getStock($id)>0?ProductModel::getStock($id):$product->getData('stock'))->min(0)->precision(0)->col(8),
|
||||
Form::number('cost','产品成本价',$product->getData('cost'))->min(0)->col(8),
|
||||
Form::number('sort','排序',$product->getData('sort'))->col(8),
|
||||
Form::radio('is_show','产品状态',$product->getData('is_show'))->options([['label'=>'上架','value'=>1],['label'=>'下架','value'=>0]])->col(8),
|
||||
Form::radio('is_hot','热卖单品',$product->getData('is_hot'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_benefit','促销单品',$product->getData('is_benefit'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_best','精品推荐',$product->getData('is_best'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_new','首发新品',$product->getData('is_new'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8)
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('编辑产品')->setSuccessScript('parent.$(".J_iframe:visible")[0].contentWindow.location.reload();');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['cate_id',[]],
|
||||
'store_name',
|
||||
'store_info',
|
||||
'keyword',
|
||||
['unit_name','件'],
|
||||
['image',[]],
|
||||
['slider_image',[]],
|
||||
'postage',
|
||||
'ot_price',
|
||||
'price',
|
||||
'sort',
|
||||
'stock',
|
||||
'sales',
|
||||
'ficti',
|
||||
['give_integral',0],
|
||||
['is_show',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['is_benefit',0],
|
||||
['is_best',0],
|
||||
['is_new',0],
|
||||
['mer_use',0],
|
||||
['is_postage',0],
|
||||
],$request);
|
||||
if(count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
||||
$data['cate_id'] = implode(',',$data['cate_id']);
|
||||
if(!$data['store_name']) return Json::fail('请输入产品名称');
|
||||
// if(!$data['store_info']) return Json::fail('请输入产品简介');
|
||||
// if(!$data['keyword']) 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($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
|
||||
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
|
||||
if($data['postage'] == '' || $data['postage'] < 0) return Json::fail('请输入邮费');
|
||||
if($data['cost'] == '' || $data['cost'] < 0) return Json::fail('请输入产品成本价');
|
||||
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
||||
if($data['sales'] == '' || $data['sales'] < 0) return Json::fail('请输入销量');
|
||||
if($data['give_integral'] < 0) return Json::fail('请输入赠送积分');
|
||||
$data['image'] = $data['image'][0];
|
||||
$data['slider_image'] = json_encode($data['slider_image']);
|
||||
ProductModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
public function attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在!');
|
||||
$result = StoreProductAttrResult::getResult($id);
|
||||
$image = ProductModel::where('id',$id)->value('image');
|
||||
$this->assign(compact('id','result','product','image'));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 生成属性
|
||||
* @param int $id
|
||||
*/
|
||||
public function is_format_attr($id = 0){
|
||||
if(!$id) return Json::fail('产品不存在');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('产品不存在');
|
||||
$attrFormat = attrFormat($attr)[1];
|
||||
if(count($detail)){
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
foreach ($detail as $kk=>$vv){
|
||||
if($v['detail'] == $vv['detail']){
|
||||
$attrFormat[$k]['price'] = $vv['price'];
|
||||
$attrFormat[$k]['cost'] = isset($vv['cost']) ? $vv['cost'] : $product['cost'];
|
||||
$attrFormat[$k]['sales'] = $vv['sales'];
|
||||
$attrFormat[$k]['pic'] = $vv['pic'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
break;
|
||||
}else{
|
||||
$attrFormat[$k]['cost'] = $product['cost'];
|
||||
$attrFormat[$k]['price'] = '';
|
||||
$attrFormat[$k]['sales'] = '';
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
$attrFormat[$k]['cost'] = $product['cost'];
|
||||
$attrFormat[$k]['price'] = $product['price'];
|
||||
$attrFormat[$k]['sales'] = $product['stock'];
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
}
|
||||
}
|
||||
return Json::successful($attrFormat);
|
||||
}
|
||||
|
||||
public function set_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$res = StoreProductAttr::createProductAttr($attr,$detail,$id);
|
||||
if($res)
|
||||
return $this->successful('编辑属性成功!');
|
||||
else
|
||||
return $this->failed(StoreProductAttr::getErrorInfo());
|
||||
}
|
||||
|
||||
public function clear_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
if(false !== StoreProductAttr::clearProductAttr($id) && false !== StoreProductAttrResult::clearResult($id))
|
||||
return $this->successful('清空产品属性成功!');
|
||||
else
|
||||
return $this->failed(StoreProductAttr::getErrorInfo('清空产品属性失败!'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$data['is_del'] = 1;
|
||||
if(!ProductModel::edit($data,$id))
|
||||
return Json::fail(ProductModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function collect($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign(StoreProductRelation::getCollect($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function like($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign(StoreProductRelation::getLike($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改产品价格
|
||||
* @param Request $request
|
||||
*/
|
||||
public function edit_product_price(Request $request){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['price',0],
|
||||
],$request);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
$res = ProductModel::edit(['price'=>$data['price']],$data['id']);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品库存
|
||||
* @param Request $request
|
||||
*/
|
||||
public function edit_product_stock(Request $request){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['stock',0],
|
||||
],$request);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
$res = ProductModel::edit(['stock'=>$data['stock']],$data['id']);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
92
application/admin/controller/store/StoreProductReply.php
Normal file
92
application/admin/controller/store/StoreProductReply.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use traits\CurdControllerTrait;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\store\StoreProductReply as ProductReplyModel;
|
||||
use think\Url;
|
||||
/**
|
||||
* 评论管理 控制器
|
||||
* Class StoreProductReply
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreProductReply extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['is_reply',''],
|
||||
['comment',''],
|
||||
],$this->request);
|
||||
$product_id = 0;
|
||||
$product_id = input('product_id');
|
||||
if($product_id)
|
||||
$where['product_id'] = $product_id;
|
||||
else
|
||||
$where['product_id'] = 0;
|
||||
$this->assign('where',$where);
|
||||
$this->assign(ProductReplyModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function delete($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$data['is_del'] = 1;
|
||||
if(!ProductReplyModel::edit($data,$id))
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function set_reply(Request $request){
|
||||
$data = Util::postMore([
|
||||
'id',
|
||||
'content',
|
||||
],$request);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$save['merchant_reply_content'] = $data['content'];
|
||||
$save['merchant_reply_time'] = time();
|
||||
$save['is_reply'] = 2;
|
||||
$res = ProductReplyModel::edit($save,$data['id']);
|
||||
if(!$res)
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('回复成功!');
|
||||
}
|
||||
|
||||
public function edit_reply(Request $request){
|
||||
$data = Util::postMore([
|
||||
'id',
|
||||
'content',
|
||||
],$request);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$save['merchant_reply_content'] = $data['content'];
|
||||
$save['merchant_reply_time'] = time();
|
||||
$save['is_reply'] = 2;
|
||||
$res = ProductReplyModel::edit($save,$data['id']);
|
||||
if(!$res)
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('回复成功!');
|
||||
}
|
||||
|
||||
}
|
||||
60
application/admin/controller/system/Clear.php
Normal file
60
application/admin/controller/system/Clear.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\CacheService;
|
||||
use service\JsonService as Json;
|
||||
|
||||
/**
|
||||
* 首页控制器
|
||||
* Class Clear
|
||||
* @package app\admin\controller
|
||||
*
|
||||
*/
|
||||
class Clear extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
public function refresh_cache(){
|
||||
if(function_exists('shell_exec')){
|
||||
`php think optimize:schema`;
|
||||
`php think optimize:autoload`;
|
||||
`php think optimize:route`;
|
||||
`php think optimize:config`;
|
||||
}else if(function_exists('exec')){
|
||||
exec('php think optimize:schema');
|
||||
exec('php think optimize:autoload');
|
||||
exec('php think optimize:route');
|
||||
exec('php think optimize:config');
|
||||
}
|
||||
return Json::successful('数据缓存刷新成功!');
|
||||
}
|
||||
public function delete_cache(){
|
||||
$this->delDirAndFile("./runtime/temp");
|
||||
$this->delDirAndFile("./runtime/cache");
|
||||
return Json::successful('清除缓存成功!');
|
||||
}
|
||||
public function delete_log(){
|
||||
$this->delDirAndFile("./runtime/log");
|
||||
return Json::successful('清除日志成功!');
|
||||
}
|
||||
function delDirAndFile($dirName,$subdir=true){
|
||||
if ($handle = opendir("$dirName")){
|
||||
while(false !== ($item = readdir($handle))){
|
||||
if($item != "." && $item != ".."){
|
||||
if(is_dir("$dirName/$item"))
|
||||
$this->delDirAndFile("$dirName/$item",false);
|
||||
else
|
||||
@unlink("$dirName/$item");
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
if(!$subdir) @rmdir($dirName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
application/admin/controller/system/SystemAttachment.php
Normal file
41
application/admin/controller/system/SystemAttachment.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UploadService as Upload;
|
||||
/**
|
||||
* 附件管理控制器
|
||||
* Class SystemAttachment
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemAttachment extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 编辑器上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('upfile','editor/'.date('Ymd'));
|
||||
if($res->status==false && $res->error){
|
||||
exit(json_encode(['state'=>$res->error]));
|
||||
}
|
||||
$fileInfo = $res->fileInfo->getinfo();
|
||||
//产品图片上传记录
|
||||
$fileInfo = $res->fileInfo->getinfo();
|
||||
SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,'',0);
|
||||
$info = array(
|
||||
"originalName" => $fileInfo['name'],
|
||||
"name" => $res->fileInfo->getSaveName(),
|
||||
"url" => '.'.$res->dir,
|
||||
"size" => $fileInfo['size'],
|
||||
"type" => $fileInfo['type'],
|
||||
"state" => "SUCCESS"
|
||||
);
|
||||
echo json_encode($info);
|
||||
}
|
||||
}
|
||||
53
application/admin/controller/system/SystemClear.php
Normal file
53
application/admin/controller/system/SystemClear.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\CacheService;
|
||||
use service\JsonService as Json;
|
||||
|
||||
/**
|
||||
* 清除缓存
|
||||
* Class Clear
|
||||
* @package app\admin\controller
|
||||
*
|
||||
*/
|
||||
class systemClear extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
public function refresh_cache(){
|
||||
`php think optimize:schema`;
|
||||
`php think optimize:autoload`;
|
||||
`php think optimize:route`;
|
||||
`php think optimize:config`;
|
||||
return Json::successful('数据缓存刷新成功!');
|
||||
}
|
||||
public function delete_cache(){
|
||||
$this->delDirAndFile("./runtime/temp");
|
||||
$this->delDirAndFile("./runtime/cache");
|
||||
return Json::successful('清除缓存成功!');
|
||||
}
|
||||
public function delete_log(){
|
||||
$this->delDirAndFile("./runtime/log");
|
||||
return Json::successful('清除日志成功!');
|
||||
}
|
||||
function delDirAndFile($dirName,$subdir=true){
|
||||
if ($handle = opendir("$dirName")){
|
||||
while(false !== ($item = readdir($handle))){
|
||||
if($item != "." && $item != ".."){
|
||||
if(is_dir("$dirName/$item"))
|
||||
$this->delDirAndFile("$dirName/$item",false);
|
||||
else
|
||||
@unlink("$dirName/$item");
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
if(!$subdir) @rmdir($dirName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
157
application/admin/controller/system/SystemCleardata.php
Normal file
157
application/admin/controller/system/SystemCleardata.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: liying
|
||||
* Date: 2018/5/24
|
||||
* Time: 10:58
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use service\JsonService as Json;
|
||||
use think\db;
|
||||
use think\Config;
|
||||
/**
|
||||
* 清除默认数据理控制器
|
||||
* Class SystemCleardata
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemCleardata extends AuthController
|
||||
{
|
||||
public function index(){
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
//清除用户数据
|
||||
public function UserRelevant(){
|
||||
SystemCleardata::ClearData('user_recharge',1);
|
||||
SystemCleardata::ClearData('user_address',1);
|
||||
SystemCleardata::ClearData('user_bill',1);
|
||||
SystemCleardata::ClearData('user_enter',1);
|
||||
SystemCleardata::ClearData('user_extract',1);
|
||||
SystemCleardata::ClearData('user_notice',1);
|
||||
SystemCleardata::ClearData('user_notice_see',1);
|
||||
SystemCleardata::ClearData('wechat_qrcode',1);
|
||||
SystemCleardata::ClearData('wechat_message',1);
|
||||
SystemCleardata::ClearData('store_coupon_user',1);
|
||||
SystemCleardata::ClearData('store_coupon_issue_user',1);
|
||||
SystemCleardata::ClearData('store_bargain_user',1);
|
||||
SystemCleardata::ClearData('store_bargain_user_help',1);
|
||||
SystemCleardata::ClearData('store_product_reply',1);
|
||||
$this->delDirAndFile('./public/uploads/store/comment');
|
||||
SystemCleardata::ClearData('store_product_relation',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除商城数据
|
||||
public function storedata(){
|
||||
SystemCleardata::ClearData('store_coupon',1);
|
||||
SystemCleardata::ClearData('store_coupon_issue',1);
|
||||
SystemCleardata::ClearData('store_bargain',1);
|
||||
SystemCleardata::ClearData('store_combination',1);
|
||||
SystemCleardata::ClearData('store_product_attr',1);
|
||||
SystemCleardata::ClearData('store_product_attr_result',1);
|
||||
SystemCleardata::ClearData('store_product_attr_value',1);
|
||||
SystemCleardata::ClearData('store_seckill',1);
|
||||
SystemCleardata::ClearData('store_product',1);
|
||||
$this->delDirAndFile('./public/uploads/store/product');
|
||||
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除产品分类
|
||||
public function categorydata(){
|
||||
SystemCleardata::ClearData('store_category',1);
|
||||
$this->delDirAndFile('./public/uploads/store/product');
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除订单数据
|
||||
public function orderdata(){
|
||||
SystemCleardata::ClearData('store_order',1);
|
||||
SystemCleardata::ClearData('store_order_cart_info',1);
|
||||
SystemCleardata::ClearData('store_order_copy',1);
|
||||
SystemCleardata::ClearData('store_order_status',1);
|
||||
SystemCleardata::ClearData('store_pink',1);
|
||||
SystemCleardata::ClearData('store_cart',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除客服数据
|
||||
public function kefudata(){
|
||||
SystemCleardata::ClearData('store_service',1);
|
||||
$this->delDirAndFile('./public/uploads/store/service');
|
||||
SystemCleardata::ClearData('store_service_log',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//修改用户默认密码
|
||||
public function userdate(){
|
||||
SystemCleardata::ClearData('user',1);
|
||||
$headimgurl= WechatUser::Where('uid',1)->value('headimgurl');
|
||||
$data['account']='crmeb';
|
||||
$data['pwd']=md5(123456);
|
||||
$data['avatar']=$headimgurl;
|
||||
$data['add_time']=time();
|
||||
$data['status']=1;
|
||||
$data['level']=0;
|
||||
$data['user_type']="wechat";
|
||||
$data['is_promoter']=1;
|
||||
User::create($data);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除微信管理数据
|
||||
public function wechatdata(){
|
||||
SystemCleardata::ClearData('wechat_media',1);
|
||||
SystemCleardata::ClearData('wechat_reply',1);
|
||||
SystemCleardata::ClearData('wechat_news_content',1);
|
||||
SystemCleardata::ClearData('wechat_news',1);
|
||||
SystemCleardata::ClearData('wechat_news_category',1);
|
||||
$this->delDirAndFile('./public/uploads/wechat');
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除所有附件
|
||||
public function uploaddata(){
|
||||
$this->delDirAndFile('./public/uploads');
|
||||
return Json::successful('清除上传文件成功!');
|
||||
}
|
||||
//清除微信用户
|
||||
public function wechatuserdata(){
|
||||
$data= WechatUser::get(1)->toArray();
|
||||
SystemCleardata::ClearData('wechat_user',1);
|
||||
unset($data['uid']);
|
||||
WechatUser::set($data);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除内容分类
|
||||
public function articledata(){
|
||||
SystemCleardata::ClearData('article_category',1);
|
||||
$this->delDirAndFile('./public/uploads/article/');
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除制定表数据
|
||||
public function ClearData($table_name,$status){
|
||||
$table_name = Config::get('database')['prefix'].$table_name;
|
||||
if($status){
|
||||
db::query('TRUNCATE TABLE '.$table_name);
|
||||
}else{
|
||||
db::query('DELETE FROM'.$table_name);
|
||||
}
|
||||
|
||||
}
|
||||
//递归删除文件
|
||||
function delDirAndFile($dirName,$subdir=true){
|
||||
if ($handle = opendir("$dirName")){
|
||||
while(false !== ($item = readdir($handle))){
|
||||
if($item != "." && $item != ".."){
|
||||
if(is_dir("$dirName/$item"))
|
||||
$this->delDirAndFile("$dirName/$item",false);
|
||||
else
|
||||
@unlink("$dirName/$item");
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
if(!$subdir) @rmdir($dirName);
|
||||
}
|
||||
}
|
||||
}
|
||||
233
application/admin/controller/system/SystemFile.php
Normal file
233
application/admin/controller/system/SystemFile.php
Normal file
@ -0,0 +1,233 @@
|
||||
<?php
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\model\system\SystemFile as SystemFileModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemFile
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemFile extends AuthController
|
||||
{
|
||||
public function index(){
|
||||
$app = $this->getDir('./application');
|
||||
$extend = $this->getDir('./extend');
|
||||
$public = $this->getDir('./public');
|
||||
$arr = array();
|
||||
$arr = array_merge($app,$extend);
|
||||
$arr = array_merge($arr,$public);
|
||||
$fileAll = array();//本地文件
|
||||
$cha = array();//不同的文件
|
||||
foreach ($arr as $k=>$v) {
|
||||
$fp = fopen($v, 'r');
|
||||
if (filesize($v)) $ct = fread($fp, filesize($v));
|
||||
else $ct = null;
|
||||
fclose($fp);
|
||||
$cthash = md5($ct);
|
||||
$update_time = stat($v);
|
||||
$fileAll[$k]['cthash'] = $cthash;
|
||||
$fileAll[$k]['filename'] = $v;
|
||||
$fileAll[$k]['atime'] = $update_time['atime'];
|
||||
$fileAll[$k]['mtime'] = $update_time['mtime'];
|
||||
$fileAll[$k]['ctime'] = $update_time['ctime'];
|
||||
}
|
||||
$file = SystemFileModel::all(function($query){
|
||||
$query->order('atime', 'desc');
|
||||
})->toArray();//数据库中的文件
|
||||
if(empty($file)){
|
||||
$data_num = array_chunk($fileAll,10);
|
||||
SystemFileModel::beginTrans();
|
||||
$res = true;
|
||||
foreach ($data_num as $k=>$v){
|
||||
$res = $res && SystemFileModel::insertAll($v);
|
||||
}
|
||||
SystemFileModel::checkTrans($res);
|
||||
if($res){
|
||||
$cha = array();//不同的文件
|
||||
}else{
|
||||
$cha = $fileAll;
|
||||
}
|
||||
}else{
|
||||
$cha = array();//差异文件
|
||||
foreach ($file as $k=>$v){
|
||||
foreach ($fileAll as $ko=>$vo){
|
||||
if($v['filename'] == $vo['filename']){
|
||||
if($v['cthash'] != $vo['cthash']){
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '已修改';
|
||||
}
|
||||
unset($fileAll[$ko]);
|
||||
unset($file[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($file as $k=>$v){
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '已删除';
|
||||
}
|
||||
foreach ($fileAll as $k=>$v){
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '新增的';
|
||||
}
|
||||
|
||||
}
|
||||
// dump($file);
|
||||
// dump($fileAll);
|
||||
$this->assign('cha',$cha);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function filelist(){
|
||||
$app = $this->getDir('./application');
|
||||
print_r($app);
|
||||
$extend = $this->getDir('./extend');
|
||||
$public = $this->getDir('./public');
|
||||
$arr = array();
|
||||
$arr = array_merge($app,$extend);
|
||||
$arr = array_merge($arr,$public);
|
||||
$fileAll = array();//本地文件
|
||||
foreach ($arr as $k=>$v) {
|
||||
$fp = fopen($v, 'r');
|
||||
if (filesize($v)) $ct = fread($fp, filesize($v));
|
||||
else $ct = null;
|
||||
fclose($fp);
|
||||
$cthash = md5($ct);
|
||||
$update_time = stat($v);
|
||||
$fileAll[$k]['cthash'] = $cthash;
|
||||
$fileAll[$k]['filename'] = $v;
|
||||
$fileAll[$k]['atime'] = $update_time['atime'];
|
||||
$fileAll[$k]['mtime'] = $update_time['mtime'];
|
||||
$fileAll[$k]['ctime'] = $update_time['ctime'];
|
||||
}
|
||||
|
||||
// dump($file);
|
||||
dump($fileAll);
|
||||
}
|
||||
/**
|
||||
* 获取文件夹中的文件 不包括子文件
|
||||
* @param $dir
|
||||
* @return array
|
||||
*/
|
||||
public function getNextDir(){
|
||||
$dir = './';
|
||||
$list = scandir($dir);
|
||||
$dirlist = array();
|
||||
$filelist = array();
|
||||
foreach($list as $key=>$v) {
|
||||
if($v !='.' && $v !='..'){
|
||||
if (is_dir($dir.'/'.$v)) {
|
||||
$dirlist[$key]['name'] = $v;
|
||||
$dirlist[$key]['type'] = 'dir';
|
||||
}
|
||||
if(is_file($dir.'/'.$v)){
|
||||
$filelist[$key]['name'] = $v;
|
||||
$filelist[$key]['type'] = 'file';
|
||||
}
|
||||
}
|
||||
}
|
||||
$filesarr = array_merge($dirlist,$filelist);
|
||||
print_r($filesarr);
|
||||
}
|
||||
/**
|
||||
* 获取文件夹中的文件 包括子文件 不能直接用 直接使用 $this->getDir()方法 P156
|
||||
* @param $path
|
||||
* @param $data
|
||||
*/
|
||||
public function searchDir($path,&$data){
|
||||
if(is_dir($path) && !strpos($path,'uploads')){
|
||||
$dp=dir($path);
|
||||
while($file=$dp->read()){
|
||||
if($file!='.'&& $file!='..'){
|
||||
$this->searchDir($path.'/'.$file,$data);
|
||||
}
|
||||
}
|
||||
$dp->close();
|
||||
}
|
||||
if(is_file($path)){
|
||||
$data[]=$path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹中的文件 包括子文件
|
||||
* @param $dir
|
||||
* @return array
|
||||
*/
|
||||
public function getDir($dir){
|
||||
$data=array();
|
||||
$this->searchDir($dir,$data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//测试
|
||||
public function ceshi(){
|
||||
//创建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','/admin/system.system_attachment/index.html?fodder=frame')
|
||||
,Form::frameInputs('frameInputs','frameInputs','/admin/system.system_attachment/index.html?fodder=frameInputs')
|
||||
,Form::frameFiles('month1','frameFiles','/admin/system.system_attachment/index.html?fodder=month1')
|
||||
,Form::frameImages('fodder1','frameImages','/admin/system.system_attachment/index.html?fodder=fodder1')->maxLength(3)->width('800px')->height('400px')
|
||||
,Form::frameImages('fodder11','frameImages','/admin/system.system_attachment/index.html?fodder=fodder11')->icon('images')
|
||||
,Form::frameInputOne('month3','frameInputOne','/admin/system.system_attachment/index.html?fodder=month3')->icon('ionic')
|
||||
,Form::frameFileOne('month4','frameFileOne','/admin/system.system_attachment/index.html?fodder=month4')
|
||||
,Form::frameImageOne('month5','frameImageOne','/admin/system.system_attachment/index.html?fodder=month5')->icon('image')
|
||||
,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;
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/system/SystemLog.php
Normal file
1
application/admin/controller/system/SystemLog.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
namespace app\admin\controller\system;
use app\admin\controller\AuthController;
use app\admin\model\system\SystemAdmin;
use app\admin\model\system\SystemLog as LogModel;
use service\UtilService as Util;
/**
* 管理员操作记录表控制器
* Class SystemLog
* @package app\admin\controller\system
*/
class SystemLog extends AuthController
{
/**
* 显示操作记录
*/
public function index(){
$where = Util::getMore([
['pages',''],
['admin_id',''],
['data',''],
],$this->request);
$where['level'] = $this->adminInfo['level'];
$this->assign('where',$where);
$this->assign('admin',SystemAdmin::getOrdAdmin('id,real_name',$this->adminInfo['level']));
$this->assign(LogModel::systemPage($where));
return $this->fetch();
}
}
|
||||
196
application/admin/controller/system/SystemUpgradeclient.php
Normal file
196
application/admin/controller/system/SystemUpgradeclient.php
Normal file
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\JsonService as Json;
|
||||
use service\UpgradeService as uService;
|
||||
use think\Db;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
/**
|
||||
* 在线升级控制器
|
||||
* Class SystemUpgradeclient
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemUpgradeclient extends AuthController
|
||||
{
|
||||
|
||||
protected $serverweb = array('version'=>'1.0','version_code'=>0);//本站点信息
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
//屏蔽所有错误避免操作文件夹发生错误提示
|
||||
ini_set('display_errors',0);
|
||||
error_reporting(0);
|
||||
self::snyweninfo();//更新站点信息
|
||||
$this->assign(['auth'=>self::isauth(),'app'=>uService::isWritable(APP_PATH),'extend'=>uService::isWritable(EXTEND_PATH),'public'=>uService::isWritable(ROOT_PATH.'public')]);
|
||||
}
|
||||
//同步更新站点信息
|
||||
public function snyweninfo(){
|
||||
$this->serverweb['ip'] = $this->request->ip();
|
||||
$this->serverweb['host'] = $this->request->host();
|
||||
$this->serverweb['https'] = !empty($this->request->domain())?$this->request->domain():SystemConfig::getValue('site_url');
|
||||
$this->serverweb['webname'] = SystemConfig::getValue('site_name');
|
||||
$local=uService::getVersion();
|
||||
if($local['code']==200 && isset($local['msg']['version']) && isset($local['msg']['version_code'])){
|
||||
$this->serverweb['version'] = uService::replace($local['msg']['version']);
|
||||
$this->serverweb['version_code'] = (int)uService::replace($local['msg']['version_code']);
|
||||
}
|
||||
uService::snyweninfo($this->serverweb);
|
||||
}
|
||||
//是否授权
|
||||
public function isauth(){
|
||||
return uService::isauth();
|
||||
}
|
||||
public function index(){
|
||||
$server=uService::start();
|
||||
$version=$this->serverweb['version'];
|
||||
$version_code=$this->serverweb['version_code'];
|
||||
$this->assign(compact('server','version','version_code'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function get_list(){
|
||||
$list=uService::request_post(uService::$isList,['page'=>input('post.page/d'),'limit'=>input('post.limit/d')]);
|
||||
if(is_array($list) && isset($list['code']) && isset($list['data']) && $list['code']==200){
|
||||
$list=$list['data'];
|
||||
}else{
|
||||
$list=[];
|
||||
}
|
||||
Json::successful('ok',['list'=>$list,'page'=>input('post.page/d')+1]);
|
||||
}
|
||||
//删除备份文件
|
||||
public function setcopydel(){
|
||||
$post=input('post.');
|
||||
if(!isset($post['id'])) Json::fail('删除备份文件失败,缺少参数ID');
|
||||
if(!isset($post['ids'])) Json::fail('删除备份文件失败,缺少参数IDS');
|
||||
$fileservice=new uService;
|
||||
if(is_array($post['ids'])){
|
||||
foreach ($post['ids'] as $file){
|
||||
$fileservice->del_dir(ROOT_PATH.'public'.DS.'copyfile'.$file);
|
||||
}
|
||||
}
|
||||
if($post['id']){
|
||||
$copyFile=ROOT_PATH.'public'.DS.'copyfile'.$post['id'];
|
||||
$fileservice->del_dir($copyFile);
|
||||
}
|
||||
Json::successful('删除成功');
|
||||
}
|
||||
public function get_new_version_conte(){
|
||||
$post=$this->request->post();
|
||||
if(!isset($post['id'])) Json::fail('缺少参数ID');
|
||||
$versionInfo=uService::request_post(uService::$NewVersionCount,['id'=>$post['id']]);
|
||||
if(isset($versionInfo['code']) && isset($versionInfo['data']['count']) && $versionInfo['code']==200){
|
||||
return Json::successful(['count'=>$versionInfo['data']['count']]);
|
||||
}else{
|
||||
return Json::fail('服务器异常');
|
||||
}
|
||||
}
|
||||
//一键升级
|
||||
public function auto_upgrad(){
|
||||
$prefix=config('database.prefix');
|
||||
$fileservice=new uService;
|
||||
$post=$this->request->post();
|
||||
if(!isset($post['id'])) Json::fail('缺少参数ID');
|
||||
$versionInfo=$fileservice->request_post(uService::$isNowVersion,['id'=>$post['id']]);
|
||||
if($versionInfo===null) Json::fail('服务器异常,请稍后再试');
|
||||
if(isset($versionInfo['code']) && $versionInfo['code']==400) Json::fail(isset($versionInfo['msg'])?$versionInfo['msg']:'您暂时没有权限升级,请联系管理员!');
|
||||
if(is_array($versionInfo) && isset($versionInfo['data'])){
|
||||
$list=$versionInfo['data'];
|
||||
$id=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$savefile=ROOT_PATH . 'public' . DS.'upgrade_lv';
|
||||
//1,检查远程下载文件,并下载
|
||||
if(($save_path=$fileservice->check_remote_file_exists($val['zip_name'],$savefile))===false) Json::fail('远程升级包不存在');
|
||||
//2,首先解压文件
|
||||
$savename=ROOT_PATH.'public'.DS.'upgrade_lv'.DS.time();
|
||||
$fileservice->zipopen($save_path,$savename);
|
||||
//3,执行SQL文件
|
||||
Db::startTrans();
|
||||
try{
|
||||
//参数3不介意大小写的
|
||||
$sqlfile=$fileservice->list_dir_info($savename.DS,true,'sql');
|
||||
if(is_array($sqlfile) && !empty($sqlfile)){
|
||||
foreach($sqlfile as $file){
|
||||
if(file_exists($file)){
|
||||
//为一键安装做工作记得表前缀要改为[#DB_PREFIX#]哦
|
||||
$execute_sql=explode(";\r",str_replace(['[#DB_PREFIX#]', "\n"], [$prefix, "\r"], file_get_contents($file)));
|
||||
foreach($execute_sql as $_sql){
|
||||
if ($query_string = trim(str_replace(array(
|
||||
"\r",
|
||||
"\n",
|
||||
"\t"
|
||||
), '', $_sql))) Db::execute($query_string);
|
||||
}
|
||||
//执行完sql记得删掉哦
|
||||
$fileservice->unlink_file($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
}catch(\Exception $e){
|
||||
Db::rollback();
|
||||
//删除解压下的文件
|
||||
$fileservice->del_dir(ROOT_PATH.'public'.DS.'upgrade_lv');
|
||||
//删除压缩包
|
||||
$fileservice->unlink_file($save_path);
|
||||
//升级失败发送错误信息
|
||||
$fileservice->request_post(uService::$isInsertLog,[
|
||||
'content'=>'升级失败,错误信息为:'.$e->getMessage(),
|
||||
'add_time'=>time(),
|
||||
'ip'=>$this->request->ip(),
|
||||
'http'=>$this->request->domain(),
|
||||
'type'=>'error',
|
||||
'version'=>$val['version']
|
||||
]);
|
||||
return Json::fail('升级失败SQL文件执行有误');
|
||||
}
|
||||
//4,备份文件
|
||||
$copyFile=ROOT_PATH.'public'.DS.'copyfile'.$val['id'];
|
||||
$copyList=$fileservice->get_dirs($savename.DS);
|
||||
if(isset($copyList['dir'])){
|
||||
if($copyList['dir'][0]=='.' && $copyList['dir'][1]=='..'){
|
||||
array_shift($copyList['dir']);
|
||||
array_shift($copyList['dir']);
|
||||
}
|
||||
foreach($copyList['dir'] as $dir){
|
||||
if(file_exists(ROOT_PATH.$dir,$copyFile.DS.$dir)){
|
||||
$fileservice->copy_dir(ROOT_PATH.$dir,$copyFile.DS.$dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
//5,覆盖文件
|
||||
$fileservice->handle_dir($savename,ROOT_PATH);
|
||||
//6,删除升级生成的目录
|
||||
$fileservice->del_dir(ROOT_PATH.'public'.DS.'upgrade_lv');
|
||||
//7,删除压缩包
|
||||
$fileservice->unlink_file($save_path);
|
||||
//8,改写本地升级文件
|
||||
$handle=fopen(APP_PATH.'version.php','w+');
|
||||
if($handle===false) Json::fail(APP_PATH.'version.php'.'无法写入打开');
|
||||
$content=<<<EOT
|
||||
version={$val['version']}
|
||||
version_code={$val['id']}
|
||||
EOT;
|
||||
if(fwrite($handle,$content)===false) Json::fail('升级包写入失败');
|
||||
fclose($handle);
|
||||
//9,向服务端发送升级日志
|
||||
$posts=[
|
||||
'ip'=>$this->request->ip(),
|
||||
'https'=>$this->request->domain(),
|
||||
'update_time'=>time(),
|
||||
'content'=>'一键升级成功,升级版本号为:'.$val['version'].'。版本code为:'.$val['id'],
|
||||
'type'=>'log',
|
||||
'versionbefor'=>$this->serverweb['version'],
|
||||
'versionend'=>$val['version']
|
||||
];
|
||||
$inset=$fileservice->request_post(uService::$isInsertLog,$posts);
|
||||
$id[]=$val['id'];
|
||||
}
|
||||
//10,升级完成
|
||||
Json::successful('升级成功',['code'=>end($id),'version'=>$val['version']]);
|
||||
}else{
|
||||
Json::fail('服务器异常,请稍后再试');
|
||||
}
|
||||
}
|
||||
}
|
||||
281
application/admin/controller/ump/StoreCoupon.php
Normal file
281
application/admin/controller/ump/StoreCoupon.php
Normal file
@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\ump\StoreCouponIssue;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use service\FormBuilder as Form;
|
||||
use service\JsonService;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UtilService;
|
||||
use think\Request;
|
||||
use app\admin\model\ump\StoreCoupon as CouponModel;
|
||||
use think\Url;
|
||||
|
||||
/**
|
||||
* 优惠券控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCoupon extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('title','优惠券名称');
|
||||
$f[] = Form::number('coupon_price','优惠券面值',0)->min(0);
|
||||
$f[] = Form::number('use_min_price','优惠券最低消费')->min(0);
|
||||
$f[] = Form::number('coupon_time','优惠券有效期限')->min(0);
|
||||
$f[] = Form::number('sort','排序');
|
||||
$f[] = Form::radio('status','状态',0)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::build('save'));//->setSuccessScript('<script>formCreate.formSuccess = function(form,$r){$r.closeModal();};</script>');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'coupon_price',
|
||||
'use_min_price',
|
||||
'coupon_time',
|
||||
'sort',
|
||||
['status',0]
|
||||
],$request);
|
||||
if(!$data['title']) return Json::fail('请输入优惠券名称');
|
||||
if(!$data['coupon_price']) return Json::fail('请输入优惠券面值');
|
||||
if(!$data['coupon_time']) return Json::fail('请输入优惠券有效期限');
|
||||
$data['add_time'] = time();
|
||||
CouponModel::set($data);
|
||||
return Json::successful('添加优惠券成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$coupon = CouponModel::get($id);
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('title','优惠券名称',$coupon->getData('title'));
|
||||
$f[] = Form::number('coupon_price','优惠券面值',$coupon->getData('coupon_price'))->min(0);
|
||||
$f[] = Form::number('use_min_price','优惠券最低消费',$coupon->getData('use_min_price'))->min(0);
|
||||
$f[] = Form::number('coupon_time','优惠券有效期限',$coupon->getData('coupon_time'))->min(0);
|
||||
$f[] = Form::number('sort','排序',$coupon->getData('sort'));
|
||||
$f[] = Form::radio('status','状态',$coupon->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::build('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'coupon_price',
|
||||
'use_min_price',
|
||||
'coupon_time',
|
||||
'sort',
|
||||
['status',0]
|
||||
],$request);
|
||||
if(!$data['title']) return Json::fail('请输入优惠券名称');
|
||||
if(!$data['coupon_price']) return Json::fail('请输入优惠券面值');
|
||||
if(!$data['coupon_time']) return Json::fail('请输入优惠券有效期限');
|
||||
CouponModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$data['is_del'] = 1;
|
||||
if(!CouponModel::edit($data,$id))
|
||||
return Json::fail(CouponModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改优惠券状态
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function status($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!CouponModel::editIsDel($id))
|
||||
return Json::fail(CouponModel::getErrorInfo('修改失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function grant_subscribe(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function grant_all(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function grant($id){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$nickname = UserModel::where('uid','IN',$id)->column('uid,nickname');
|
||||
$this->assign('where',$where);
|
||||
$this->assign('uid',$id);
|
||||
$this->assign('nickname',implode(',',$nickname));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function issue($id)
|
||||
{
|
||||
if(!CouponModel::be(['id'=>$id,'status'=>1,'is_del'=>0]))
|
||||
return $this->failed('发布的优惠劵已失效或不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('id','优惠劵ID',$id)->disabled(1);
|
||||
$f[] = Form::dateTimeRange('range_date','领取时间')->placeholder('不填为永久有效');
|
||||
$f[] = Form::number('count','发布数量',0)->min(0)->placeholder('不填或填0,为不限量');
|
||||
$f[] = Form::radio('is_permanent','是否不限量',0)->options([['label'=>'限量','value'=>0],['label'=>'不限量','value'=>1]]);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::build('update_issue',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
// FormBuilder::text('id','优惠劵ID',$id)->disabled();
|
||||
// FormBuilder::dateTimeRange('range_date','领取时间')->placeholder('不填为永久有效');
|
||||
// FormBuilder::text('count','发布数量')->placeholder('不填或填0,为不限量');
|
||||
// FormBuilder::radio('status','是否开启',[
|
||||
// ['value'=>1,'label'=>'开启'],
|
||||
// ['value'=>0,'label'=>'关闭']
|
||||
// ],1);
|
||||
// $this->assign(['title'=>'发布优惠券','rules'=>FormBuilder::builder()->getContent(),'action'=>Url::build('update_issue',array('id'=>$id))]);
|
||||
// return $this->fetch('public/common_form');
|
||||
}
|
||||
|
||||
public function update_issue(Request $request,$id)
|
||||
{
|
||||
list($_id,$rangeTime,$count,$status) = UtilService::postMore([
|
||||
'id',['range_date',['','']],['count',0],['status',0]
|
||||
],$request,true);
|
||||
if($_id != $id) return JsonService::fail('操作失败,信息不对称');
|
||||
if(!$count) $count = 0;
|
||||
if(!CouponModel::be(['id'=>$id,'status'=>1,'is_del'=>0])) return JsonService::fail('发布的优惠劵已失效或不存在!');
|
||||
if(count($rangeTime)!=2) return JsonService::fail('请选择正确的时间区间');
|
||||
|
||||
list($startTime,$endTime) = $rangeTime;
|
||||
// echo $startTime;echo $endTime;var_dump($rangeTime);die;
|
||||
if(!$startTime) $startTime = 0;
|
||||
if(!$endTime) $endTime = 0;
|
||||
if(!$startTime && $endTime) return JsonService::fail('请选择正确的开始时间');
|
||||
if($startTime && !$endTime) return JsonService::fail('请选择正确的结束时间');
|
||||
if(StoreCouponIssue::setIssue($id,$count,strtotime($startTime),strtotime($endTime),$count,$status))
|
||||
return JsonService::successful('发布优惠劵成功!');
|
||||
else
|
||||
return JsonService::fail('发布优惠劵失败!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给分组用户发放优惠券
|
||||
*/
|
||||
public function grant_group(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$group = UserModel::getUserGroup();
|
||||
$this->assign('where',$where);
|
||||
$this->assign('group',json_encode($group));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 给标签用户发放优惠券
|
||||
*/
|
||||
public function grant_tag(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$tag = UserModel::getUserTag();;//获取所有标签
|
||||
$this->assign('where',$where);
|
||||
$this->assign('tag',json_encode($tag));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
63
application/admin/controller/ump/StoreCouponIssue.php
Normal file
63
application/admin/controller/ump/StoreCouponIssue.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/17
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use app\admin\model\ump\StoreCouponIssue as CouponIssueModel;
|
||||
use app\admin\model\ump\StoreCouponIssueUser;
|
||||
use service\JsonService;
|
||||
use think\Url;
|
||||
use traits\CurdControllerTrait;
|
||||
use service\UtilService as Util;
|
||||
|
||||
class StoreCouponIssue extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = CouponIssueModel::class;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$where=Util::getMore([
|
||||
['status',''],
|
||||
['coupon_title','']
|
||||
]);
|
||||
$this->assign(CouponIssueModel::stsypage($where));
|
||||
$this->assign('where',$where);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function delete($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
if(CouponIssueModel::edit(['is_del'=>1],$id,'id'))
|
||||
return JsonService::successful('删除成功!');
|
||||
else
|
||||
return JsonService::fail('删除失败!');
|
||||
}
|
||||
|
||||
public function edit($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
$issueInfo = CouponIssueModel::get($id);
|
||||
if(-1 == $issueInfo['status'] || 1 == $issueInfo['is_del']) return $this->failed('状态错误,无法修改');
|
||||
$f = [Form::radio('status','是否开启',$issueInfo['status'])->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])];
|
||||
$form = Form::make_post_form('状态修改',$f,Url::build('change_field',array('id'=>$id,'field'=>'status')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function issue_log($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
$this->assign(StoreCouponIssueUser::systemCouponIssuePage($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
114
application/admin/controller/ump/StoreCouponUser.php
Normal file
114
application/admin/controller/ump/StoreCouponUser.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use app\admin\model\ump\StoreCoupon as CouponModel;
|
||||
use app\admin\model\ump\StoreCouponUser as CouponUserModel;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCouponUser extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['is_fail',''],
|
||||
['coupon_title',''],
|
||||
['nickname',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponUserModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 给已关注的用户发放优惠券
|
||||
* @param $id
|
||||
*/
|
||||
public function grant_subscribe($id){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = UserModel::getSubscribe('uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 给所有人发放优惠券
|
||||
* @param $id
|
||||
*/
|
||||
public function grant_all($id){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = UserModel::getUserAll('uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放优惠券到指定个人
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function grant($id,$uid){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = explode(',',$uid);
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
|
||||
}
|
||||
|
||||
public function grant_group($id,Request $request){
|
||||
$data = Util::postMore([
|
||||
['group',0]
|
||||
],$request);
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = WechatUser::where('groupid',$data['group'])->column('uid','uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
public function grant_tag($id,Request $request){
|
||||
$data = Util::postMore([
|
||||
['tag',0]
|
||||
],$request);
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = WechatUser::where("tagid_list","LIKE","%$data[tag]%")->column('uid','uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
}
|
||||
373
application/admin/controller/ump/StoreSeckill.php
Normal file
373
application/admin/controller/ump/StoreSeckill.php
Normal file
@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use traits\CurdControllerTrait;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\store\StoreProduct as ProductModel;
|
||||
use think\Url;
|
||||
use app\admin\model\ump\StoreSeckillAttr;
|
||||
use app\admin\model\ump\StoreSeckillAttrResult;
|
||||
use app\admin\model\ump\StoreSeckill as StoreSeckillModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 限时秒杀 控制器
|
||||
* Class StoreSeckill
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreSeckill extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = StoreSeckillModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign('countSeckill',StoreSeckillModel::getSeckillCount());
|
||||
$this->assign('seckillId',StoreSeckillModel::getSeckillIdAll());
|
||||
return $this->fetch();
|
||||
}
|
||||
public function save_excel(){
|
||||
$where=Util::getMore([
|
||||
['status',''],
|
||||
['store_name','']
|
||||
]);
|
||||
StoreSeckillModel::SaveExcel($where);
|
||||
}
|
||||
/**
|
||||
* 异步获取砍价数据
|
||||
*/
|
||||
public function get_seckill_list(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['status',''],
|
||||
['store_name','']
|
||||
]);
|
||||
$seckillList = StoreSeckillModel::systemPage($where);
|
||||
if(is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
|
||||
$data = $seckillList['list']['data'];
|
||||
foreach ($data as $k=>$v){
|
||||
$data[$k]['_stop_time'] = date('Y/m/d H:i:s',$v['stop_time']);
|
||||
}
|
||||
return Json::successlayui(['count'=>$seckillList['list']['total'],'data'=>$data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加秒杀产品
|
||||
* @return form-builder
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('title','产品标题');
|
||||
$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::number('price','秒杀价')->min(0)->col(12);
|
||||
$f[] = Form::number('ot_price','原价')->min(0)->col(12);
|
||||
$f[] = Form::number('cost','成本价')->min(0)->col(12);
|
||||
$f[] = Form::number('stock','库存')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序')->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数')->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费')->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',1)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**保存秒杀产品
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
*/
|
||||
public function save(Request $request,$id = 0)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'info',
|
||||
'unit_name',
|
||||
['image',''],
|
||||
['images',[]],
|
||||
'price',
|
||||
'ot_price',
|
||||
'cost',
|
||||
'sales',
|
||||
'stock',
|
||||
'sort',
|
||||
'give_integral',
|
||||
'postage',
|
||||
['section_time',[]],
|
||||
['is_postage',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['status',0],
|
||||
['num',0]
|
||||
],$request);
|
||||
if(!$data['title']) return Json::fail('请输入产品标题');
|
||||
if(!$data['unit_name']) return Json::fail('请输入产品单位');
|
||||
// var_dump($this->request->post());
|
||||
if(count($data['section_time'])<1) return Json::fail('请选择活动时间');
|
||||
$data['start_time'] = strtotime($data['section_time'][0]);
|
||||
$data['stop_time'] = strtotime($data['section_time'][1]);
|
||||
unset($data['section_time']);
|
||||
if(!$data['image']) return Json::fail('请选择推荐图');
|
||||
if(count($data['images'])<1) return Json::fail('请选择轮播图');
|
||||
$data['images'] = json_encode($data['images']);
|
||||
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品秒杀售价');
|
||||
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);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
StoreSeckillModel::edit($data,$id);
|
||||
return Json::successful('编辑成功!');
|
||||
}else{
|
||||
StoreSeckillModel::set($data);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
}
|
||||
/** 开启秒杀
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function seckill($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('title','产品标题',$product->getData('store_name'));
|
||||
$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::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);
|
||||
$f[] = Form::number('stock','库存',$product->getData('stock'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序',$product->getData('sort'))->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数')->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('title','产品标题',$product->getData('title'));
|
||||
$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::number('price','秒杀价',$product->getData('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);
|
||||
$f[] = Form::number('stock','库存',$product->getData('stock'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序',$product->getData('sort'))->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数',$product->getData('num'))->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',$product->getData('is_hot'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::build('save',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$data['is_del'] = 1;
|
||||
if(!StoreSeckillModel::edit($data,$id))
|
||||
return Json::fail(StoreSeckillModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function edit_content($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$seckill = StoreSeckillModel::get($id);
|
||||
if(!$seckill) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'content'=>StoreSeckillModel::where('id',$id)->value('description'),
|
||||
'field'=>'description',
|
||||
'action'=>Url::build('change_field',['id'=>$id,'field'=>'description'])
|
||||
]);
|
||||
return $this->fetch('public/edit_content');
|
||||
}
|
||||
|
||||
public function change_field(Request $request,$id,$field){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$seckill = StoreSeckillModel::get($id);
|
||||
if(!$seckill) return Json::fail('数据不存在!');
|
||||
$data['description'] = $request->post('description');
|
||||
$res = StoreSeckillModel::edit($data,$id);
|
||||
if($res)
|
||||
return Json::successful('添加成功');
|
||||
else
|
||||
return Json::fail('添加失败');
|
||||
}
|
||||
/**
|
||||
* 属性页面
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在!');
|
||||
$result = StoreSeckillAttrResult::getResult($id);
|
||||
$image = StoreSeckillModel::where('id',$id)->value('image');
|
||||
$this->assign(compact('id','result','product','image'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成属性
|
||||
* @param int $id
|
||||
*/
|
||||
public function is_format_attr($id = 0){
|
||||
if(!$id) return Json::fail('产品不存在');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('产品不存在');
|
||||
$attrFormat = attrFormat($attr)[1];
|
||||
if(count($detail)){
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
foreach ($detail as $kk=>$vv){
|
||||
if($v['detail'] == $vv['detail']){
|
||||
$attrFormat[$k]['price'] = $vv['price'];
|
||||
$attrFormat[$k]['sales'] = $vv['sales'];
|
||||
$attrFormat[$k]['pic'] = $vv['pic'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
break;
|
||||
}else{
|
||||
$attrFormat[$k]['price'] = '';
|
||||
$attrFormat[$k]['sales'] = '';
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
$attrFormat[$k]['price'] = $product['price'];
|
||||
$attrFormat[$k]['sales'] = $product['stock'];
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
}
|
||||
}
|
||||
return Json::successful($attrFormat);
|
||||
}
|
||||
/**
|
||||
* 添加 修改属性
|
||||
* @param $id
|
||||
*/
|
||||
public function set_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$res = StoreSeckillAttr::createProductAttr($attr,$detail,$id);
|
||||
if($res)
|
||||
return $this->successful('编辑属性成功!');
|
||||
else
|
||||
return $this->failed(StoreSeckillAttr::getErrorInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除属性
|
||||
* @param $id
|
||||
*/
|
||||
public function clear_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
if(false !== StoreSeckillAttr::clearProductAttr($id) && false !== StoreSeckillAttrResult::clearResult($id))
|
||||
return $this->successful('清空产品属性成功!');
|
||||
else
|
||||
return $this->failed(StoreSeckillAttr::getErrorInfo('清空产品属性失败!'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改秒杀产品状态
|
||||
* @param $status
|
||||
* @param int $id
|
||||
*/
|
||||
public function set_seckill_status($status,$id = 0){
|
||||
if(!$id) return Json::fail('参数错误');
|
||||
$res = StoreSeckillModel::edit(['status'=>$status],$id);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
}
|
||||
70
application/admin/controller/ump/UserPoint.php
Normal file
70
application/admin/controller/ump/UserPoint.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UtilService as Util;
|
||||
use app\admin\model\user\UserPoint AS UserPointModel;
|
||||
use think\Url;
|
||||
use service\JsonService;
|
||||
use app\admin\model\user\UserBill;
|
||||
|
||||
/**
|
||||
* 优惠券控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class UserPoint extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth('y'),
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->assign(['title'=>'添加优惠券','action'=>Url::build('save'),'rules'=>$this->rules()->getContent()]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
//异步获取积分列表
|
||||
public function getponitlist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['page',1],
|
||||
['limit',10],
|
||||
]);
|
||||
return JsonService::successlayui(UserPointModel::getpointlist($where));
|
||||
}
|
||||
//导出Excel表格
|
||||
public function export(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
]);
|
||||
UserPointModel::SaveExport($where);
|
||||
}
|
||||
//获取积分日志头部信息
|
||||
public function getuserpointbadgelist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
]);
|
||||
return JsonService::successful(UserPointModel::getUserpointBadgelist($where));
|
||||
}
|
||||
|
||||
}
|
||||
1
application/admin/controller/user/User.php
Normal file
1
application/admin/controller/user/User.php
Normal file
File diff suppressed because one or more lines are too long
296
application/admin/controller/user/UserNotice.php
Normal file
296
application/admin/controller/user/UserNotice.php
Normal file
@ -0,0 +1,296 @@
|
||||
<?php
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\JsonService;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\user\UserNotice as UserNoticeModel;
|
||||
use app\admin\model\user\UserNoticeSee as UserNoticeSeeModel;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
/**
|
||||
* 用户通知
|
||||
* Class UserNotice
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class UserNotice extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign(UserNoticeModel::getList());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create(){
|
||||
$f = array();
|
||||
$f[] = Form::input('user','发送人','系统管理员');
|
||||
$f[] = Form::input('title','通知标题');
|
||||
$f[] = Form::input('content','通知内容')->type('textarea');
|
||||
$f[] = Form::radio('type','消息类型',1)->options([['label'=>'系统消息','value'=>1],['label'=>'用户通知','value'=>2]]);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request){
|
||||
$params = $request->post();
|
||||
if(!$params["user"])return Json::fail('请输入发送人!');
|
||||
if(!$params["title"])return Json::fail('请输入通知标题!');
|
||||
if(!$params["content"])return Json::fail('请输入通知内容!');
|
||||
if($params["type"] == 2){
|
||||
$uids = UserModel::order('uid desc')->column("uid");
|
||||
$params["uid"] = count($uids) > 0 ? ",".implode(",",$uids)."," : "";
|
||||
}
|
||||
$params["add_time"] = time();
|
||||
UserNoticeModel::set($params);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$notice = UserNoticeModel::get($id);
|
||||
if(!$notice) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('user','发送人',$notice["user"]);
|
||||
$f[] = Form::input('title','通知标题',$notice["title"]);
|
||||
$f[] = Form::input('content','通知内容',$notice["content"])->type('textarea');
|
||||
$f[] = Form::radio('type','消息类型',$notice["type"])->options([['label'=>'系统消息','value'=>1],['label'=>'用户通知','value'=>2]]);
|
||||
$form = Form::make_post_form('编辑通知',$f,Url::build('update',["id"=>$id]),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request,$id)
|
||||
{
|
||||
$params = $request->post();
|
||||
if(!$params["user"])return Json::fail('请输入发送人!');
|
||||
if(!$params["title"])return Json::fail('请输入通知标题!');
|
||||
if(!$params["content"])return Json::fail('请输入通知内容!');
|
||||
UserNoticeModel::edit($params,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function send($id)
|
||||
{
|
||||
UserNoticeModel::edit(array("is_send"=>1,"send_time"=>time()),$id);
|
||||
return Json::successful('发送成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!UserNoticeModel::del($id))
|
||||
return Json::fail(UserNoticeModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询发送信息的用户资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user($id){
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
$model = new UserModel;
|
||||
$model = $model::alias('A');
|
||||
$model = $model->field('A.*');
|
||||
if($notice["type"] == 2){
|
||||
if($notice["uid"] != ""){
|
||||
$uids = explode(",",$notice["uid"]);
|
||||
array_splice($uids,0,1);
|
||||
array_splice($uids,count($uids)-1,1);
|
||||
$model = $model->where("A.uid","in",$uids);
|
||||
}else{
|
||||
$model = $model->where("A.uid",$notice['uid']);
|
||||
}
|
||||
$model->order('A.uid desc');
|
||||
}else{
|
||||
$model = $model->join('__USER_NOTICE_SEE__ B','A.uid = B.uid','RIGHT');
|
||||
$model = $model->where("B.nid",$notice['id']);
|
||||
$model->order('B.add_time desc');
|
||||
}
|
||||
$this->assign(UserModel::page($model,function($item,$key) use ($notice){
|
||||
$item["is_see"] = UserNoticeSeeModel::where("uid",$item["uid"])->where("nid",$notice["id"])->count() > 0 ? 1 : 0;
|
||||
}));
|
||||
$this->assign(compact('notice'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加发送信息的用户
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user_create($id){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['data',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserModel::systemPage($where));
|
||||
$this->assign(['title'=>'添加发送用户','save'=>Url::build('user_save',array('id'=>$id))]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user_save(Request $request,$id){
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
if($notice["type"] == 1) return Json::fail('系统通知不能管理用户!');
|
||||
|
||||
//查找当前选中的uid
|
||||
$params = $request->post();
|
||||
if(isset($params["search"])){
|
||||
$model = new UserModel;
|
||||
if($params['search']['nickname'] !== '') $model = $model->where('nickname','LIKE',"%".$params['search']['nickname']."%");
|
||||
if($params['search']['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$params['search']['data']);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
}
|
||||
$model = $model->order('uid desc');
|
||||
$uids = $model->column("uid");
|
||||
}else{
|
||||
$uids = $params["checked_menus"];
|
||||
}
|
||||
if(count($uids) <= 0)return Json::fail('请选择要添加的用户!');
|
||||
|
||||
//合并原来和现在的uid
|
||||
if($notice["uid"] != ""){
|
||||
$now_uids = explode(",",$notice["uid"]);
|
||||
array_splice($now_uids,0,1);
|
||||
array_splice($now_uids,count($now_uids)-1,1);
|
||||
$now_uids = array_merge($now_uids,$uids);
|
||||
}else{
|
||||
$now_uids = $uids;
|
||||
}
|
||||
|
||||
//编辑合并之后的uid
|
||||
$res_uids = UserModel::where("uid","in",$now_uids)->order('uid desc')->column("uid");
|
||||
UserNoticeModel::edit(array("uid"=>",".implode(",",$res_uids).","),$notice["id"]);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user_delete($id,$uid)
|
||||
{
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
if($notice["type"] == 1) return Json::fail('系统通知不能管理用户!');
|
||||
if($notice["uid"] != ""){
|
||||
$res_uids = explode(",",$notice["uid"]);
|
||||
array_splice($res_uids,0,1);
|
||||
array_splice($res_uids,count($res_uids)-1,1);
|
||||
}
|
||||
array_splice($res_uids,array_search($uid,$res_uids),1);
|
||||
$value = count($res_uids) > 0 ? ",".implode(",",$res_uids)."," : "";
|
||||
UserNoticeModel::edit(array("uid"=>$value),$notice["id"]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user_select_delete(Request $request,$id){
|
||||
$params = $request->post();
|
||||
if(count($params["checked_menus"]) <= 0)return Json::fail('删除数据不能为空!');
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
|
||||
$res_uids = explode(",",$notice["uid"]);
|
||||
array_splice($res_uids,0,1);
|
||||
array_splice($res_uids,count($res_uids)-1,1);
|
||||
foreach ($params["checked_menus"] as $key => $value) {
|
||||
array_splice($res_uids,array_search($value,$res_uids),1);
|
||||
}
|
||||
$value = count($res_uids) > 0 ? ",".implode(",",$res_uids)."," : "";
|
||||
UserNoticeModel::edit(array("uid"=>$value),$notice["id"]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function notice($id){
|
||||
$where = Util::getMore([
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$nickname = UserModel::where('uid','IN',$id)->column('uid,nickname');
|
||||
$this->assign('where',$where);
|
||||
$this->assign('uid',$id);
|
||||
$this->assign('nickname',implode(',',$nickname));
|
||||
$this->assign(UserNoticeModel::getUserList($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给指定用户发送站内信息
|
||||
* @param $id
|
||||
*/
|
||||
public function send_user($id = 0,$uid = '')
|
||||
{
|
||||
if(!$id || $uid == '') return JsonService::fail('参数错误');
|
||||
$uid = ",".$uid.",";
|
||||
UserNoticeModel::edit(array("is_send"=>1,"send_time"=>time(),'uid'=>$uid),$id);
|
||||
return Json::successful('发送成功!');
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/wechat/ArticleCategory.php
Normal file
1
application/admin/controller/wechat/ArticleCategory.php
Normal file
File diff suppressed because one or more lines are too long
38
application/admin/controller/wechat/Menus.php
Normal file
38
application/admin/controller/wechat/Menus.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\WechatService;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 微信菜单 控制器
|
||||
* Class Menus
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Menus extends AuthController
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$menus = Db::name('cache')->where('key','wechat_menus')->value('result');
|
||||
$menus = $menus ? : '[]';
|
||||
$this->assign('menus',$menus);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$buttons = $request->post('button/a',[]);
|
||||
if(!count($buttons)) return $this->failed('请添加至少一个按钮');
|
||||
try{
|
||||
WechatService::menuService()->add($buttons);
|
||||
Db::name('cache')->insert(['key'=>'wechat_menus','result'=>json_encode($buttons),'add_time'=>time()],true);
|
||||
return $this->successful('修改成功!');
|
||||
}catch (\Exception $e){
|
||||
return $this->failed($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
171
application/admin/controller/wechat/Reply.php
Normal file
171
application/admin/controller/wechat/Reply.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\wechat\WechatReply;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* 关键字管理 控制器
|
||||
* Class Reply
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Reply extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
if(empty(input('key'))) return $this->failed('请输入参数key');
|
||||
if(empty(input('title'))) return $this->failed('请输入参数title');
|
||||
$replay = WechatReply::where('key',input('key'))->find();
|
||||
$replay_arr =count($replay) ? $replay->toArray() : [];
|
||||
$replay_arr['data'] = json_decode(isset($replay_arr['data']) ? $replay_arr['data'] : '',true);
|
||||
$this->assign('replay_arr',json_encode($replay_arr));
|
||||
$this->assign('key',input('key'));
|
||||
$this->assign('title',input('title'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function one_reply(){
|
||||
$where = Util::postMore([
|
||||
['key'],
|
||||
['add',0],
|
||||
],$this->request);
|
||||
// dump($where);
|
||||
// exit();
|
||||
if(!empty($where['key'])) $replay = WechatReply::where('key',$where['key'])->find();
|
||||
$replay_arr = $replay->toArray();
|
||||
$replay_arr['code'] = 200;
|
||||
$replay_arr['data'] = json_decode($replay_arr['data'],true);
|
||||
if(empty($replay_arr)) {
|
||||
$replay_arr['code'] = 0;
|
||||
}
|
||||
if($where['add'] && empty($where['key'])){
|
||||
$replay_arr['code'] = 0;
|
||||
}
|
||||
exit(json_encode($replay_arr));
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'type',
|
||||
'key',
|
||||
['status',0],
|
||||
['data',[]],
|
||||
],$request);
|
||||
if(!isset($data['type']) && empty($data['type']))
|
||||
return Json::fail('请选择回复类型');
|
||||
if(!in_array($data['type'],WechatReply::$reply_type))
|
||||
return Json::fail('回复类型有误!');
|
||||
if(!isset($data['data']) || !is_array($data['data']))
|
||||
return Json::fail('回复消息参数有误!');
|
||||
$res = WechatReply::redact($data['data'],$data['key'],$data['type'],$data['status']);
|
||||
if(!$res)
|
||||
return Json::fail(WechatReply::getErrorInfo());
|
||||
else
|
||||
return Json::successful('保存成功!',$data);
|
||||
}
|
||||
|
||||
public function upload_img(Request $request)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public function upload_file(Request $request)
|
||||
{
|
||||
$name = $request->post('file');
|
||||
if(!$name) return Json::fail('请上传声音');
|
||||
$autoValidate['size'] = 2097152;
|
||||
$res = Upload::file($name,'wechat/voice',true,$autoValidate);
|
||||
return $res->status === true ? Json::successful('上传成功',$res->filePath) : Json::fail($res->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字回复
|
||||
* */
|
||||
public function keyword(){
|
||||
$where = Util::getMore([
|
||||
['key',''],
|
||||
['type',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatReply::getKeyAll($where));
|
||||
return $this->fetch();
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加关键字
|
||||
* */
|
||||
public function add_keyword(){
|
||||
$key = input('key');
|
||||
if(empty($key)) $key = '';
|
||||
$this->assign('key',$key);
|
||||
$this->assign('dis',1);
|
||||
$this->assign('replay_arr',json_encode(array()));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改关键字
|
||||
* */
|
||||
public function info_keyword(){
|
||||
$key = input('key');
|
||||
if(empty($key)) return $this->failed('参数错误,请重新修改');
|
||||
$replay = WechatReply::where('key',$key)->find();
|
||||
$replay_arr = $replay->toArray();
|
||||
$replay_arr['data'] = json_decode($replay_arr['data'],true);
|
||||
$this->assign('replay_arr',json_encode($replay_arr));
|
||||
$this->assign('key',$key);
|
||||
$this->assign('dis',2);
|
||||
return $this->fetch('add_keyword');
|
||||
}
|
||||
/**
|
||||
* 保存关键字
|
||||
* */
|
||||
public function save_keyword(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'key',
|
||||
'type',
|
||||
['status',0],
|
||||
['data',[]],
|
||||
],$request);
|
||||
// dump($data);
|
||||
// exit();
|
||||
if(!isset($data['key']) && empty($data['key']))
|
||||
return Json::fail('请输入关键字');
|
||||
if(isset($data['key']) && !empty($data['key'])){
|
||||
if(trim($data['key']) == 'subscribe') return Json::fail('请重新输入关键字');
|
||||
if(trim($data['key']) == 'default') return Json::fail('请重新输入关键字');
|
||||
}
|
||||
if(!isset($data['type']) && empty($data['type']))
|
||||
return Json::fail('请选择回复类型');
|
||||
if(!in_array($data['type'],WechatReply::$reply_type))
|
||||
return Json::fail('回复类型有误!');
|
||||
if(!isset($data['data']) || !is_array($data['data']))
|
||||
return Json::fail('回复消息参数有误!');
|
||||
$res = WechatReply::redact($data['data'],$data['key'],$data['type'],$data['status']);
|
||||
if(!$res)
|
||||
return Json::fail(WechatReply::getErrorInfo());
|
||||
else
|
||||
return Json::successful('保存成功!',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除关键字
|
||||
* */
|
||||
public function delete($id){
|
||||
if(!WechatReply::del($id))
|
||||
return Json::fail(WechatReply::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
166
application/admin/controller/wechat/StoreService.php
Normal file
166
application/admin/controller/wechat/StoreService.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
namespace app\admin\controller\wechat;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\wechat\StoreService as ServiceModel;
|
||||
use app\admin\model\wechat\StoreServiceLog as StoreServiceLog;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
|
||||
/**
|
||||
* 客服管理
|
||||
* Class StoreService
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreService extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign(ServiceModel::getList(0));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create(){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['data',''],
|
||||
['tagid_list',''],
|
||||
['groupid','-1'],
|
||||
['sex',''],
|
||||
['export',''],
|
||||
['stair',''],
|
||||
['second',''],
|
||||
['order_stair',''],
|
||||
['order_second',''],
|
||||
['subscribe',''],
|
||||
['now_money',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserModel::systemPage($where));
|
||||
$this->assign(['title'=>'添加客服','save'=>Url::build('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request){
|
||||
$params = $request->post();
|
||||
if(count($params["checked_menus"]) <= 0)return Json::fail('请选择要添加的用户!');
|
||||
if(ServiceModel::where('mer_id',0)->where(array("uid"=>array("in",$params["checked_menus"])))->count())return Json::fail('添加用户中存在已有的客服!');
|
||||
foreach ($params["checked_menus"] as $key => $value) {
|
||||
$now_user = UserModel::get($value);
|
||||
$data[$key]["mer_id"] = 0;
|
||||
$data[$key]["uid"] = $now_user["uid"];
|
||||
$data[$key]["avatar"] = $now_user["headimgurl"];
|
||||
$data[$key]["nickname"] = $now_user["nickname"];
|
||||
$data[$key]["add_time"] = time();
|
||||
}
|
||||
ServiceModel::setAll($data);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$service = ServiceModel::get($id);
|
||||
if(!$service) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::frameImageOne('avatar','客服头像',Url::build('admin/widget.images/index',array('fodder'=>'avatar')),$service['avatar'])->icon('image');
|
||||
$f[] = Form::input('nickname','客服名称',$service["nickname"]);
|
||||
$f[] = Form::input('content','通知内容')->type('textarea');
|
||||
$f[] = Form::radio('status','状态',$service['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('修改数据',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request,$id)
|
||||
{
|
||||
$params = $request->post();
|
||||
if(empty($params["nickname"]))return Json::fail("客服名称不能为空!");
|
||||
// print_r($params);die;
|
||||
$data = array("avatar"=>$params["avatar"],"nickname"=>$params["nickname"],'status'=>$params['status']);
|
||||
ServiceModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!ServiceModel::del($id))
|
||||
return Json::fail(ServiceModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function chat_user($id)
|
||||
{
|
||||
$now_service = ServiceModel::get($id);
|
||||
if(!$now_service) return Json::fail('数据不存在!');
|
||||
$list = ServiceModel::getChatUser($now_service,0);
|
||||
$this->assign(compact('list','now_service'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function chat_list($uid,$to_uid)
|
||||
{
|
||||
$this->assign(StoreServiceLog::getChatList($uid,$to_uid,0));
|
||||
$this->assign('to_uid',$to_uid);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
1
application/admin/controller/wechat/WechatMessage.php
Normal file
1
application/admin/controller/wechat/WechatMessage.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
namespace app\admin\controller\wechat;
use app\admin\controller\AuthController;
use app\admin\model\wechat\WechatMessage as MessageModel;
use service\UtilService as Util;
/**
* 用户扫码点击事件
* Class SystemMessage
* @package app\admin\controller\system
*/
class WechatMessage extends AuthController
{
/**
* 显示操作记录
*/
public function index(){
$where = Util::getMore([
['nickname',''],
['type',''],
['data',''],
],$this->request);
$this->assign('where',$where);
$this->assign('mold',MessageModel::$mold);
$this->assign(MessageModel::systemPage($where));
return $this->fetch();
}
}
|
||||
186
application/admin/controller/wechat/WechatNews.php
Normal file
186
application/admin/controller/wechat/WechatNews.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\wechat\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\wechat\WechatNews as WechatNewsModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 图文管理
|
||||
* Class WechatNews
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class WechatNews extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示后台管理员添加的图文
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($cid = 0)
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
if($cid)
|
||||
$where['cid'] = $cid;
|
||||
else
|
||||
$where['cid'] = '';
|
||||
$this->assign('where',$where);
|
||||
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign(WechatNewsModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示页面 添加和删除
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(){
|
||||
$id = input('id');
|
||||
$cid = input('cid');
|
||||
$news = array();
|
||||
$news['id'] = '';
|
||||
$news['image_input'] = '';
|
||||
$news['title'] = '';
|
||||
$news['author'] = '';
|
||||
$news['content'] = '';
|
||||
$news['synopsis'] = '';
|
||||
$news['url'] = '';
|
||||
$news['cid'] = array();
|
||||
if($id){
|
||||
$news = \app\admin\model\wechat\WechatNews::where('n.id',$id)->alias('n')->field('n.*,c.content')->join('__WECHAT_NEWS_CONTENT__ c','c.nid=n.id')->find();
|
||||
if(!$news) return $this->failedNotice('数据不存在!');
|
||||
$news['cid'] = explode(',',$news['cid']);
|
||||
// dump($news);
|
||||
}
|
||||
$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(empty($all)){
|
||||
$all = ArticleCategoryModel::getField('id,title');//新闻分类
|
||||
$select = 0;
|
||||
}
|
||||
$this->assign('all',$all);
|
||||
$this->assign('news',$news);
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign('select',$select);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图文图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加和修改图文
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function add_new(Request $request){
|
||||
$post = $request->post();
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['cid',[]],
|
||||
'title',
|
||||
'author',
|
||||
'image_input',
|
||||
'content',
|
||||
'synopsis',
|
||||
'share_title',
|
||||
'share_synopsis',
|
||||
['visit',0],
|
||||
['sort',0],
|
||||
'url',
|
||||
['status',1],],$request);
|
||||
$data['cid'] = implode(',',$data['cid']);
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
if($data['id']){
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
WechatNewsModel::beginTrans();
|
||||
$res1 = WechatNewsModel::edit($data,$id,'id');
|
||||
$res2 = WechatNewsModel::setContent($id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
// dump($res);
|
||||
// exit();
|
||||
WechatNewsModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('修改图文成功!',$id);
|
||||
else
|
||||
return Json::fail('修改图文失败!',$id);
|
||||
}else{
|
||||
$data['add_time'] = time();
|
||||
$data['admin_id'] = $this->adminId;
|
||||
WechatNewsModel::beginTrans();
|
||||
$res1 = WechatNewsModel::set($data);
|
||||
$res2 = false;
|
||||
if($res1)
|
||||
$res2 = WechatNewsModel::setContent($res1->id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
WechatNewsModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('添加图文成功!',$res1->id);
|
||||
else
|
||||
return Json::successful('添加图文失败!',$res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图文
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$res = WechatNewsModel::del($id);
|
||||
if(!$res)
|
||||
return Json::fail('删除失败,请稍候再试!');
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function merchantIndex(){
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$where['cid'] = input('cid');
|
||||
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign(WechatNewsModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
284
application/admin/controller/wechat/WechatNewsCategory.php
Normal file
284
application/admin/controller/wechat/WechatNewsCategory.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\article\Article;
|
||||
use service\FormBuilder as Form;
|
||||
use service\JsonService;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use app\admin\model\wechat\WechatReply;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use service\UtilService;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use service\WechatService;
|
||||
use \app\admin\model\wechat\WechatNewsCategory as WechatNewsCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
/**
|
||||
* 图文信息
|
||||
* Class WechatNewsCategory
|
||||
* @package app\admin\controller\wechat
|
||||
*
|
||||
*/
|
||||
class WechatNewsCategory extends AuthController
|
||||
{
|
||||
public function select($callback = '_selectNews$eb'){
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('callback',$callback);
|
||||
$this->assign(WechatNewsCategoryModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatNewsCategoryModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function create(){
|
||||
$f = array();
|
||||
$f[] = Form::input('cate_name','分类名称')->autofocus(1);
|
||||
$f[] = Form::select('new_id','图文列表')->setOptions(function(){
|
||||
$list = ArticleModel::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1)->multiple(1);
|
||||
$form = Form::make_post_form('编辑菜单',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save(Request $request){
|
||||
$data = Util::postMore([
|
||||
'cate_name',
|
||||
['new_id',[]],
|
||||
['sort',0],
|
||||
['add_time',time()],
|
||||
['status',1],],$request);
|
||||
if(!$data['cate_name']) return Json::fail('请输入图文名称');
|
||||
if(empty($data['new_id'])) return Json::fail('请选择图文列表');
|
||||
$data['new_id'] = array_unique($data['new_id']);
|
||||
if(count($data['new_id']) > 8){
|
||||
$data['new_id'] = array_slice($data['new_id'], 0, 8);
|
||||
};
|
||||
$data['new_id'] = implode(',',$data['new_id']);
|
||||
WechatNewsCategoryModel::set($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
public function edit($id){
|
||||
$menu = WechatNewsCategoryModel::get($id);
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$arr_new_id = array_unique(explode(',',$menu->new_id));
|
||||
foreach ($arr_new_id as $k=>$v){
|
||||
$arr_new_id[$k] = intval($v);
|
||||
}
|
||||
$f = array();
|
||||
$f[] = Form::input('cate_name','分类名称',$menu['cate_name'])->autofocus(1);
|
||||
$f[] = Form::select('new_id','图文列表',$arr_new_id)->setOptions(function(){
|
||||
$list = ArticleModel::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1)->multiple(1);
|
||||
$form = Form::make_post_form('编辑图文',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'cate_name',
|
||||
['new_id',[]],
|
||||
['sort',0],
|
||||
['status',1],],$request);
|
||||
if(!$data['cate_name']) return Json::fail('请输入图文名称');
|
||||
if(empty($data['new_id'])) return Json::fail('请选择图文列表');
|
||||
if(count($data['new_id']) > 8){
|
||||
$data['new_id'] = array_slice($data['new_id'], 0, 8);
|
||||
};
|
||||
$data['new_id'] = implode(',',$data['new_id']);;
|
||||
if(!WechatNewsCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
WechatNewsCategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
public function delete($id){
|
||||
if(!WechatNewsCategoryModel::del($id))
|
||||
return Json::fail(WechatNewsCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param int $id
|
||||
* @param string $wechat
|
||||
* $wechat 不为空 发消息 / 空 群发消息
|
||||
*/
|
||||
public function push($id = 0,$wechat = ''){
|
||||
if(!$id) return Json::fail('参数错误');
|
||||
$list = WechatNewsCategoryModel::getWechatNewsItem($id);
|
||||
$wechatNews = [];
|
||||
if($list){
|
||||
if($list['new'] && is_array($list['new'])){
|
||||
foreach ($list['new'] as $kk=>$vv){
|
||||
$wechatNews[$kk]['title'] = $vv['title'];
|
||||
$wechatNews[$kk]['image'] = $vv['image_input'];
|
||||
$wechatNews[$kk]['date'] = date('m月d日',time());
|
||||
$wechatNews[$kk]['description'] = $vv['synopsis'];
|
||||
$wechatNews[$kk]['id'] = $vv['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if($wechat != ''){//客服消息
|
||||
$wechatNews = WechatReply::tidyNews($wechatNews);
|
||||
$message = WechatService::newsMessage($wechatNews);
|
||||
$errorLog = [];//发送失败的用户
|
||||
$user = WechatUser::where('uid','IN',$wechat)->column('nickname,subscribe,openid','uid');
|
||||
if($user){
|
||||
foreach ($user as $v){
|
||||
if($v['subscribe'] && $v['openid']){
|
||||
try {
|
||||
WechatService::staffService()->message($message)->to($v['openid'])->send();
|
||||
} catch (\Exception $e) {
|
||||
$errorLog[] = $v['nickname'].'发送失败';
|
||||
}
|
||||
}else{
|
||||
$errorLog[] = $v['nickname'].'没有关注发送失败(不是微信公众号用户)';
|
||||
}
|
||||
}
|
||||
}else return Json::fail('发送失败,参数不正确');
|
||||
if(!count($errorLog)) return Json::successful('全部发送成功');
|
||||
else return Json::successful(implode(',',$errorLog).',剩余的发送成功');
|
||||
}else{//群发消息
|
||||
// if($list){
|
||||
// if($list['new'] && is_array($list['new'])){
|
||||
// foreach ($list['new'] as $kk=>$vv){
|
||||
// $wechatNews[$kk]['title'] = $vv['title'];
|
||||
// $wechatNews[$kk]['thumb_media_id'] = $vv['image_input'];
|
||||
// $wechatNews[$kk]['author'] = $vv['author'];
|
||||
// $wechatNews[$kk]['digest'] = $vv['synopsis'];
|
||||
// $wechatNews[$kk]['show_cover_pic'] = 1;
|
||||
// $wechatNews[$kk]['content'] = Db::name('articleContent')->where('nid',$vv["id"])->value('content');
|
||||
// $wechatNews[$kk]['content_source_url'] = $vv['url'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//6sFx6PzPF2v_Lv4FGOMzz-oQunU2Z3wrOWb-7zS508E
|
||||
//6sFx6PzPF2v_Lv4FGOMzz7SUUuamgWwlqdVfhQ5ALT4
|
||||
// foreach ($wechatNews as $k=>$v){
|
||||
// $material = WechatService::materialService()->uploadImage(UtilService::urlToPath($v['thumb_media_id']));
|
||||
// dump($material);
|
||||
// $wechatNews[$k]['thumb_media_id'] = $material->media_id;
|
||||
// }
|
||||
// $mediaIdNews = WechatService::uploadNews($wechatNews);
|
||||
// $res = WechatService::sendNewsMessage($mediaIdNews->media_id);
|
||||
// if($res->errcode) return Json::fail($res->errmsg);
|
||||
// else return Json::successful('推送成功');
|
||||
// dump($mediaIdNews);
|
||||
// dump($res);
|
||||
}
|
||||
}
|
||||
|
||||
public function send_news($id = ''){
|
||||
if($id == '') return $this->failed('参数错误');
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('wechat',$id);
|
||||
$this->assign(WechatNewsCategoryModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function append(){
|
||||
$this->assign('list',[
|
||||
[
|
||||
'id'=>0,
|
||||
'title'=>'',
|
||||
'author'=>$this->adminInfo->real_name,
|
||||
'content'=>'',
|
||||
'image_input'=>'/public/system/module/wechat/news/images/image.png',
|
||||
'synopsis'=>'',
|
||||
]
|
||||
]);
|
||||
$this->assign('id',0);
|
||||
$this->assign('author',$this->adminInfo->real_name);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function append_save(Request $request){
|
||||
$data = UtilService::postMore([
|
||||
['list',[]],
|
||||
['id',0]
|
||||
],$request);
|
||||
$id = [];
|
||||
$countList = count($data['list']);
|
||||
if(!$countList) return JsonService::fail('请添加图文');
|
||||
Article::beginTrans();
|
||||
foreach ($data['list'] as $k=>$v){
|
||||
if($v['title'] == '') return JsonService::fail('标题不能为空');
|
||||
if($v['author'] == '') return JsonService::fail('作者不能为空');
|
||||
if($v['content'] == '') return JsonService::fail('正文不能为空');
|
||||
if($v['synopsis'] == '') return JsonService::fail('摘要不能为空');
|
||||
if($v['id']){
|
||||
$idC = $v['id'];
|
||||
unset($v['id']);
|
||||
Article::edit($v,$idC);
|
||||
Db::name('ArticleContent')->where('nid',$idC)->update(['content'=>$v['content']]);
|
||||
$data['list'][$k]['id'] = $idC;
|
||||
$id[] = $idC;
|
||||
}else{
|
||||
unset($v['id']);
|
||||
$res = Article::set($v)->toArray();
|
||||
$id[] = $res['id'];
|
||||
$data['list'][$k]['id'] = $res['id'];
|
||||
Db::name('ArticleContent')->insert(['content'=>$v['content'],'nid'=>$res['id']]);
|
||||
}
|
||||
}
|
||||
$countId = count($id);
|
||||
if($countId != $countList){
|
||||
Article::checkTrans(false);
|
||||
if($data['id']) return JsonService::fail('修改失败');
|
||||
else return JsonService::fail('添加失败');
|
||||
}else{
|
||||
Article::checkTrans(true);
|
||||
$newsCategory['cate_name'] = $data['list'][0]['title'];
|
||||
$newsCategory['new_id'] = implode(',',$id);
|
||||
$newsCategory['sort'] = 0;
|
||||
$newsCategory['add_time'] = time();
|
||||
$newsCategory['status'] = 1;
|
||||
if($data['id']) {
|
||||
WechatNewsCategoryModel::edit($newsCategory,$data['id']);
|
||||
return JsonService::successful('修改成功');
|
||||
}else{
|
||||
WechatNewsCategoryModel::set($newsCategory);
|
||||
return JsonService::successful('添加成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function modify($id){
|
||||
$menu = WechatNewsCategoryModel::get($id);
|
||||
$list = Article::getArticleList($menu['new_id']);
|
||||
$this->assign('list',$list);
|
||||
$this->assign('id',$id);
|
||||
$this->assign('author',$this->adminInfo->real_name);
|
||||
return $this->fetch('append');
|
||||
}
|
||||
|
||||
}
|
||||
130
application/admin/controller/wechat/WechatTemplate.php
Normal file
130
application/admin/controller/wechat/WechatTemplate.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use service\FormBuilder as Form;
|
||||
use service\UtilService as Util;
|
||||
use service\JsonService as Json;
|
||||
use service\WechatTemplateService;
|
||||
use think\Cache;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\wechat\WechatTemplate as WechatTemplateModel;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
|
||||
/**
|
||||
* 微信模板消息控制器
|
||||
* Class WechatTemplate
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class WechatTemplate extends AuthController
|
||||
{
|
||||
|
||||
protected $cacheTag = '_system_wechat';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['status','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatTemplateModel::SystemPage($where));
|
||||
$industry = Cache::tag($this->cacheTag)->remember('_wechat_industry',function(){
|
||||
$cache = WechatTemplateService::getIndustry();
|
||||
if(!$cache) return [];
|
||||
Cache::tag($this->cacheTag,['_wechat_industry']);
|
||||
return $cache->toArray();
|
||||
},0)?:[];
|
||||
!is_array($industry) && $industry = [];
|
||||
$this->assign('industry',$industry);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板消息
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号');
|
||||
$f[] = Form::input('tempid','模板ID');
|
||||
$f[] = Form::input('name','模板名');
|
||||
$f[] = Form::input('content','回复内容')->type('textarea');
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加模板消息',$f,Url::build('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempkey',
|
||||
'tempid',
|
||||
'name',
|
||||
'content',
|
||||
['status',0]
|
||||
],$request);
|
||||
if($data['tempkey'] == '') return Json::fail('请输入模板编号');
|
||||
if($data['tempkey'] != '' && WechatTemplateModel::be($data['tempkey'],'tempkey'))
|
||||
return Json::fail('请输入模板编号已存在,请重新输入');
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if($data['name'] == '') return Json::fail('请输入模板名');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$data['add_time'] = time();
|
||||
WechatTemplateModel::set($data);
|
||||
return Json::successful('添加模板消息成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑模板消息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = WechatTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号',$product->getData('tempkey'))->disabled(1);
|
||||
$f[] = Form::input('name','模板名',$product->getData('name'))->disabled(1);
|
||||
$f[] = Form::input('tempid','模板ID',$product->getData('tempid'));
|
||||
$f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑模板消息',$f,Url::build('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempid',
|
||||
['status',0]
|
||||
],$request);
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = WechatTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
WechatTemplateModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板消息
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!WechatTemplateModel::del($id))
|
||||
return Json::fail(WechatTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
application/admin/controller/wechat/WechatUser.php
Normal file
1
application/admin/controller/wechat/WechatUser.php
Normal file
File diff suppressed because one or more lines are too long
7
application/admin/controller/wechat/index.php
Normal file
7
application/admin/controller/wechat/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/18 0018
|
||||
* Time: 上午 10:44
|
||||
*/
|
||||
229
application/admin/controller/widget/Images.php
Normal file
229
application/admin/controller/widget/Images.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\widget;
|
||||
use function Sodium\add;
|
||||
use think\Request;
|
||||
use think\Url;
|
||||
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
|
||||
use app\admin\model\system\SystemAttachmentCategory as Category;
|
||||
use app\admin\controller\AuthController;
|
||||
use service\UploadService as Upload;
|
||||
use service\JsonService as Json;
|
||||
use service\UtilService as Util;
|
||||
use service\FormBuilder as Form;
|
||||
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemFile
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class Images extends AuthController
|
||||
{
|
||||
const dir = [
|
||||
0=>['tid'=>0,'name'=>'编辑器','path'=>'editor']
|
||||
,1=>['tid'=>1,'name'=>'产品图片','path'=>'store/product']
|
||||
,2=>['tid'=>2,'name'=>'拼团图片','path'=>'store/combination']
|
||||
,3=>['tid'=>3,'name'=>'砍价图片','path'=>'store/bargain']
|
||||
,4=>['tid'=>4,'name'=>'秒杀图片','path'=>'store/seckill']
|
||||
,5=>['tid'=>5,'name'=>'文章图片','path'=>'wechat/image']
|
||||
,6=>['tid'=>6,'name'=>'组合数据图','path'=>'common']
|
||||
];
|
||||
/**
|
||||
* 附件列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pid = input('pid')!=''?input('pid'):0;
|
||||
$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');
|
||||
}
|
||||
/**
|
||||
* 编辑器上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$pid = input('pid')!=''?input('pid'):0;
|
||||
|
||||
$res = Upload::image('file',$pid.'/'.date('Ymd'));
|
||||
//产品图片上传记录
|
||||
$fileInfo = $res->fileInfo->getinfo();
|
||||
SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,'',$pid);
|
||||
$info = array(
|
||||
// "originalName" => $fileInfo['name'],
|
||||
// "name" => $res->fileInfo->getSaveName(),
|
||||
// "url" => '.'.$res->dir,
|
||||
// "size" => $fileInfo['size'],
|
||||
// "type" => $fileInfo['type'],
|
||||
// "state" => "SUCCESS"
|
||||
'code' =>200,
|
||||
'msg' =>'SUCCESS',
|
||||
'src' =>$res->dir
|
||||
);
|
||||
echo json_encode($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* ajax 提交删除
|
||||
*/
|
||||
public function delete(){
|
||||
$request = Request::instance();
|
||||
$post = $request->post();
|
||||
if(empty($post['imageid'] ))
|
||||
Json::fail('还没选择要删除的图片呢?');
|
||||
foreach ($post['imageid'] as $v){
|
||||
self::deleteimganddata($v);
|
||||
}
|
||||
Json::successful('删除成功');
|
||||
}
|
||||
|
||||
/**删除图片和数据记录
|
||||
* @param $att_id
|
||||
*/
|
||||
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'],'.'));
|
||||
SystemAttachmentModel::where(['att_id'=>$att_id])->delete();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移动图片分类
|
||||
*/
|
||||
public function moveimg($imgaes){
|
||||
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::hidden('imgaes',$imgaes);
|
||||
$formbuider[] = Form::select('pid','选择分类')->setOptions(function (){
|
||||
$list = Category::getCateList();
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$form = Form::make_post_form('编辑分类',$formbuider,Url::build('moveImgCecate'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**移动图片
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function moveImgCecate(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'imgaes'
|
||||
],$request);
|
||||
if($data['imgaes'] == '') return Json::fail('请选择图片');
|
||||
if(!$data['pid']) return Json::fail('请选择分类');
|
||||
$res = SystemAttachmentModel::where('att_id','in',$data['imgaes'])->update(['pid'=>$data['pid']]);
|
||||
if($res)
|
||||
Json::successful('移动成功');
|
||||
else
|
||||
Json::fail('移动失败!');
|
||||
}
|
||||
/**
|
||||
* ajax 添加分类
|
||||
*/
|
||||
public function addcate($id){
|
||||
$id = $id || 0;
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::select('pid','上级分类','0')->setOptions(function (){
|
||||
$list = Category::getCateList(0);
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$formbuider[] = Form::input('name','分类名称');
|
||||
$form = Form::make_post_form('添加分类',$formbuider,Url::build('saveCate'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 添加分类
|
||||
*/
|
||||
public function saveCate(){
|
||||
$request = Request::instance();
|
||||
$post = $request->post();
|
||||
$data['pid'] = $post['pid'];
|
||||
$data['name'] = $post['name'];
|
||||
if(empty($post['name'] ))
|
||||
Json::fail('分类名称不能为空!');
|
||||
$res = Category::create($data);
|
||||
if($res)
|
||||
Json::successful('添加成功');
|
||||
else
|
||||
Json::fail('添加失败!');
|
||||
|
||||
}
|
||||
/**
|
||||
* 编辑分类
|
||||
*/
|
||||
public function editcate($id){
|
||||
$Category = Category::get($id);
|
||||
if(!$Category) return Json::fail('数据不存在!');
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::hidden('id',$id);
|
||||
$formbuider[] = Form::select('pid','上级分类',(string)$Category->getData('pid'))->setOptions(function ()use($id){
|
||||
$list = Category::getCateList();
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$formbuider[] = Form::input('name','分类名称',$Category->getData('name'));
|
||||
$form = Form::make_post_form('编辑分类',$formbuider,Url::build('updateCate'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 更新分类
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function updateCate(Request $request,$id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'name'
|
||||
],$request);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['name']) return Json::fail('请输入分类名称');
|
||||
Category::edit($data,$id);
|
||||
return Json::successful('分类编辑成功!');
|
||||
}
|
||||
/**
|
||||
* 删除分类
|
||||
*/
|
||||
public function deletecate($id){
|
||||
$chdcount = Category::where('pid',$id)->count();
|
||||
if($chdcount) return Json::fail('有子栏目不能删除');
|
||||
$chdcount = SystemAttachmentModel::where('pid',$id)->count();
|
||||
if($chdcount) return Json::fail('栏目内有图片不能删除');
|
||||
if(Category::del($id))
|
||||
return Json::successful('删除成功!');
|
||||
else
|
||||
return Json::fail('删除失败');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
49
application/admin/controller/widget/Widgets.php
Normal file
49
application/admin/controller/widget/Widgets.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\widget;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemFile
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class Widgets extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* icon
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function icon()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 会员列页面
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function userlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 产品列表页
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function productlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 图文列表页
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function newtlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
application/admin/model/article/Article.php
Normal file
1
application/admin/model/article/Article.php
Normal file
File diff suppressed because one or more lines are too long
85
application/admin/model/article/ArticleCategory.php
Normal file
85
application/admin/model/article/ArticleCategory.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
namespace app\admin\model\article;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
use basic\ModelBasic;
|
||||
use service\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 文章分类model
|
||||
* Class ArticleCategory
|
||||
* @package app\admin\model\wechat
|
||||
*/
|
||||
class ArticleCategory extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 获取系统分页数据 分类
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where = array()){
|
||||
$model = new self;
|
||||
if($where['title'] !== '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
if($where['status'] !== '') $model = $model->where('status',$where['status']);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->where('hidden',0);
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function delArticleCategory($id)
|
||||
{
|
||||
if(count(self::getArticle($id,'*'))>0)
|
||||
return self::setErrorInfo('请先删除改分类下的文章!');
|
||||
return self::edit(['is_del'=>1],$id,'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类名称和id field
|
||||
* @param $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getField($field){
|
||||
return self::where('is_del','eq',0)->where('status','eq',1)->where('hidden','eq',0)->column($field);
|
||||
}
|
||||
/**
|
||||
* 分级排序列表
|
||||
* @param null $model
|
||||
* @return array
|
||||
*/
|
||||
public static function getTierList($model = null)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
return Util::sortListTier($model->select()->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类底下的文章
|
||||
* id 分类表中的分类id
|
||||
* return array
|
||||
* */
|
||||
public static function getArticle($id,$field){
|
||||
$res = ArticleModel::where('status',1)->where('hide',0)->column($field,'id');
|
||||
$new_res = array();
|
||||
foreach ($res as $k=>$v){
|
||||
$cid_arr = explode(',',$v['cid']);
|
||||
if(in_array($id,$cid_arr)){
|
||||
$new_res[$k] = $res[$k];
|
||||
}
|
||||
}
|
||||
return $new_res;
|
||||
}
|
||||
|
||||
}
|
||||
262
application/admin/model/finance/FinanceModel.php
Normal file
262
application/admin/model/finance/FinanceModel.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/16 0016
|
||||
* Time: 11:07
|
||||
*/
|
||||
|
||||
namespace app\admin\model\finance;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\ExportService;
|
||||
use app\wap\model\user\UserBill;
|
||||
use app\admin\model\user\User;
|
||||
use service\PHPExcelService;
|
||||
/*数据统计处理*/
|
||||
class FinanceModel extends ModelBasic
|
||||
{
|
||||
protected $name = 'user_bill';
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 处理金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where)
|
||||
{
|
||||
$model = new self;
|
||||
//翻页
|
||||
$limit = $where['limit'];
|
||||
$offset= $where['offset'];
|
||||
$limit = $offset.','.$limit;
|
||||
//排序
|
||||
$order = '';
|
||||
if(!empty($where['sort'])&&!empty($where['sortOrder'])){
|
||||
$order = $where['sort'].' '.$where['sortOrder'];
|
||||
}
|
||||
unset($where['limit']);unset($where['offset']);
|
||||
unset($where['sort']);unset($where['sortOrder']);
|
||||
if(!empty($where['add_time'])){
|
||||
list($startTime,$endTime) = explode(' - ',$where['add_time']);
|
||||
$where['add_time'] = array('between',[strtotime($startTime),strtotime($endTime)]);
|
||||
}else{
|
||||
$where['add_time'] = array('between',[strtotime(date('Y/m').'/01'),strtotime(date('Y/m').'/'.date('t'))]);
|
||||
}
|
||||
if(empty($where['title'])){
|
||||
unset($where['title']);
|
||||
}
|
||||
|
||||
$total = $model->where($where)->count();
|
||||
$rows = $model->where($where)->order($order)->limit($limit)->select()->each(function($e){
|
||||
return $e['add_time'] = date('Y-m-d H:i:s',$e['add_time']);
|
||||
})->toArray();
|
||||
return compact('total','rows');
|
||||
}
|
||||
public static function getBillList($where){
|
||||
// \think\Db::listen(function($sql, $time, $explain){
|
||||
// // 记录SQL
|
||||
// echo $sql. ' ['.$time.'s]';
|
||||
// // 查看性能分析结果
|
||||
//// dump($explain);
|
||||
// });
|
||||
$data=($data=self::setWhereList($where)->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray():[];
|
||||
$count=self::setWhereList($where)->count();
|
||||
return compact('data','count');
|
||||
}
|
||||
public static function SaveExport($where){
|
||||
$data=($data=self::setWhereList($where)->select()) && count($data) ? $data->toArray():[];
|
||||
$export = [];
|
||||
foreach ($data as $value){
|
||||
$export[]=[
|
||||
$value['uid'],
|
||||
$value['nickname'],
|
||||
$value['pm']==0 ? '-'.$value['number']:$value['number'],
|
||||
$value['title'],
|
||||
$value['mark'],
|
||||
$value['add_time'],
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['会员ID','昵称','金额/积分','类型','备注','创建时间'])
|
||||
->setExcelTile('资金监控', '资金监控',date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
public static function setWhereList($where){
|
||||
$time['data']='';
|
||||
if($where['start_time']!='' && $where['end_time']!=''){
|
||||
$time['data']=$where['start_time'].' - '.$where['end_time'];
|
||||
}
|
||||
$model=self::getModelTime($time,self::alias('A')
|
||||
->join('user B','B.uid=A.uid')
|
||||
->where('A.category','not in','integral')
|
||||
->order('A.add_time desc'),'A.add_time');
|
||||
if(trim($where['type'])!=''){
|
||||
$model=$model->where('A.type',$where['type']);
|
||||
}else{
|
||||
$model=$model->where('A.type','not in','gain,system_sub,deduction,sign');
|
||||
}
|
||||
if($where['nickname']!=''){
|
||||
$model=$model->where('B.nickname|B.uid','like',"%$where[nickname]%");
|
||||
}
|
||||
return $model->field(['A.*','FROM_UNIXTIME(A.add_time,"%Y-%m-%d %H:%i:%s") as add_time','B.uid','B.nickname']);
|
||||
}
|
||||
/**
|
||||
* 获取营业数据
|
||||
*/
|
||||
public static function getOrderInfo($where)
|
||||
{
|
||||
$orderinfo = self::getTimeWhere($where)
|
||||
->field('sum(total_price) total_price,sum(cost) cost,sum(pay_postage) pay_postage,sum(pay_price) pay_price,sum(coupon_price) coupon_price,sum(deduction_price) deduction_price,from_unixtime(pay_time,\'%Y-%m-%d\') pay_time')->order('pay_time')->group('from_unixtime(pay_time,\'%Y-%m-%d\')')->select()->toArray();
|
||||
$price = 0;
|
||||
$postage = 0;
|
||||
$deduction = 0;
|
||||
$coupon = 0;
|
||||
$cost = 0;
|
||||
foreach ($orderinfo as $info) {
|
||||
$price = bcadd($price, $info['total_price'], 2);//应支付
|
||||
$postage = bcadd($postage, $info['pay_postage'], 2);//邮费
|
||||
$deduction = bcadd($deduction, $info['deduction_price'], 2);//抵扣
|
||||
$coupon = bcadd($coupon, $info['coupon_price'], 2);//优惠券
|
||||
$cost = bcadd($cost, $info['cost'], 2);//成本
|
||||
}
|
||||
return compact('orderinfo', 'price', 'postage', 'deduction', 'coupon', 'cost');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
*/
|
||||
public static function statusByWhere($status, $model = null)
|
||||
{
|
||||
if ($model == null) $model = new self;
|
||||
if ('' === $status)
|
||||
return $model;
|
||||
else if ($status == 'weixin')//微信支付
|
||||
return $model->where('pay_type', 'weixin');
|
||||
else if ($status == 'yue')//余额支付
|
||||
return $model->where('pay_type', 'yue');
|
||||
else if ($status == 'offline')//线下支付
|
||||
return $model->where('pay_type', 'offline');
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getTimeWhere($where, $model = null)
|
||||
{
|
||||
return self::getTime($where)->where('paid', 1)->where('refund_status', 0);
|
||||
}
|
||||
/**
|
||||
* 获取时间区间
|
||||
*/
|
||||
public static function getTime($where,$model=null,$prefix='add_time'){
|
||||
if ($model == null) $model = new self;
|
||||
if ($where['data'] == '') {
|
||||
switch ($where['date']){
|
||||
case 'today':case 'week':case 'month':case 'year':
|
||||
$model=$model->whereTime($prefix,$where['date']);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
list($startTime, $endTime) = explode(' - ', $where['data']);
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取新增消费
|
||||
*/
|
||||
public static function getConsumption($where)
|
||||
{
|
||||
$consumption=self::getTime($where,new UserBill,'b.add_time')->alias('a')->join('user b','a.uid = b.uid')
|
||||
->field('sum(a.number) number')
|
||||
->where('a.type','pay_product')->find()->toArray();
|
||||
return $consumption;
|
||||
}
|
||||
/**
|
||||
* 获取拼团商品
|
||||
*/
|
||||
public static function getPink($where)
|
||||
{
|
||||
$pink = self::getTimeWhere($where)->where('pink_id', 'neq', 0)->sum('pay_price');
|
||||
return $pink;
|
||||
}
|
||||
/**
|
||||
* 获取秒杀商品
|
||||
*/
|
||||
public static function getSeckill($where){
|
||||
$seckill=self::getTimeWhere($where)->where('seckill_id', 'neq', 0)->sum('pay_price');
|
||||
return $seckill;
|
||||
}
|
||||
/**
|
||||
* 获取普通商品数
|
||||
*/
|
||||
public static function getOrdinary($where)
|
||||
{
|
||||
$ordinary = self::getTimeWhere($where)->where('pink_id', 'eq', 0)->where('seckill_id','eq','0')->sum('pay_price');
|
||||
return $ordinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户充值
|
||||
*/
|
||||
public static function getRecharge($where)
|
||||
{
|
||||
$Recharge = self::getTime($where,new UserBill)->where('type', 'system_add')->where('category','now_money')->sum('number');
|
||||
return $Recharge;
|
||||
}
|
||||
/**
|
||||
* 获取推广金
|
||||
*/
|
||||
public static function getExtension($where)
|
||||
{
|
||||
$extension = self::getTime($where,new UserBill)->where('type', 'brokerage')->where('category','now_money')->sum('number');
|
||||
return $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近交易
|
||||
*/
|
||||
public static function trans()
|
||||
{
|
||||
$trans = self::alias('a')
|
||||
->join('user b', 'a.uid=b.uid')
|
||||
->join('store_order_cart_info c', 'a.id=c.oid')
|
||||
->join('store_product d', 'c.product_id=d.id')
|
||||
->field('b.nickname,a.pay_price,d.store_name')
|
||||
->order('a.add_time DESC')
|
||||
->limit('6')
|
||||
->select()->toArray();
|
||||
return $trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出表格
|
||||
*/
|
||||
public static function systemTable($where){
|
||||
$orderinfos=self::getOrderInfo($where);
|
||||
if($where['export'] == 1){
|
||||
$export = [];
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
foreach($orderinfo as $info){
|
||||
$time=$info['pay_time'];
|
||||
$price = $info['total_price']+$info['pay_postage'];
|
||||
$zhichu = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$profit = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
$deduction=$info['deduction_price'];//积分抵扣
|
||||
$coupon=$info['coupon_price'];//优惠
|
||||
$cost=$info['cost'];//成本
|
||||
$export[] = [$time,$price,$zhichu,$cost,$coupon,$deduction,$profit];
|
||||
}
|
||||
// ExportService::exportCsv($export,'统计'.time(),['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)']);
|
||||
dump($export);
|
||||
PHPExcelService::setExcelHeader(['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)'])->setExcelTile('财务统计', '财务统计',date('Y-m-d H:i:s',time()))->setExcelContent($export)->ExcelSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
658
application/admin/model/order/StoreOrder.php
Normal file
658
application/admin/model/order/StoreOrder.php
Normal file
@ -0,0 +1,658 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\order;
|
||||
|
||||
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use app\admin\model\ump\StorePink;
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use service\PHPExcelService;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\WechatTemplateService;
|
||||
use think\Url;
|
||||
use think\Db;
|
||||
/**
|
||||
* 订单管理Model
|
||||
* Class StoreOrder
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreOrder extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where,$userid){
|
||||
$model = self::getOrderWhere($where,self::alias('a')->join('user r','r.uid=a.uid','LEFT'),'a.','r')->field('a.*,r.nickname');
|
||||
if($where['order']){
|
||||
$model = $model->order('a.'.$where['order']);
|
||||
}else{
|
||||
$model = $model->order('a.id desc');
|
||||
}
|
||||
if($where['export'] == 1){
|
||||
$list = $model->select()->toArray();
|
||||
$export = [];
|
||||
foreach ($list as $index=>$item){
|
||||
|
||||
if ($item['pay_type'] == 'weixin'){
|
||||
$payType = '微信支付';
|
||||
}elseif($item['pay_type'] == 'yue'){
|
||||
$payType = '余额支付';
|
||||
}elseif($item['pay_type'] == 'offline'){
|
||||
$payType = '线下支付';
|
||||
}else{
|
||||
$payType = '其他支付';
|
||||
}
|
||||
|
||||
$_info = db('store_order_cart_info')->where('oid',$item['id'])->column('cart_info');
|
||||
$goodsName = [];
|
||||
foreach ($_info as $k=>$v){
|
||||
$v = json_decode($v,true);
|
||||
$goodsName[] = implode(
|
||||
[$v['productInfo']['store_name'],
|
||||
isset($v['productInfo']['attrInfo']) ? '('.$v['productInfo']['attrInfo']['suk'].')' : '',
|
||||
"[{$v['cart_num']} * {$v['truePrice']}]"
|
||||
],' ');
|
||||
}
|
||||
$item['cartInfo'] = $_info;
|
||||
$export[] = [
|
||||
$item['order_id'],$payType,
|
||||
$item['total_num'],$item['total_price'],$item['total_postage'],$item['pay_price'],$item['refund_price'],
|
||||
$item['mark'],$item['remark'],
|
||||
[$item['real_name'],$item['user_phone'],$item['user_address']],
|
||||
$goodsName,
|
||||
[$item['paid'] == 1? '已支付':'未支付','支付时间: '.($item['pay_time'] > 0 ? date('Y/md H:i',$item['pay_time']) : '暂无')]
|
||||
|
||||
];
|
||||
$list[$index] = $item;
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['订单号','支付方式','商品总数','商品总价','邮费','支付金额','退款金额','用户备注','管理员备注','收货人信息','商品信息','支付状态'])
|
||||
->setExcelTile('订单导出','订单信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
return self::page($model,function ($item){
|
||||
$item['nickname'] = WechatUser::where('uid',$item['uid'])->value('nickname');
|
||||
$_info = db('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select();
|
||||
foreach ($_info as $k=>$v){
|
||||
$_info[$k]['cart_info'] = json_decode($v['cart_info'],true);
|
||||
}
|
||||
$item['_info'] = $_info;
|
||||
if($item['pink_id'] && $item['combination_id']){
|
||||
$pinkStatus = StorePink::where('order_id_key',$item['id'])->value('status');
|
||||
if($pinkStatus == 1){
|
||||
$item['pink_name'] = '[拼团订单]正在进行中';
|
||||
$item['color'] = '#f00';
|
||||
}else if($pinkStatus == 2){
|
||||
$item['pink_name'] = '[拼团订单]已完成';
|
||||
$item['color'] = '#00f';
|
||||
}else if($pinkStatus == 3){
|
||||
$item['pink_name'] = '[拼团订单]未完成';
|
||||
$item['color'] = '#f0f';
|
||||
}else{
|
||||
$item['pink_name'] = '[拼团订单]历史订单';
|
||||
$item['color'] = '#457856';
|
||||
}
|
||||
}else{
|
||||
if($item['seckill_id']){
|
||||
$item['pink_name'] = '[秒杀订单]';
|
||||
$item['color'] = '#32c5e9';
|
||||
}else{
|
||||
$item['pink_name'] = '[普通订单]';
|
||||
$item['color'] = '#895612';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},$where);
|
||||
}
|
||||
|
||||
public static function statusByWhere($status,$model = null,$alert='')
|
||||
{
|
||||
if($model == null) $model = new self;
|
||||
if('' === $status)
|
||||
return $model;
|
||||
else if($status == 0)//未支付
|
||||
return $model->where($alert.'paid',0)->where($alert.'status',0)->where($alert.'refund_status',0);
|
||||
else if($status == 1)//已支付 未发货
|
||||
return $model->where($alert.'paid',1)->where($alert.'status',0)->where($alert.'refund_status',0);
|
||||
else if($status == 2)//已支付 待收货
|
||||
return $model->where($alert.'paid',1)->where($alert.'status',1)->where($alert.'refund_status',0);
|
||||
else if($status == 3)// 已支付 已收货 待评价
|
||||
return $model->where($alert.'paid',1)->where($alert.'status',2)->where($alert.'refund_status',0);
|
||||
else if($status == 4)// 交易完成
|
||||
return $model->where($alert.'paid',1)->where($alert.'status',3)->where($alert.'refund_status',0);
|
||||
else if($status == -1)//退款中
|
||||
return $model->where($alert.'paid',1)->where($alert.'refund_status',1);
|
||||
else if($status == -2)//已退款
|
||||
return $model->where($alert.'paid',1)->where($alert.'refund_status',2);
|
||||
else if($status == -3)//退款
|
||||
return $model->where($alert.'paid',1)->where($alert.'refund_status','in','1,2');
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function timeQuantumWhere($startTime = null,$endTime = null,$model = null)
|
||||
{
|
||||
if($model === null) $model = new self;
|
||||
if($startTime != null && $endTime != null)
|
||||
$model = $model->where('add_time','>',strtotime($startTime))->where('add_time','<',strtotime($endTime));
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function changeOrderId($orderId)
|
||||
{
|
||||
$ymd = substr($orderId,2,8);
|
||||
$key = substr($orderId,16);
|
||||
return 'wx'.$ymd.date('His').$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 线下付款
|
||||
* @param $id
|
||||
* @return $this
|
||||
*/
|
||||
public static function updateOffline($id){
|
||||
$orderId = self::where('id',$id)->value('order_id');
|
||||
$res = self::where('order_id',$orderId)->update(['paid'=>1,'pay_time'=>time()]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款发送模板消息
|
||||
* @param $oid
|
||||
* $oid 订单id key
|
||||
*/
|
||||
public static function refundTemplate($data,$oid)
|
||||
{
|
||||
$order = self::where('id',$oid)->find();
|
||||
WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($order['uid']),WechatTemplateService::ORDER_REFUND_STATUS, [
|
||||
'first'=>'亲,您购买的商品已退款,本次退款'.$data['refund_price'].'金额',
|
||||
'keyword1'=>$order['order_id'],
|
||||
'keyword2'=>$order['pay_price'],
|
||||
'keyword3'=>date('Y-m-d H:i:s',$order['add_time']),
|
||||
'remark'=>'点击查看订单详情'
|
||||
],Url::build('wap/My/order',['uni'=>$order['order_id']],true,true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
* @param $where
|
||||
* @param $model
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOrderWhere($where,$model,$aler='',$join=''){
|
||||
// $model = $model->where('combination_id',0);
|
||||
if($where['status'] != '') $model = self::statusByWhere($where['status'],$model,$aler);
|
||||
if($where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where($aler.'is_del',$where['is_del']);
|
||||
if($where['combination_id'] =='普通订单'){
|
||||
$model = $model->where($aler.'combination_id',0)->where($aler.'seckill_id',0);
|
||||
}
|
||||
if($where['combination_id'] =='拼团订单'){
|
||||
$model = $model->where($aler.'combination_id',">",0)->where($aler.'pink_id',">",0);
|
||||
}
|
||||
if($where['combination_id'] =='秒杀订单'){
|
||||
$model = $model->where($aler.'seckill_id',">",0);
|
||||
}
|
||||
|
||||
if($where['real_name'] != ''){
|
||||
$model = $model->where($aler.'order_id|'.$aler.'real_name|'.$aler.'user_phone'.($join ? '|'.$join.'.nickname|'.$join.'.uid':''),'LIKE',"%$where[real_name]%");
|
||||
}
|
||||
if($where['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$where['data']);
|
||||
$model = $model->where($aler.'add_time','>',strtotime($startTime));
|
||||
$model = $model->where($aler.'add_time','<',strtotime($endTime));
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理订单金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPrice($where){
|
||||
$model = new self;
|
||||
$price = array();
|
||||
$price['pay_price'] = 0;//支付金额
|
||||
$price['refund_price'] = 0;//退款金额
|
||||
$price['pay_price_wx'] = 0;//微信支付金额
|
||||
$price['pay_price_yue'] = 0;//余额支付金额
|
||||
$price['pay_price_offline'] = 0;//线下支付金额
|
||||
$price['pay_price_other'] = 0;//其他支付金额
|
||||
$price['use_integral'] = 0;//用户使用积分
|
||||
$price['back_integral'] = 0;//退积分总数
|
||||
$price['deduction_price'] = 0;//抵扣金额
|
||||
$price['total_num'] = 0; //商品总数
|
||||
$model = self::getOrderWhere($where,$model);
|
||||
$list = $model->select()->toArray();
|
||||
foreach ($list as $v){
|
||||
$price['total_num'] = bcadd($price['total_num'],$v['total_num'],0);
|
||||
$price['pay_price'] = bcadd($price['pay_price'],$v['pay_price'],2);
|
||||
$price['refund_price'] = bcadd($price['refund_price'],$v['refund_price'],2);
|
||||
$price['use_integral'] = bcadd($price['use_integral'],$v['use_integral'],2);
|
||||
$price['back_integral'] = bcadd($price['back_integral'],$v['back_integral'],2);
|
||||
$price['deduction_price'] = bcadd($price['deduction_price'],$v['deduction_price'],2);
|
||||
if ($v['pay_type'] == 'weixin'){
|
||||
$price['pay_price_wx'] = bcadd($price['pay_price_wx'],$v['pay_price'],2);
|
||||
}elseif($v['pay_type'] == 'yue'){
|
||||
$price['pay_price_yue'] = bcadd($price['pay_price_yue'],$v['pay_price'],2);
|
||||
}elseif($v['pay_type'] == 'offline'){
|
||||
$price['pay_price_offline'] = bcadd($price['pay_price_offline'],$v['pay_price'],2);
|
||||
}else{
|
||||
$price['pay_price_other'] = bcadd($price['pay_price_other'],$v['pay_price'],2);
|
||||
}
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
public static function systemPagePink($where){
|
||||
$model = new self;
|
||||
$model = self::getOrderWherePink($where,$model);
|
||||
$model = $model->order('id desc');
|
||||
|
||||
if($where['export'] == 1){
|
||||
$list = $model->select()->toArray();
|
||||
$export = [];
|
||||
foreach ($list as $index=>$item){
|
||||
|
||||
if ($item['pay_type'] == 'weixin'){
|
||||
$payType = '微信支付';
|
||||
}elseif($item['pay_type'] == 'yue'){
|
||||
$payType = '余额支付';
|
||||
}elseif($item['pay_type'] == 'offline'){
|
||||
$payType = '线下支付';
|
||||
}else{
|
||||
$payType = '其他支付';
|
||||
}
|
||||
|
||||
$_info = db('store_order_cart_info')->where('oid',$item['id'])->column('cart_info');
|
||||
$goodsName = [];
|
||||
foreach ($_info as $k=>$v){
|
||||
$v = json_decode($v,true);
|
||||
$goodsName[] = implode(
|
||||
[$v['productInfo']['store_name'],
|
||||
isset($v['productInfo']['attrInfo']) ? '('.$v['productInfo']['attrInfo']['suk'].')' : '',
|
||||
"[{$v['cart_num']} * {$v['truePrice']}]"
|
||||
],' ');
|
||||
}
|
||||
$item['cartInfo'] = $_info;
|
||||
$export[] = [
|
||||
$item['order_id'],$payType,
|
||||
$item['total_num'],$item['total_price'],$item['total_postage'],$item['pay_price'],$item['refund_price'],
|
||||
$item['mark'],$item['remark'],
|
||||
[$item['real_name'],$item['user_phone'],$item['user_address']],
|
||||
$goodsName,
|
||||
[$item['paid'] == 1? '已支付':'未支付','支付时间: '.($item['pay_time'] > 0 ? date('Y/md H:i',$item['pay_time']) : '暂无')]
|
||||
|
||||
];
|
||||
$list[$index] = $item;
|
||||
}
|
||||
ExportService::exportCsv($export,'订单导出'.time(),['订单号','支付方式','商品总数','商品总价','邮费','支付金额','退款金额','用户备注','管理员备注','收货人信息','商品信息','支付状态']);
|
||||
}
|
||||
|
||||
return self::page($model,function ($item){
|
||||
$item['nickname'] = WechatUser::where('uid',$item['uid'])->value('nickname');
|
||||
$_info = db('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select();
|
||||
foreach ($_info as $k=>$v){
|
||||
$_info[$k]['cart_info'] = json_decode($v['cart_info'],true);
|
||||
}
|
||||
$item['_info'] = $_info;
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
* @param $where
|
||||
* @param $model
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getOrderWherePink($where,$model){
|
||||
$model = $model->where('combination_id','GT',0);
|
||||
if($where['status'] != '') $model = $model::statusByWhere($where['status']);
|
||||
// if($where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where('is_del',$where['is_del']);
|
||||
if($where['real_name'] != ''){
|
||||
$model = $model->where('order_id|real_name|user_phone','LIKE',"%$where[real_name]%");
|
||||
}
|
||||
if($where['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$where['data']);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理订单金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPricePink($where){
|
||||
$model = new self;
|
||||
$price = array();
|
||||
$price['pay_price'] = 0;//支付金额
|
||||
$price['refund_price'] = 0;//退款金额
|
||||
$price['pay_price_wx'] = 0;//微信支付金额
|
||||
$price['pay_price_yue'] = 0;//余额支付金额
|
||||
$price['pay_price_offline'] = 0;//线下支付金额
|
||||
$price['pay_price_other'] = 0;//其他支付金额
|
||||
$price['use_integral'] = 0;//用户使用积分
|
||||
$price['back_integral'] = 0;//退积分总数
|
||||
$price['deduction_price'] = 0;//抵扣金额
|
||||
$price['total_num'] = 0; //商品总数
|
||||
$model = self::getOrderWherePink($where,$model);
|
||||
$list = $model->select()->toArray();
|
||||
foreach ($list as $v){
|
||||
$price['total_num'] = bcadd($price['total_num'],$v['total_num'],0);
|
||||
$price['pay_price'] = bcadd($price['pay_price'],$v['pay_price'],2);
|
||||
$price['refund_price'] = bcadd($price['refund_price'],$v['refund_price'],2);
|
||||
$price['use_integral'] = bcadd($price['use_integral'],$v['use_integral'],2);
|
||||
$price['back_integral'] = bcadd($price['back_integral'],$v['back_integral'],2);
|
||||
$price['deduction_price'] = bcadd($price['deduction_price'],$v['deduction_price'],2);
|
||||
if ($v['pay_type'] == 'weixin'){
|
||||
$price['pay_price_wx'] = bcadd($price['pay_price_wx'],$v['pay_price'],2);
|
||||
}elseif($v['pay_type'] == 'yue'){
|
||||
$price['pay_price_yue'] = bcadd($price['pay_price_yue'],$v['pay_price'],2);
|
||||
}elseif($v['pay_type'] == 'offline'){
|
||||
$price['pay_price_offline'] = bcadd($price['pay_price_offline'],$v['pay_price'],2);
|
||||
}else{
|
||||
$price['pay_price_other'] = bcadd($price['pay_price_other'],$v['pay_price'],2);
|
||||
}
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨天的订单 首页在使用
|
||||
* @param int $preDay
|
||||
* @param int $day
|
||||
* @return $this|StoreOrder
|
||||
*/
|
||||
public static function isMainYesterdayCount($preDay = 0,$day = 0){
|
||||
$model = new self();
|
||||
$model = $model->where('add_time','gt',$preDay);
|
||||
$model = $model->where('add_time','lt',$day);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户购买次数
|
||||
* @param int $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getUserCountPay($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
return self::where('uid',$uid)->where('paid',1)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个用户购买列表
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOneorderList($where){
|
||||
return self::where(['uid'=>$where['uid']])
|
||||
->order('add_time desc')
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->field(['order_id','real_name','total_num','total_price','pay_price',
|
||||
'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time','paid','pay_type',
|
||||
'pink_id','seckill_id','bargain_id'
|
||||
])->select()
|
||||
->toArray();
|
||||
}
|
||||
/*
|
||||
* 设置订单统计图搜索
|
||||
* $where array 条件
|
||||
* return object
|
||||
*/
|
||||
public static function setEchatWhere($where,$status=null,$time=null){
|
||||
$model=self::statusByWhere($where['status']);
|
||||
if($status!==null) $where['type']=$status;
|
||||
if($time===true) $where['data']='';
|
||||
switch ($where['type']){
|
||||
case 1:
|
||||
//普通商品
|
||||
$model=$model->where('combination_id',0)->where('seckill_id',0);
|
||||
break;
|
||||
case 2:
|
||||
//拼团商品
|
||||
$model=$model->where('combination_id',">",0)->where('pink_id',">",0);
|
||||
break;
|
||||
case 3:
|
||||
//秒杀商品
|
||||
$model=$model->where('seckill_id',">",0);
|
||||
break;
|
||||
case 4:
|
||||
//砍价商品
|
||||
$model=$model->where('bargain_id','>',0);
|
||||
break;
|
||||
}
|
||||
return self::getModelTime($where,$model);
|
||||
}
|
||||
/*
|
||||
* 获取订单数据统计图
|
||||
* $where array
|
||||
* $limit int
|
||||
* return array
|
||||
*/
|
||||
public static function getEchartsOrder($where,$limit=20){
|
||||
$orderlist=self::setEchatWhere($where)->field([
|
||||
'FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time',
|
||||
'sum(total_num) total_num',
|
||||
'count(*) count',
|
||||
'sum(total_price) total_price',
|
||||
'sum(refund_price) refund_price',
|
||||
'group_concat(cart_id SEPARATOR "|") cart_ids'
|
||||
])->group('_add_time')->order('_add_time asc')->select();
|
||||
count($orderlist) && $orderlist=$orderlist->toArray();
|
||||
$legend=['商品数量','订单数量','订单金额','退款金额'];
|
||||
$seriesdata=[
|
||||
[
|
||||
'name'=>$legend[0],
|
||||
'type'=>'line',
|
||||
'data'=>[],
|
||||
],
|
||||
[
|
||||
'name'=>$legend[1],
|
||||
'type'=>'line',
|
||||
'data'=>[]
|
||||
],
|
||||
[
|
||||
'name'=>$legend[2],
|
||||
'type'=>'line',
|
||||
'data'=>[]
|
||||
],
|
||||
[
|
||||
'name'=>$legend[3],
|
||||
'type'=>'line',
|
||||
'data'=>[]
|
||||
]
|
||||
];
|
||||
$xdata=[];
|
||||
$zoom='';
|
||||
foreach ($orderlist as $item){
|
||||
$xdata[]=$item['_add_time'];
|
||||
$seriesdata[0]['data'][]=$item['total_num'];
|
||||
$seriesdata[1]['data'][]=$item['count'];
|
||||
$seriesdata[2]['data'][]=$item['total_price'];
|
||||
$seriesdata[3]['data'][]=$item['refund_price'];
|
||||
}
|
||||
count($xdata) > $limit && $zoom=$xdata[$limit-5];
|
||||
$badge=self::getOrderBadge($where);
|
||||
$bingpaytype=self::setEchatWhere($where)->group('pay_type')->field(['count(*) as count','pay_type'])->select();
|
||||
count($bingpaytype) && $bingpaytype=$bingpaytype->toArray();
|
||||
$bing_xdata=['微信支付','余额支付','其他支付'];
|
||||
$color=['#ffcccc','#99cc00','#fd99cc','#669966'];
|
||||
$bing_data=[];
|
||||
foreach ($bingpaytype as $key=>$item){
|
||||
if($item['pay_type']=='weixin'){
|
||||
$value['name']=$bing_xdata[0];
|
||||
}else if($item['pay_type']=='yue'){
|
||||
$value['name']=$bing_xdata[1];
|
||||
}else{
|
||||
$value['name']=$bing_xdata[2];
|
||||
}
|
||||
$value['value']=$item['count'];
|
||||
$value['itemStyle']['color']=isset($color[$key]) ? $color[$key]:$color[0];
|
||||
$bing_data[]=$value;
|
||||
}
|
||||
return compact('zoom','xdata','seriesdata','badge','legend','bing_data','bing_xdata');
|
||||
}
|
||||
|
||||
public static function getOrderBadge($where){
|
||||
return [
|
||||
[
|
||||
'name'=>'拼团订单数量',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where,2)->count(),
|
||||
'content'=>'拼团总订单数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,2,true)->count(),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'砍价订单数量',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where,4)->count(),
|
||||
'content'=>'砍价总订单数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,4,true)->count(),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'秒杀订单数量',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where,3)->count(),
|
||||
'content'=>'秒杀总订单数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,3,true)->count(),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'普通订单数量',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where,1)->count(),
|
||||
'content'=>'普通总订单数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,1,true)->count(),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2,
|
||||
],
|
||||
[
|
||||
'name'=>'使用优惠卷金额',
|
||||
'field'=>'元',
|
||||
'count'=>self::setEchatWhere($where)->sum('coupon_price'),
|
||||
'content'=>'普通总订单数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('coupon_price'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'积分消耗数',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where)->sum('use_integral'),
|
||||
'content'=>'积分消耗总数',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('use_integral'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'积分抵扣金额',
|
||||
'field'=>'个',
|
||||
'count'=>self::setEchatWhere($where)->sum('deduction_price'),
|
||||
'content'=>'积分抵扣总金额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('deduction_price'),
|
||||
'class'=>'fa fa-money',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'在线支付金额',
|
||||
'field'=>'元',
|
||||
'count'=>self::setEchatWhere($where)->where('pay_type','weixin')->sum('pay_price'),
|
||||
'content'=>'在线支付总金额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','weixin')->sum('pay_price'),
|
||||
'class'=>'fa fa-weixin',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'余额支付金额',
|
||||
'field'=>'元',
|
||||
'count'=>self::setEchatWhere($where)->where('pay_type','yue')->sum('pay_price'),
|
||||
'content'=>'余额支付总金额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','yue')->sum('pay_price'),
|
||||
'class'=>'fa fa-balance-scale',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'赚取积分',
|
||||
'field'=>'分',
|
||||
'count'=>self::setEchatWhere($where)->sum('gain_integral'),
|
||||
'content'=>'赚取总积分',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('gain_integral'),
|
||||
'class'=>'fa fa-gg-circle',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'交易额',
|
||||
'field'=>'元',
|
||||
'count'=>self::setEchatWhere($where)->sum('pay_price'),
|
||||
'content'=>'总交易额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('pay_price'),
|
||||
'class'=>'fa fa-jpy',
|
||||
'col'=>2
|
||||
],
|
||||
[
|
||||
'name'=>'订单商品数量',
|
||||
'field'=>'元',
|
||||
'count'=>self::setEchatWhere($where)->sum('total_num'),
|
||||
'content'=>'订单商品总数量',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::setEchatWhere($where,null,true)->sum('total_num'),
|
||||
'class'=>'fa fa-cube',
|
||||
'col'=>2
|
||||
]
|
||||
];
|
||||
}
|
||||
/*
|
||||
* 退款列表
|
||||
* $where array
|
||||
* return array
|
||||
*/
|
||||
// public static function getRefundList($where){
|
||||
// $refundlist=self::setEchatWhere($where)->field([
|
||||
// 'order_id','total_price','coupon_price','deduction_price',
|
||||
// 'use_integral','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time','FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time','combination_id',
|
||||
// 'seckill_id','bargain_id','cost','status','cart_id','pay_price','refund_status'
|
||||
// ])->page((int)$where['page'],(int)$where['limit'])->select();
|
||||
// count($refundlist) && $refundlist=$refundlist->toArray();
|
||||
// foreach($refundlist as &$item){
|
||||
// $item['product']=StoreProduct::where('id','in',function ($quers) use($item){
|
||||
// $quers->name('store_cart')->where('id','in',json_decode($item['cart_id'],true))->field('product_id');
|
||||
// })->field(['store_name','cost','price','image'])->select()->toArray();
|
||||
// if($item['refund_status']==1) {
|
||||
// $item['_refund'] = '申请退款中';
|
||||
// }elseif ($item['refund_status']==2){
|
||||
// $item['_refund'] = '退款成功';
|
||||
// }
|
||||
// }
|
||||
// return $refundlist;
|
||||
// }
|
||||
}
|
||||
56
application/admin/model/order/StoreOrderStatus.php
Normal file
56
application/admin/model/order/StoreOrderStatus.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\order;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 订单操作纪律model
|
||||
* Class StoreOrderStatus
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreOrderStatus extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $oid
|
||||
* @param $type
|
||||
* @param $message
|
||||
*/
|
||||
public static function setStatus($oid,$type,$message){
|
||||
$data['oid'] = (int)$oid;
|
||||
$data['change_type'] = $type;
|
||||
$data['change_message'] = $message;
|
||||
$data['change_time'] = time();
|
||||
self::set($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($oid){
|
||||
$model = new self;
|
||||
$model = $model->where('oid',$oid);
|
||||
$model = $model->order('change_time asc');
|
||||
return self::page($model);
|
||||
}
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPageMer($oid){
|
||||
$model = new self;
|
||||
$model = $model->where('oid',$oid);
|
||||
// $model = $model->where('change_type','LIKE','mer_%');
|
||||
$model = $model->order('change_time asc');
|
||||
return self::page($model);
|
||||
}
|
||||
}
|
||||
206
application/admin/model/record/StoreStatistics.php
Normal file
206
application/admin/model/record/StoreStatistics.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/16 0016
|
||||
* Time: 11:07
|
||||
*/
|
||||
|
||||
namespace app\admin\model\record;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\ExportService;
|
||||
use app\wap\model\user\UserBill;
|
||||
use app\admin\model\user\User;
|
||||
use service\PHPExcelService;
|
||||
class StoreStatistics extends ModelBasic
|
||||
{
|
||||
protected $name = 'store_order';
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 处理金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPrice($where)
|
||||
{
|
||||
$model = new self;
|
||||
$price = array();
|
||||
$price['pay_price_wx'] = 0;//微信支付金额
|
||||
$price['pay_price_yue'] = 0;//余额支付金额
|
||||
$price['pay_price_offline'] = 0;//线下支付金额
|
||||
$list = self::getTimeWhere($where, $model)->field('pay_price,total_price,deduction_price,coupon_price,total_postage,pay_type,pay_time')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
$price['pay_price_wx'] = 0;
|
||||
$price['pay_price_yue'] = 0;
|
||||
$price['pay_price_offline'] = 0;
|
||||
}
|
||||
foreach ($list as $v) {
|
||||
if ($v['pay_type'] == 'weixin') {
|
||||
$price['pay_price_wx'] = bcadd($price['pay_price_wx'], $v['pay_price'], 2);
|
||||
} elseif ($v['pay_type'] == 'yue') {
|
||||
$price['pay_price_yue'] = bcadd($price['pay_price_yue'], $v['pay_price'], 2);
|
||||
} elseif ($v['pay_type'] == 'offline') {
|
||||
$price['pay_price_offline'] = bcadd($price['pay_price_offline'], $v['pay_price'], 2);
|
||||
}
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取营业数据
|
||||
*/
|
||||
public static function getOrderInfo($where)
|
||||
{
|
||||
$orderinfo = self::getTimeWhere($where)
|
||||
->field('sum(total_price) total_price,sum(cost) cost,sum(pay_postage) pay_postage,sum(pay_price) pay_price,sum(coupon_price) coupon_price,sum(deduction_price) deduction_price,from_unixtime(pay_time,\'%Y-%m-%d\') pay_time')->order('pay_time')->group('from_unixtime(pay_time,\'%Y-%m-%d\')')->select()->toArray();
|
||||
$price = 0;
|
||||
$postage = 0;
|
||||
$deduction = 0;
|
||||
$coupon = 0;
|
||||
$cost = 0;
|
||||
foreach ($orderinfo as $info) {
|
||||
$price = bcadd($price, $info['total_price'], 2);//应支付
|
||||
$postage = bcadd($postage, $info['pay_postage'], 2);//邮费
|
||||
$deduction = bcadd($deduction, $info['deduction_price'], 2);//抵扣
|
||||
$coupon = bcadd($coupon, $info['coupon_price'], 2);//优惠券
|
||||
$cost = bcadd($cost, $info['cost'], 2);//成本
|
||||
}
|
||||
return compact('orderinfo', 'price', 'postage', 'deduction', 'coupon', 'cost');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
*/
|
||||
public static function statusByWhere($status, $model = null)
|
||||
{
|
||||
if ($model == null) $model = new self;
|
||||
if ('' === $status)
|
||||
return $model;
|
||||
else if ($status == 'weixin')//微信支付
|
||||
return $model->where('pay_type', 'weixin');
|
||||
else if ($status == 'yue')//余额支付
|
||||
return $model->where('pay_type', 'yue');
|
||||
else if ($status == 'offline')//线下支付
|
||||
return $model->where('pay_type', 'offline');
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getTimeWhere($where, $model = null)
|
||||
{
|
||||
return self::getTime($where)->where('paid', 1)->where('refund_status', 0);
|
||||
}
|
||||
/**
|
||||
* 获取时间区间
|
||||
*/
|
||||
public static function getTime($where,$model=null,$prefix='add_time'){
|
||||
if ($model == null) $model = new self;
|
||||
if ($where['data'] == '') {
|
||||
switch ($where['date']){
|
||||
case 'today':case 'week':case 'month':case 'year':
|
||||
$model=$model->whereTime($prefix,$where['date']);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
list($startTime, $endTime) = explode(' - ', $where['data']);
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取新增消费
|
||||
*/
|
||||
public static function getConsumption($where)
|
||||
{
|
||||
$consumption=self::getTime($where,new UserBill,'b.add_time')->alias('a')->join('user b','a.uid = b.uid')
|
||||
->field('sum(a.number) number')
|
||||
->where('a.type','pay_product')->find()->toArray();
|
||||
return $consumption;
|
||||
}
|
||||
/**
|
||||
* 获取拼团商品
|
||||
*/
|
||||
public static function getPink($where)
|
||||
{
|
||||
$pink = self::getTimeWhere($where)->where('pink_id', 'neq', 0)->sum('pay_price');
|
||||
return $pink;
|
||||
}
|
||||
/**
|
||||
* 获取秒杀商品
|
||||
*/
|
||||
public static function getSeckill($where){
|
||||
$seckill=self::getTimeWhere($where)->where('seckill_id', 'neq', 0)->sum('pay_price');
|
||||
return $seckill;
|
||||
}
|
||||
/**
|
||||
* 获取普通商品数
|
||||
*/
|
||||
public static function getOrdinary($where)
|
||||
{
|
||||
$ordinary = self::getTimeWhere($where)->where('pink_id', 'eq', 0)->where('seckill_id','eq','0')->sum('pay_price');
|
||||
return $ordinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户充值
|
||||
*/
|
||||
public static function getRecharge($where)
|
||||
{
|
||||
$Recharge = self::getTime($where,new UserBill)->where('type', 'system_add')->where('category','now_money')->sum('number');
|
||||
return $Recharge;
|
||||
}
|
||||
/**
|
||||
* 获取推广金
|
||||
*/
|
||||
public static function getExtension($where)
|
||||
{
|
||||
$extension = self::getTime($where,new UserBill)->where('type', 'brokerage')->where('category','now_money')->sum('number');
|
||||
return $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近交易
|
||||
*/
|
||||
public static function trans()
|
||||
{
|
||||
$trans = self::alias('a')
|
||||
->join('user b', 'a.uid=b.uid')
|
||||
->join('store_order_cart_info c', 'a.id=c.oid')
|
||||
->join('store_product d', 'c.product_id=d.id')
|
||||
->field('b.nickname,a.pay_price,d.store_name')
|
||||
->order('a.add_time DESC')
|
||||
->limit('6')
|
||||
->select()->toArray();
|
||||
return $trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出表格
|
||||
*/
|
||||
public static function systemTable($where){
|
||||
$orderinfos=self::getOrderInfo($where);
|
||||
if($where['export'] == 1){
|
||||
$export = [];
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
foreach($orderinfo as $info){
|
||||
$time=$info['pay_time'];
|
||||
$price = $info['total_price']+$info['pay_postage'];
|
||||
$zhichu = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$profit = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
$deduction=$info['deduction_price'];//积分抵扣
|
||||
$coupon=$info['coupon_price'];//优惠
|
||||
$cost=$info['cost'];//成本
|
||||
$export[] = [$time,$price,$zhichu,$cost,$coupon,$deduction,$profit];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)'])->setExcelTile('财务统计', '财务统计',date('Y-m-d H:i:s',time()))->setExcelContent($export)->ExcelSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
57
application/admin/model/record/StoreVisit.php
Normal file
57
application/admin/model/record/StoreVisit.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use app\admin\model\user\User;
|
||||
/**
|
||||
*
|
||||
* Class StoreOrder
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreVisit extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getVisit($date,$class=[]){
|
||||
$model=new self();
|
||||
switch ($date){
|
||||
case null:case 'today':case 'week':case 'year':
|
||||
if($date==null) $date='month';
|
||||
$model=$model->whereTime('add_time',$date);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where('add_time','>',$startTime);
|
||||
$model = $model->where('add_time','<',$endTime);
|
||||
break;
|
||||
default:
|
||||
list($startTime,$endTime)=explode('-',$date);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
$list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
|
||||
$view=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
|
||||
$now_list['value']=$val['sum'];
|
||||
$now_list['class']=isset($class[$key])?$class[$key]:'';
|
||||
$view[]=$now_list;
|
||||
}
|
||||
if(empty($list)){
|
||||
$view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
32
application/admin/model/routine/RoutineTemplate.php
Normal file
32
application/admin/model/routine/RoutineTemplate.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
namespace app\admin\model\routine;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 小程序模板消息Model
|
||||
* Class RoutineTemplate
|
||||
* @package app\admin\model\wechat
|
||||
*/
|
||||
class RoutineTemplate extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 获取系统分页数据 分类
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where = array()){
|
||||
$model = new self;
|
||||
if($where['name'] !== '') $model = $model->where('name','LIKE',"%$where[name]%");
|
||||
if($where['status'] !== '') $model = $model->where('status',$where['status']);
|
||||
return self::page($model);
|
||||
}
|
||||
}
|
||||
81
application/admin/model/store/StoreBargain.php
Normal file
81
application/admin/model/store/StoreBargain.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/16 0016
|
||||
* Time: 11:07
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\PHPExcelService;
|
||||
|
||||
/**
|
||||
* 砍价Model
|
||||
* Class StoreBargain
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreBargain extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
if($where['store_name'] != ''){
|
||||
$model = $model->where('title','LIKE',"%$where[store_name]%");
|
||||
$model = $model->whereOr('store_name','LIKE',"%$where[store_name]%");
|
||||
}
|
||||
if($where['data'] != '') $model = $model->whereTime('add_time', 'between', explode('-',$where['data']));
|
||||
$model = $model->order('id desc');
|
||||
$model = $model->where('is_del',0);
|
||||
if($where['export'] == 1){
|
||||
$list = $model->select()->toArray();
|
||||
$export = [];
|
||||
foreach ($list as $index=>$item){
|
||||
$export[] = [
|
||||
$item['title'],
|
||||
$item['info'],
|
||||
$item['store_name'],
|
||||
'¥'.$item['price'],
|
||||
'¥'.$item['cost'],
|
||||
$item['num'],
|
||||
'¥'.$item['bargain_max_price'],
|
||||
'¥'.$item['bargain_min_price'],
|
||||
$item['bargain_num'],
|
||||
$item['status'] ? '开启' : '关闭',
|
||||
date('Y-m-d H:i:s',$item['start_time']),
|
||||
date('Y-m-d H:i:s',$item['stop_time']),
|
||||
$item['sales'],
|
||||
$item['stock'],
|
||||
$item['give_integral'],
|
||||
date('Y-m-d H:i:s',$item['add_time']),
|
||||
];
|
||||
$list[$index] = $item;
|
||||
}
|
||||
|
||||
PHPExcelService::setExcelHeader(['砍价活动名称','砍价活动简介','砍价产品名称','砍价金额','成本价','每次购买的砍价产品数量','用户每次砍价的最大金额','用户每次砍价的最小金额',
|
||||
'用户每次砍价的次数','砍价状态','砍价开启时间','砍价结束时间','销量','库存','返多少积分','添加时间'])
|
||||
->setExcelTile('砍价产品导出','产品信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
return self::page($model,function($item){
|
||||
if($item['status']){
|
||||
if($item['start_time'] > time())
|
||||
$item['start_name'] = '活动未开始';
|
||||
else if($item['stop_time'] < time())
|
||||
$item['start_name'] = '活动已结束';
|
||||
else if($item['stop_time'] > time() && $item['start_time'] < time())
|
||||
$item['start_name'] = '正在进行中';
|
||||
}
|
||||
|
||||
},$where);
|
||||
}
|
||||
}
|
||||
70
application/admin/model/store/StoreCategory.php
Normal file
70
application/admin/model/store/StoreCategory.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\UtilService;
|
||||
|
||||
/**
|
||||
* Class StoreCategory
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreCategory extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['pid'] != '') $model = $model->where('pid',$where['pid']);
|
||||
else if($where['pid']=='' && $where['cate_name']=='') $model = $model->where('pid',0);
|
||||
if($where['is_show'] != '') $model = $model->where('is_show',$where['is_show']);
|
||||
if($where['cate_name'] != '') $model = $model->where('cate_name','LIKE',"%$where[cate_name]%");
|
||||
return self::page($model,function ($item){
|
||||
if($item['pid']){
|
||||
$item['pid_name'] = self::where('id',$item['pid'])->value('cate_name');
|
||||
}else{
|
||||
$item['pid_name'] = '顶级';
|
||||
}
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顶级分类
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategory($field = 'id,cate_name')
|
||||
{
|
||||
return self::where('is_show',1)->column($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分级排序列表
|
||||
* @param null $model
|
||||
* @return array
|
||||
*/
|
||||
public static function getTierList($model = null)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
return UtilService::sortListTier($model->select()->toArray());
|
||||
}
|
||||
|
||||
public static function delCategory($id){
|
||||
$count = self::where('pid',$id)->count();
|
||||
if($count)
|
||||
return false;
|
||||
else{
|
||||
return self::del($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
103
application/admin/model/store/StoreCouponUser.php
Normal file
103
application/admin/model/store/StoreCouponUser.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function tidyCouponList($couponList)
|
||||
{
|
||||
$time = time();
|
||||
foreach ($couponList as &$coupon){
|
||||
$coupon['_add_time'] = date('Y/m/d',$coupon['add_time']);
|
||||
$coupon['_end_time'] = date('Y/m/d',$coupon['end_time']);
|
||||
$coupon['use_min_price'] = floatval($coupon['use_min_price']);
|
||||
$coupon['coupon_price'] = floatval($coupon['coupon_price']);
|
||||
if($coupon['is_fail']){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已失效';
|
||||
}else if ($coupon['status'] == 1){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已使用';
|
||||
}else if ($coupon['status'] == 2){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else if($coupon['add_time'] > $time || $coupon['end_time'] < $time){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else{
|
||||
if($coupon['add_time']+ 3600*24 > $time){
|
||||
$coupon['_type'] = 2;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}else{
|
||||
$coupon['_type'] = 1;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}
|
||||
}
|
||||
$coupon['integral']=db('store_coupon')->where(['id'=>$coupon['cid']])->value('integral');
|
||||
}
|
||||
return $couponList;
|
||||
}
|
||||
//获取个人优惠券列表
|
||||
public static function getOneCouponsList($where){
|
||||
$list=self::where(['uid'=>$where['uid']])->page((int)$where['page'],(int)$where['limit'])->select();
|
||||
return self::tidyCouponList($list);
|
||||
}
|
||||
//获取优惠劵头部信息
|
||||
public static function getCouponBadgeList($where){
|
||||
return [
|
||||
[
|
||||
'name'=>'总发放优惠券',
|
||||
'field'=>'张',
|
||||
'count'=>self::getModelTime($where,db('store_coupon_issue'))->where('status',1)->sum('total_count'),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>6,
|
||||
],
|
||||
[
|
||||
'name'=>'总使用优惠券',
|
||||
'field'=>'张',
|
||||
'count'=>self::getModelTime($where,new self())->where('status',1)->count(),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>6,
|
||||
]
|
||||
];
|
||||
}
|
||||
//获取优惠劵图表
|
||||
public static function getConponCurve($where,$limit=20){
|
||||
//优惠劵发放记录
|
||||
$list=self::getModelTime($where,db('store_coupon_issue')
|
||||
->where('status',1)
|
||||
->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(total_count) as total_count'])->group('_add_time')->order('_add_time asc'))->select();
|
||||
$date=[];
|
||||
$seriesdata=[];
|
||||
$zoom='';
|
||||
foreach ($list as $item){
|
||||
$date[]=$item['_add_time'];
|
||||
$seriesdata[]=$item['total_count'];
|
||||
}
|
||||
unset($item);
|
||||
if(count($date)>$limit){
|
||||
$zoom=$date[$limit-5];
|
||||
}
|
||||
//优惠劵使用记录
|
||||
$componList=self::getModelTime($where,self::where('status',1)->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(coupon_price) as coupon_price'])
|
||||
->group('_add_time')->order('_add_time asc'))->select();
|
||||
count($componList) && $componList=$componList->toArray();
|
||||
$compon_date=[];
|
||||
$compon_data=[];
|
||||
$compon_zoom='';
|
||||
foreach($componList as $item){
|
||||
$compon_date[]=$item['_add_time'];
|
||||
$compon_data[]=$item['coupon_price'];
|
||||
}
|
||||
if(count($compon_date)>$limit){
|
||||
$compon_zoom=$compon_date[$limit-5];
|
||||
}
|
||||
return compact('date','seriesdata','zoom','compon_date','compon_data','compon_zoom');
|
||||
}
|
||||
|
||||
}
|
||||
524
application/admin/model/store/StoreProduct.php
Normal file
524
application/admin/model/store/StoreProduct.php
Normal file
@ -0,0 +1,524 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use app\admin\model\system\Merchant;
|
||||
use service\PHPExcelService;
|
||||
use think\Db;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
|
||||
/**
|
||||
* 产品管理 model
|
||||
* Class StoreProduct
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProduct extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where,$adminInfo){
|
||||
$model = new self;
|
||||
$model = $model->alias('p');
|
||||
if($where['store_name'] != '') $model = $model->where('p.store_name|p.keyword|p.id','LIKE',"%$where[store_name]%");
|
||||
if($where['cate_id'] != '') $model = $model->where('p.cate_id','LIKE',"%$where[cate_id]%");
|
||||
switch ($where['type']){
|
||||
case 1:
|
||||
$data = ['p.is_show'=>1,'is_del'=>0];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
case 2:
|
||||
$data = ['p.is_show'=>0,'is_del'=>0];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
case 3:
|
||||
$data = ['p.is_del'=>0];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
case 4:
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>0];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
case 5:
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>['elt',1]];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
case 6:
|
||||
$data = ['p.is_del'=>1];
|
||||
$model = $model->where($data);
|
||||
break;
|
||||
};
|
||||
$model = $model->field('p.*,sum("pav.stock") as vstock');
|
||||
$model = $model->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT');
|
||||
$model = $model->group('p.id');
|
||||
$order = '';
|
||||
if($where['sales'] != '') $order .= $where['sales'];
|
||||
$order .= 'p.id desc';
|
||||
$model = $model->order($order);
|
||||
if($where['export'] == 1){
|
||||
$list = $model->select()->toArray();
|
||||
$export = [];
|
||||
foreach ($list as $index=>$item){
|
||||
$cateName = CategoryModel::where('id','IN',$item['cate_id'])->column('cate_name','id'); if(is_array($cateName)){ $cateNameStr = implode(',',$cateName); }
|
||||
$export[] = [
|
||||
$item['store_name'],
|
||||
$item['store_info'],
|
||||
$cateName,
|
||||
'¥'.$item['price'],
|
||||
$item['stock'],
|
||||
$item['sales'],
|
||||
StoreProductRelation::where('product_id',$item['id'])->where('type','like')->count(),
|
||||
StoreProductRelation::where('product_id',$item['id'])->where('type','collect')->count()
|
||||
];
|
||||
$list[$index] = $item;
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['产品名称','产品简介','产品分类','价格','库存','销量','点赞人数','收藏人数'])
|
||||
->setExcelTile('产品导出','产品信息'.time(),'操作人昵称:'.$adminInfo['real_name'].' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
return self::page($model,function($item){
|
||||
$cateName = CategoryModel::where('id','IN',$item['cate_id'])->column('cate_name','id');
|
||||
if(is_array($cateName)){
|
||||
$item['cate_name'] = implode(',',$cateName); }
|
||||
$item['collect'] = StoreProductRelation::where('product_id',$item['id'])->where('type','collect')->count();//收藏
|
||||
$item['like'] = StoreProductRelation::where('product_id',$item['id'])->where('type','like')->count();//点赞
|
||||
$item['stock'] = self::getStock($item['id'])>0?self::getStock($item['id']):$item['stock'];//库存
|
||||
$item['stock_attr'] = self::getStock($item['id'])>0 ? true : false;//库存
|
||||
$item['sales_attr'] = self::getSales($item['id']);//属性销量
|
||||
$item['visitor'] = Db::name('store_visit')->where('product_id',$item['id'])->where('product_type','product')->count();
|
||||
|
||||
},$where);
|
||||
}
|
||||
public static function getChatrdata($type,$data){
|
||||
$legdata=['销量','数量','点赞','收藏'];
|
||||
$model=self::setWhereType(self::order('id desc'),$type);
|
||||
$list=self::getModelTime(compact('data'),$model)
|
||||
->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(id) as count,sum(sales) as sales')
|
||||
->group('un_time')
|
||||
->distinct(true)
|
||||
->select()
|
||||
->each(function($item) use($data){
|
||||
$item['collect']=self::getModelTime(compact('data'),new StoreProductRelation)->where(['type'=>'collect'])->count();
|
||||
$item['like']=self::getModelTime(compact('data'),new StoreProductRelation)->where(['type'=>'like'])->count();
|
||||
})->toArray();
|
||||
$chatrList=[];
|
||||
$datetime=[];
|
||||
$data_item=[];
|
||||
$itemList=[0=>[],1=>[],2=>[],3=>[]];
|
||||
foreach ($list as $item){
|
||||
$itemList[0][]=$item['sales'];
|
||||
$itemList[1][]=$item['count'];
|
||||
$itemList[2][]=$item['like'];
|
||||
$itemList[3][]=$item['collect'];
|
||||
array_push($datetime,$item['un_time']);
|
||||
}
|
||||
foreach ($legdata as $key=>$leg){
|
||||
$data_item['name']=$leg;
|
||||
$data_item['type']='line';
|
||||
$data_item['data']=$itemList[$key];
|
||||
$chatrList[]=$data_item;
|
||||
unset($data_item);
|
||||
}
|
||||
unset($leg);
|
||||
$badge=self::getbadge(compact('data'),$type);
|
||||
$count=self::setWhereType(self::getModelTime(compact('data'),new self()),$type)->count();
|
||||
return compact('datetime','chatrList','legdata','badge','count');
|
||||
|
||||
}
|
||||
//获取 badge 内容
|
||||
public static function getbadge($where,$type){
|
||||
$StoreOrderModel=new StoreOrder;
|
||||
$replenishment_num = SystemConfig::getValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$stock1=self::getModelTime($where,new self())->where('stock','<',$replenishment_num)->column('stock');
|
||||
$sum_stock=self::where('stock','<',$replenishment_num)->column('stock');
|
||||
$stk=[];
|
||||
foreach ($stock1 as $item){
|
||||
$stk[]=$replenishment_num-$item;
|
||||
}
|
||||
$lack=array_sum($stk);
|
||||
$sum=[];
|
||||
foreach ($sum_stock as $val){
|
||||
$sum[]=$replenishment_num-$val;
|
||||
}
|
||||
return [
|
||||
[
|
||||
'name'=>'商品数量',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(new self(),$type)->where('add_time','<',mktime(0,0,0,date('m'),date('d'),date('Y')))->sum('stock'),
|
||||
'content'=>'商品数量总数',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>self::sum('stock'),
|
||||
'class'=>'fa fa fa-ioxhost',
|
||||
],
|
||||
[
|
||||
'name'=>'新增商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(self::getModelTime($where,new self),$type)->where('is_new',1)->sum('stock'),
|
||||
'content'=>'新增商品总数',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::where('is_new',1)->sum('stock'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'活动商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::getModelTime($where,$StoreOrderModel)->sum('total_num'),
|
||||
'content'=>'活动商品总数',
|
||||
'background_color'=>'layui-bg-green',
|
||||
'sum'=>$StoreOrderModel->sum('total_num'),
|
||||
'class'=>'fa fa-bar-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'缺货商品',
|
||||
'field'=>'件',
|
||||
'count'=>$lack,
|
||||
'content'=>'总商品数量',
|
||||
'background_color'=>'layui-bg-orange',
|
||||
'sum'=>array_sum($sum),
|
||||
'class'=>'fa fa-cube',
|
||||
],
|
||||
];
|
||||
}
|
||||
public static function setWhereType($model,$type){
|
||||
switch ($type){
|
||||
case 1:
|
||||
$data = ['is_show'=>1,'is_del'=>0];
|
||||
break;
|
||||
case 2:
|
||||
$data = ['is_show'=>0,'is_del'=>0];
|
||||
break;
|
||||
case 3:
|
||||
$data = ['is_del'=>0];
|
||||
break;
|
||||
case 4:
|
||||
$data = ['is_show'=>1,'is_del'=>0,'stock'=>0];
|
||||
break;
|
||||
case 5:
|
||||
$data = ['is_show'=>1,'is_del'=>0,'stock'=>['elt',1]];
|
||||
break;
|
||||
case 6:
|
||||
$data = ['is_del'=>1];
|
||||
break;
|
||||
}
|
||||
if(isset($data)) $model = $model->where($data);
|
||||
return $model;
|
||||
}
|
||||
/*
|
||||
* layui-bg-red 红 layui-bg-orange 黄 layui-bg-green 绿 layui-bg-blue 蓝 layui-bg-cyan 黑
|
||||
* 销量排行 top 10
|
||||
*/
|
||||
public static function getMaxList($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model=StoreOrder::alias('a')->join('StoreOrderCartInfo c','a.id=c.oid')->join('store_product b','b.id=c.product_id');
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('c.product_id')->order('p_count desc')->limit(10)
|
||||
->field(['count(c.product_id) as p_count','b.store_name','sum(b.price) as sum_price'])->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
unset($item);
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['p_count'],$sum_count,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name']);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
//获取利润
|
||||
public static function ProfityTop10($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model=StoreOrder::alias('a')->join('StoreOrderCartInfo c','a.id=c.oid')->join('store_product b','b.id=c.product_id');
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('c.product_id')->order('profity desc')->limit(10)
|
||||
->field(['count(c.product_id) as p_count','b.store_name','sum(b.price) as sum_price','(b.price-b.cost) as profity'])
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['sum_price'],$sum_price,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name'],30);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
//获取缺货
|
||||
public static function getLackList($where){
|
||||
$replenishment_num = SystemConfig::getValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$list=self::where('stock','<',$replenishment_num)->field(['id','store_name','stock','price'])->page((int)$where['page'],(int)$where['limit'])->order('stock asc')->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$count=self::where('stock','<',$replenishment_num)->count();
|
||||
return ['count'=>$count,'data'=>$list];
|
||||
}
|
||||
//获取差评
|
||||
public static function getnegativelist($where){
|
||||
$list=self::alias('s')->join('StoreProductReply r','s.id=r.product_id')
|
||||
->field('s.id,s.store_name,s.price,count(r.product_id) as count')
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->where('r.product_score',1)
|
||||
->order('count desc')
|
||||
->group('r.product_id')
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$count=self::alias('s')->join('StoreProductReply r','s.id=r.product_id')->group('r.product_id')->where('r.product_score',1)->count();
|
||||
return ['count'=>$count,'data'=>$list];
|
||||
}
|
||||
public static function TuiProductList(){
|
||||
$perd=StoreOrder::alias('s')->join('StoreOrderCartInfo c','s.id=c.oid')
|
||||
->field('count(c.product_id) as count,c.product_id as id')
|
||||
->group('c.product_id')
|
||||
->where('s.status',-1)
|
||||
->order('count desc')
|
||||
->limit(10)
|
||||
->select();
|
||||
if(count($perd)) $perd=$perd->toArray();
|
||||
foreach ($perd as &$item){
|
||||
$item['store_name']=self::where(['id'=>$item['id']])->value('store_name');
|
||||
$item['price']=self::where(['id'=>$item['id']])->value('price');
|
||||
}
|
||||
return $perd;
|
||||
}
|
||||
//编辑库存
|
||||
public static function changeStock($stock,$productId)
|
||||
{
|
||||
return self::edit(compact('stock'),$productId);
|
||||
}
|
||||
//获取库存数量
|
||||
public static function getStock($productId)
|
||||
{
|
||||
return StoreProductAttrValue::where(['product_id'=>$productId])->sum('stock');
|
||||
}
|
||||
//获取总销量
|
||||
public static function getSales($productId)
|
||||
{
|
||||
return StoreProductAttrValue::where(['product_id'=>$productId])->sum('sales');
|
||||
}
|
||||
|
||||
public static function getTierList($model = null)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
return $model->field('id,store_name')->where('is_del',0)->select()->toArray();
|
||||
}
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function setWhere($where){
|
||||
$time['data']='';
|
||||
if(isset($where['start_time']) && $where['start_time']!='' && isset($where['end_time']) && $where['end_time']!=''){
|
||||
$time['data']=$where['start_time'].' - '.$where['end_time'];
|
||||
}else{
|
||||
$time['data']=isset($where['data'])? $where['data']:'';
|
||||
}
|
||||
$model=self::getModelTime($time,db('store_cart')->alias('a')->join('store_product b','a.product_id=b.id'),'a.add_time');
|
||||
if(isset($where['title']) && $where['title']!=''){
|
||||
$model=$model->where('b.store_name|b.id','like',"%$where[title]%");
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取真实销量排行
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getSaleslists($where){
|
||||
$data=self::setWhere($where)->where('a.is_pay',1)
|
||||
->group('a.product_id')
|
||||
->field(['sum(a.cart_num) as num_product','b.store_name','b.image','b.price','b.id'])
|
||||
->order('num_product desc')
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->select();
|
||||
$count=self::setWhere($where)->where('a.is_pay',1)->group('a.product_id')->count();
|
||||
foreach ($data as &$item){
|
||||
$item['sum_price']=bcdiv($item['num_product'],$item['price'],true);
|
||||
}
|
||||
return compact('data','count');
|
||||
}
|
||||
public static function SaveProductExport($where){
|
||||
$list=self::setWhere($where)
|
||||
->where('a.is_pay',1)
|
||||
->field(['sum(a.cart_num) as num_product','b.store_name','b.image','b.price','b.id'])
|
||||
->order('num_product desc')
|
||||
->group('a.product_id')
|
||||
->select();
|
||||
$export=[];
|
||||
foreach ($list as $item){
|
||||
$export[]=[
|
||||
$item['id'],
|
||||
$item['store_name'],
|
||||
$item['price'],
|
||||
bcmul($item['num_product'],$item['price'],2),
|
||||
$item['num_product'],
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['商品编号','商品名称','商品售价','销售额','销量'])
|
||||
->setExcelTile('产品销量排行','产品销量排行',' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
/*
|
||||
* 单个商品详情的头部查询
|
||||
* $id 商品id
|
||||
* $where 条件
|
||||
*/
|
||||
public static function getProductBadgeList($id,$where){
|
||||
$data['data']=$where;
|
||||
$list=self::setWhere($data)
|
||||
->field(['sum(a.cart_num) as num_product','b.id','b.price'])
|
||||
->where('a.is_pay',1)
|
||||
->group('a.product_id')
|
||||
->order('num_product desc')
|
||||
->select();
|
||||
//排名
|
||||
$ranking=0;
|
||||
//销量
|
||||
$xiaoliang=0;
|
||||
//销售额 数组
|
||||
$list_price=[];
|
||||
foreach ($list as $key=>$item){
|
||||
if($item['id']==$id){
|
||||
$ranking=$key+1;
|
||||
$xiaoliang=$item['num_product'];
|
||||
}
|
||||
$value['sum_price']=$item['price']*$item['num_product'];
|
||||
$value['id']=$item['id'];
|
||||
$list_price[]=$value;
|
||||
}
|
||||
//排序
|
||||
$list_price=self::my_sort($list_price,'sum_price',SORT_DESC);
|
||||
//销售额排名
|
||||
$rank_price=0;
|
||||
//当前销售额
|
||||
$num_price=0;
|
||||
if($list_price!==false && is_array($list_price)){
|
||||
foreach ($list_price as $key=>$item){
|
||||
if($item['id']==$id){
|
||||
$num_price=$item['sum_price'];
|
||||
$rank_price=$key+1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
[
|
||||
'name'=>'销售额排名',
|
||||
'field'=>'名',
|
||||
'count'=>$rank_price,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'销量排名',
|
||||
'field'=>'名',
|
||||
'count'=>$ranking,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'商品销量',
|
||||
'field'=>'名',
|
||||
'count'=>$xiaoliang,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'点赞次数',
|
||||
'field'=>'个',
|
||||
'count'=>db('store_product_relation')->where('product_id',$id)->where('type','like')->count(),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'销售总额',
|
||||
'field'=>'元',
|
||||
'count'=>$num_price,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>12,
|
||||
],
|
||||
];
|
||||
}
|
||||
/*
|
||||
* 处理二维数组排序
|
||||
* $arrays 需要处理的数组
|
||||
* $sort_key 需要处理的key名
|
||||
* $sort_order 排序方式
|
||||
* $sort_type 类型 可不填写
|
||||
*/
|
||||
public static function my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){
|
||||
if(is_array($arrays)){
|
||||
foreach ($arrays as $array){
|
||||
if(is_array($array)){
|
||||
$key_arrays[] = $array[$sort_key];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($key_arrays)){
|
||||
array_multisort($key_arrays,$sort_order,$sort_type,$arrays);
|
||||
return $arrays;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* 查询单个商品的销量曲线图
|
||||
*
|
||||
*/
|
||||
public static function getProductCurve($where){
|
||||
$list=self::setWhere($where)
|
||||
->where('a.product_id',$where['id'])
|
||||
->where('a.is_pay',1)
|
||||
->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','sum(a.cart_num) as num'])
|
||||
->group('_add_time')
|
||||
->order('_add_time asc')
|
||||
->select();
|
||||
$seriesdata=[];
|
||||
$date=[];
|
||||
$zoom='';
|
||||
foreach ($list as $item){
|
||||
$date[]=$item['_add_time'];
|
||||
$seriesdata[]=$item['num'];
|
||||
}
|
||||
if(count($date)>$where['limit']) $zoom=$date[$where['limit']-5];
|
||||
return compact('seriesdata','date','zoom');
|
||||
}
|
||||
/*
|
||||
* 查询单个商品的销售列表
|
||||
*
|
||||
*/
|
||||
public static function getSalelList($where){
|
||||
return self::setWhere($where)
|
||||
->where(['a.product_id'=>$where['id'],'a.is_pay'=>1])
|
||||
->join('user c','c.uid=a.uid')
|
||||
->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','c.nickname','b.price','a.id','a.cart_num as num'])
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->select();
|
||||
}
|
||||
}
|
||||
117
application/admin/model/store/StoreProductAttr.php
Normal file
117
application/admin/model/store/StoreProductAttr.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProductAttr extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected function setAttrValuesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function getAttrValuesAttr($value)
|
||||
{
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
|
||||
public static function createProductAttr($attrList,$valueList,$productId)
|
||||
{
|
||||
$result = ['attr'=>$attrList,'value'=>$valueList];
|
||||
$attrValueList = [];
|
||||
$attrNameList = [];
|
||||
foreach ($attrList as $index=>$attr){
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!');
|
||||
$attr['value'] = trim($attr['value']);
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!!');
|
||||
if(!isset($attr['detail']) || !count($attr['detail'])) return self::setErrorInfo('请输入属性名称!');
|
||||
foreach ($attr['detail'] as $k=>$attrValue){
|
||||
$attrValue = trim($attrValue);
|
||||
if(empty($attrValue)) return self::setErrorInfo('请输入正确的属性');
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
$attrValueList[] = $attrValue;
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
}
|
||||
$attrNameList[] = $attr['value'];
|
||||
$attrList[$index] = $attr;
|
||||
}
|
||||
$attrCount = count($attrList);
|
||||
foreach ($valueList as $index=>$value){
|
||||
if(!isset($value['detail']) || count($value['detail']) != $attrCount) return self::setErrorInfo('请填写正确的商品信息');
|
||||
if(!isset($value['price']) || !is_numeric($value['price']) || floatval($value['price']) != $value['price'])
|
||||
return self::setErrorInfo('请填写正确的商品价格');
|
||||
if(!isset($value['sales']) || !is_numeric($value['sales']) || intval($value['sales']) != $value['sales'])
|
||||
return self::setErrorInfo('请填写正确的商品库存');
|
||||
if(!isset($value['cost']) || !is_numeric($value['cost']) || floatval($value['cost']) != $value['cost'])
|
||||
return self::setErrorInfo('请填写正确的商品成本价格');
|
||||
if(!isset($value['pic']) || empty($value['pic']))
|
||||
return self::setErrorInfo('请上传商品图片');
|
||||
foreach ($value['detail'] as $attrName=>$attrValue){
|
||||
$attrName = trim($attrName);
|
||||
$attrValue = trim($attrValue);
|
||||
if(!in_array($attrName,$attrNameList,true)) return self::setErrorInfo($attrName.'规则不存在');
|
||||
if(!in_array($attrValue,$attrValueList,true)) return self::setErrorInfo($attrName.'属性不存在');
|
||||
if(empty($attrName)) return self::setErrorInfo('请输入正确的属性');
|
||||
$value['detail'][$attrName] = $attrValue;
|
||||
}
|
||||
$valueList[$index] = $value;
|
||||
}
|
||||
$attrGroup = [];
|
||||
$valueGroup = [];
|
||||
foreach ($attrList as $k=>$value){
|
||||
$attrGroup[] = [
|
||||
'product_id'=>$productId,
|
||||
'attr_name'=>$value['value'],
|
||||
'attr_values'=>$value['detail']
|
||||
];
|
||||
}
|
||||
foreach ($valueList as $k=>$value){
|
||||
ksort($value['detail'],SORT_STRING);
|
||||
$suk = implode(',',$value['detail']);
|
||||
$valueGroup[$suk] = [
|
||||
'product_id'=>$productId,
|
||||
'suk'=>$suk,
|
||||
'price'=>$value['price'],
|
||||
'cost'=>$value['cost'],
|
||||
'stock'=>$value['sales'],
|
||||
'image'=>$value['pic']
|
||||
];
|
||||
}
|
||||
if(!count($attrGroup) || !count($valueGroup)) return self::setErrorInfo('请设置至少一个属性!');
|
||||
$attrModel = new self;
|
||||
$attrValueModel = new StoreProductAttrValue;
|
||||
self::beginTrans();
|
||||
if(!self::clearProductAttr($productId)) return false;
|
||||
$res = false !== $attrModel->saveAll($attrGroup)
|
||||
&& false !== $attrValueModel->saveAll($valueGroup)
|
||||
&& false !== StoreProductAttrResult::setResult($result,$productId);
|
||||
self::checkTrans($res);
|
||||
if($res)
|
||||
return true;
|
||||
else
|
||||
return self::setErrorInfo('编辑商品属性失败!');
|
||||
}
|
||||
|
||||
public static function clearProductAttr($productId)
|
||||
{
|
||||
if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
|
||||
$res = false !== self::where('product_id',$productId)->delete()
|
||||
&& false !== StoreProductAttrValue::clearProductAttrValue($productId);
|
||||
if(!$res)
|
||||
return self::setErrorInfo('编辑属性失败,清除旧属性失败!');
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
47
application/admin/model/store/StoreProductAttrResult.php
Normal file
47
application/admin/model/store/StoreProductAttrResult.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/09
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProductAttrResult extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['change_time'];
|
||||
|
||||
protected static function setChangeTimeAttr($value)
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
protected static function setResultAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
|
||||
public static function setResult($result,$product_id)
|
||||
{
|
||||
$result = self::setResultAttr($result);
|
||||
$change_time = self::setChangeTimeAttr(0);
|
||||
return self::insert(compact('product_id','result','change_time'),true);
|
||||
}
|
||||
|
||||
public static function getResult($productId)
|
||||
{
|
||||
return json_decode(self::where('product_id',$productId)->value('result'),true) ?: [];
|
||||
}
|
||||
|
||||
public static function clearResult($productId)
|
||||
{
|
||||
return self::del($productId);
|
||||
}
|
||||
|
||||
}
|
||||
49
application/admin/model/store/StoreProductAttrValue.php
Normal file
49
application/admin/model/store/StoreProductAttrValue.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreProductAttrValue extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['unique'];
|
||||
|
||||
protected function setSukAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function setUniqueAttr($value,$data)
|
||||
{
|
||||
if(is_array($data['suk'])) $data['suk'] = $this->setSukAttr($data['suk']);
|
||||
return self::uniqueId($data['product_id'].$data['suk'].uniqid(true));
|
||||
}
|
||||
|
||||
public static function decProductAttrStock($productId,$unique,$num)
|
||||
{
|
||||
return false !== self::where('product_id',$productId)->where('unique',$unique)
|
||||
->dec('stock',$num)->inc('sales',$num)->update();
|
||||
}
|
||||
|
||||
|
||||
public static function uniqueId($key)
|
||||
{
|
||||
return substr(md5($key),12,8);
|
||||
}
|
||||
|
||||
public static function clearProductAttrValue($productId)
|
||||
{
|
||||
return self::where('product_id',$productId)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
38
application/admin/model/store/StoreProductRelation.php
Normal file
38
application/admin/model/store/StoreProductRelation.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 点赞and收藏 model
|
||||
* Class StoreProductRelation
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProductRelation extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
|
||||
public static function getCollect($pid){
|
||||
$model = new self();
|
||||
$model = $model->where('r.product_id',$pid)->where('r.type','collect');
|
||||
$model = $model->alias('r')->join('__WECHAT_USER__ u','u.uid=r.uid');
|
||||
$model = $model->field('r.*,u.nickname');
|
||||
return self::page($model);
|
||||
}
|
||||
public static function getLike($pid){
|
||||
$model = new self();
|
||||
$model = $model->where('r.product_id',$pid)->where('r.type','like');
|
||||
$model = $model->alias('r')->join('__WECHAT_USER__ u','u.uid=r.uid');
|
||||
$model = $model->field('r.*,u.nickname');
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
}
|
||||
46
application/admin/model/store/StoreProductReply.php
Normal file
46
application/admin/model/store/StoreProductReply.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 评论管理 model
|
||||
* Class StoreProductReply
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProductReply extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['comment'] != '') $model = $model->where('r.comment','LIKE',"%$where[comment]%");
|
||||
if($where['is_reply'] != ''){
|
||||
if($where['is_reply'] >= 0){
|
||||
$model = $model->where('r.is_reply',$where['is_reply']);
|
||||
}else{
|
||||
$model = $model->where('r.is_reply','GT',0);
|
||||
}
|
||||
}
|
||||
if($where['product_id']) $model = $model->where('r.product_id',$where['product_id']);
|
||||
$model = $model->alias('r')->join('__WECHAT_USER__ u','u.uid=r.uid');
|
||||
$model = $model->join('__STORE_PRODUCT__ p','p.id=r.product_id');
|
||||
$model = $model->where('r.is_del',0);
|
||||
$model = $model->field('r.*,u.nickname,u.headimgurl,p.store_name');
|
||||
return self::page($model,function($itme){
|
||||
|
||||
},$where);
|
||||
}
|
||||
|
||||
}
|
||||
55
application/admin/model/store/StoreService.php
Normal file
55
application/admin/model/store/StoreService.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use app\admin\model\store\StoreServiceLog as ServiceLogModel;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 客服管理 model
|
||||
* Class StoreProduct
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreService extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getList($mer_id){
|
||||
$model = new self;
|
||||
$model->alias('a');
|
||||
$model->join('__USER__ b ','b.uid = a.uid');
|
||||
$model->field('a.*,b.nickname as wx_name');
|
||||
$model->where("mer_id",$mer_id);
|
||||
$model->order('a.id desc');
|
||||
return self::page($model,function($item,$key){
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getChatUser($now_service,$mer_id){
|
||||
$where = 'mer_id = '.$mer_id.' AND (uid = '.$now_service["uid"].' OR to_uid='.$now_service["uid"].')';
|
||||
$chat_list = ServiceLogModel::field("uid,to_uid")->where($where)->group("uid,to_uid")->select();
|
||||
if(count($chat_list) > 0){
|
||||
$arr_user = $arr_to_user = [];
|
||||
foreach ($chat_list as $key => $value) {
|
||||
array_push($arr_user,$value["uid"]);
|
||||
array_push($arr_to_user,$value["to_uid"]);
|
||||
}
|
||||
$uids = array_merge($arr_user,$arr_to_user);
|
||||
|
||||
$list = WechatUser::field("uid,nickname,headimgurl")->where(array("uid"=>array(array("in",$uids),array("neq",$now_service["uid"]))))->select();
|
||||
foreach ($list as $index => $user) {
|
||||
$service = self::field("uid,nickname,avatar as headimgurl")->where(array("uid"=>$user["uid"]))->find();
|
||||
if($service)$list[$index] = $service;
|
||||
}
|
||||
}else{
|
||||
$list = null;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
32
application/admin/model/store/StoreServiceLog.php
Normal file
32
application/admin/model/store/StoreServiceLog.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use app\admin\model\store\StoreService as ServiceModel;
|
||||
use app\wap\model\user\User;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 客服管理 model
|
||||
* Class StoreProduct
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreServiceLog extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getChatList($uid,$to_uid,$mer_id){
|
||||
$model = new self;
|
||||
$where = "mer_id = ".$mer_id." AND ((uid = ".$uid." AND to_uid = ".$to_uid.") OR (uid = ".$to_uid." AND to_uid = ".$uid."))";
|
||||
$model->where($where);
|
||||
$model->order("add_time desc");
|
||||
return self::page($model,function($item,$key) use ($mer_id){
|
||||
$user = StoreService::field("nickname,avatar")->where('mer_id',$mer_id)->where(array("uid"=>$item["uid"]))->find();
|
||||
if(!$user)$user = User::field("nickname,avatar")->where(array("uid"=>$item["uid"]))->find();
|
||||
$item["nickname"] = $user["nickname"];
|
||||
$item["avatar"] = $user["avatar"];
|
||||
});
|
||||
}
|
||||
}
|
||||
57
application/admin/model/store/StoreVisit.php
Normal file
57
application/admin/model/store/StoreVisit.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use app\admin\model\user\User;
|
||||
/**
|
||||
* 商品浏览分析
|
||||
* Class StoreOrder
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreVisit extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getVisit($date,$class=[]){
|
||||
$model=new self();
|
||||
switch ($date){
|
||||
case null:case 'today':case 'week':case 'year':
|
||||
if($date==null) $date='month';
|
||||
$model=$model->whereTime('add_time',$date);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where('add_time','>',$startTime);
|
||||
$model = $model->where('add_time','<',$endTime);
|
||||
break;
|
||||
default:
|
||||
list($startTime,$endTime)=explode('-',$date);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
$list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
|
||||
$view=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
|
||||
$now_list['value']=$val['sum'];
|
||||
$now_list['class']=isset($class[$key])?$class[$key]:'';
|
||||
$view[]=$now_list;
|
||||
}
|
||||
if(empty($list)){
|
||||
$view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
159
application/admin/model/system/SystemAdmin.php
Normal file
159
application/admin/model/system/SystemAdmin.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use behavior\system\SystemBehavior;
|
||||
use service\HookService;
|
||||
use think\Session;
|
||||
|
||||
/**
|
||||
* Class SystemAdmin
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemAdmin extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
public static function setAddTimeAttr($value)
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function setRolesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户登陆
|
||||
* @param string $account 账号
|
||||
* @param string $pwd 密码
|
||||
* @param string $verify 验证码
|
||||
* @return bool 登陆成功失败
|
||||
*/
|
||||
public static function login($account,$pwd)
|
||||
{
|
||||
$adminInfo = self::get(compact('account'));
|
||||
if(!$adminInfo) return self::setErrorInfo('登陆的账号不存在!');
|
||||
if($adminInfo['pwd'] != md5($pwd)) return self::setErrorInfo('账号或密码错误,请重新输入');
|
||||
if(!$adminInfo['status']) return self::setErrorInfo('该账号已被关闭!');
|
||||
self::setLoginInfo($adminInfo);
|
||||
HookService::afterListen('system_admin_login',$adminInfo,null,false,SystemBehavior::class);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存当前登陆用户信息
|
||||
*/
|
||||
public static function setLoginInfo($adminInfo)
|
||||
{
|
||||
Session::set('adminId',$adminInfo['id']);
|
||||
Session::set('adminInfo',$adminInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前登陆用户信息
|
||||
*/
|
||||
public static function clearLoginInfo()
|
||||
{
|
||||
Session::delete('adminInfo');
|
||||
Session::delete('adminId');
|
||||
Session::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户登陆状态
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasActiveAdmin()
|
||||
{
|
||||
return Session::has('adminId') && Session::has('adminInfo');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得登陆用户信息
|
||||
* @return mixed
|
||||
*/
|
||||
public static function activeAdminInfoOrFail()
|
||||
{
|
||||
$adminInfo = Session::get('adminInfo');
|
||||
if(!$adminInfo) exception('请登陆');
|
||||
if(!$adminInfo['status']) exception('该账号已被关闭!');
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得登陆用户Id 如果没有直接抛出错误
|
||||
* @return mixed
|
||||
*/
|
||||
public static function activeAdminIdOrFail()
|
||||
{
|
||||
$adminId = Session::get('adminId');
|
||||
if(!$adminId) exception('访问用户为登陆登陆!');
|
||||
return $adminId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function activeAdminAuthOrFail()
|
||||
{
|
||||
$adminInfo = self::activeAdminInfoOrFail();
|
||||
return $adminInfo->level === 0 ? SystemRole::getAllAuth() : SystemRole::rolesByAuth($adminInfo->roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得有效管理员信息
|
||||
* @param $id
|
||||
* @return static
|
||||
*/
|
||||
public static function getValidAdminInfoOrFail($id)
|
||||
{
|
||||
$adminInfo = self::get($id);
|
||||
if(!$adminInfo) exception('用户不能存在!');
|
||||
if(!$adminInfo['status']) exception('该账号已被关闭!');
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $field
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getOrdAdmin($field = 'real_name,id',$level = 0){
|
||||
return self::where('level','>=',$level)->field($field)->select();
|
||||
}
|
||||
|
||||
public static function getTopAdmin($field = 'real_name,id')
|
||||
{
|
||||
return self::where('level',0)->field($field)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['name'] != ''){
|
||||
$model = $model->where('account','LIKE',"%$where[name]%");
|
||||
$model = $model->where('real_name','LIKE',"%$where[name]%");
|
||||
}
|
||||
if($where['roles'] != '')
|
||||
$model = $model->where("CONCAT(',',roles,',') LIKE '%,$where[roles],%'");
|
||||
$model = $model->where('level','=',$where['level'])->where('is_del',0);
|
||||
return self::page($model,function($admin,$key){
|
||||
$admin->roles = SystemRole::where('id','IN',$admin->roles)->column('role_name');
|
||||
},$where);
|
||||
}
|
||||
}
|
||||
52
application/admin/model/system/SystemAttachment.php
Normal file
52
application/admin/model/system/SystemAttachment.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/13
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 文件检验model
|
||||
* Class SystemFile
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemAttachment extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**添加附件记录
|
||||
*/
|
||||
public static function attachmentAdd($name,$att_size,$att_type,$att_dir,$satt_dir='',$pid = 0 )
|
||||
{
|
||||
$data['name'] = $name;
|
||||
$data['att_dir'] = $att_dir;
|
||||
$data['satt_dir'] = $satt_dir;
|
||||
$data['att_size'] = $att_size;
|
||||
$data['att_type'] = $att_type;
|
||||
$data['time'] = time();
|
||||
$data['pid'] = $pid;
|
||||
return self::create($data);
|
||||
}
|
||||
/**
|
||||
* 获取分类图
|
||||
* */
|
||||
public static function getAll($id){
|
||||
$model = new self;
|
||||
$where['pid'] = $id;
|
||||
$model->where($where)->order('att_id desc');
|
||||
return $model->page($model,$where,'',30);
|
||||
}
|
||||
/**
|
||||
* 获取单条信息
|
||||
* */
|
||||
public static function getinfo($att_id){
|
||||
$model = new self;
|
||||
$where['att_id'] = $att_id;
|
||||
return $model->where($where)->select()->toArray()[0];
|
||||
}
|
||||
|
||||
}
|
||||
73
application/admin/model/system/SystemAttachmentCategory.php
Normal file
73
application/admin/model/system/SystemAttachmentCategory.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* 附件目录
|
||||
*
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\UtilService;
|
||||
|
||||
/**
|
||||
* 文件检验model
|
||||
* Class SystemFile
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemAttachmentCategory extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**添加分类
|
||||
*/
|
||||
public static function Add($name,$att_size,$att_type,$att_dir,$satt_dir='',$pid = 0 )
|
||||
{
|
||||
$data['name'] = $name;
|
||||
$data['att_dir'] = $att_dir;
|
||||
$data['satt_dir'] = $satt_dir;
|
||||
$data['att_size'] = $att_size;
|
||||
$data['att_type'] = $att_type;
|
||||
$data['time'] = time();
|
||||
$data['pid'] = $pid;
|
||||
return self::create($data);
|
||||
}
|
||||
/**
|
||||
* 获取分类图
|
||||
* */
|
||||
public static function getAll(){
|
||||
$model = new self;
|
||||
return self::tidyMenuTier($model->select(),0);
|
||||
}
|
||||
public static function tidyMenuTier($menusList,$pid = 0,$navList = [])
|
||||
{
|
||||
|
||||
foreach ($menusList as $k=>$menu){
|
||||
$menu = $menu->getData();
|
||||
if($menu['pid'] == $pid){
|
||||
unset($menusList[$k]);
|
||||
$menu['child'] = self::tidyMenuTier($menusList,$menu['id']);
|
||||
$navList[] = $menu;
|
||||
}
|
||||
}
|
||||
return $navList;
|
||||
}
|
||||
|
||||
/**获取分类下拉列表
|
||||
* @return array
|
||||
*/
|
||||
public static function getCateList($id = 10000){
|
||||
$model = new self();
|
||||
if($id == 0)
|
||||
$model->where('pid',$id);
|
||||
return UtilService::sortListTier($model->select()->toArray());
|
||||
}
|
||||
/**
|
||||
* 获取单条信息
|
||||
* */
|
||||
public static function getinfo($att_id){
|
||||
$model = new self;
|
||||
$where['att_id'] = $att_id;
|
||||
return $model->where($where)->select()->toArray()[0];
|
||||
}
|
||||
|
||||
}
|
||||
1
application/admin/model/system/SystemConfig.php
Normal file
1
application/admin/model/system/SystemConfig.php
Normal file
File diff suppressed because one or more lines are too long
1
application/admin/model/system/SystemConfigTab.php
Normal file
1
application/admin/model/system/SystemConfigTab.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
/**
*
* @author: xaboy<365615158@qq.com>
* @day: 2017/11/02
*/
namespace app\admin\model\system;
use traits\ModelTrait;
use basic\ModelBasic;
use think\Db;
/**
* 配置分类model
*
* Class SystemConfigTab
* @package app\admin\model\system
*/
class SystemConfigTab extends ModelBasic {
use ModelTrait;
/**
* 获取单选按钮或者多选按钮的显示值
* */
public static function getRadioOrCheckboxValueInfo($menu_name,$value){
$parameter = array();
$option = array();
$config_one = \app\admin\model\system\SystemConfig::getOneConfig('menu_name',$menu_name);
// dump($config_one);
// exit();
// if(empty($menu) || !($config_one = self::get(['menu_name'=>$menu]))) return false;
$parameter = explode("\n",$config_one['parameter']);
foreach ($parameter as $k=>$v){
if(isset($v) && !empty($v)){
$option[$k] = explode('=',$v);
}
}
// $value = json_decode($value,true);
if(!is_array($value)){
$value = explode("\n",$value);
}
// dump($value);
// dump($option);
$value_arr = array();//选项的值
foreach ($option as $k=>$v){
foreach ($v as $kk=>$vv){
if(is_array($value)) {
if (in_array($v[0], $value)) {
$value_arr[$k] = $v[1];
}
}
break;
}
}
if(empty($value_arr)){
return '空';
}
return $value_arr;
// exit();
// if(is_array($value)){
// foreach ($value as $k=>$value_v){
// if(in_array($value_v,$value_arr)){
// $i[$k] = 1;
// }
// }
// if(count($value) != $i) return self::setErrorInfo('输入的值不属于选项中的参数');
// }else{
// if(in_array($value,$value_arr)){
// $i++;
// }
// if(!$i) return self::setErrorInfo('输入的值不属于选项中的参数');
// }
// if($config_one['type'] == 'radio' && is_array($value)) return self::setErrorInfo('单选按钮的值是字符串不是数组');
}
/**
* 插入数据到数据库
* */
public static function set($data)
{
return self::create($data);
}
/**
* 获取全部
* */
public static function getAll($type = 0){
$where['status'] = 1;
if($type>-1)$where['type'] = $type;
return Db::name('SystemConfigTab')->where($where)->select();
}
/**
* 获取配置分类
* */
public static function getSystemConfigTabPage($where = array())
{
$model = new self;
if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
if($where['status'] != '') $model = $model->where('status',$where['status']);
return self::page($model,$where);
}
public static function edit($data,$id,$field='id')
{
return self::update($data,[$field=>$id]);
}
/**
* 更新数据
* @access public
* @param array $data 数据数组
* @param array $where 更新条件
* @param array|true $field 允许字段
* @return $this
*/
public static function update($data = [], $where = [], $field = null)
{
$model = new static();
if (!empty($field)) {
$model->allowField($field);
}
$result = $model->isUpdate(true)->save($data, $where);
return $model;
}
}
|
||||
23
application/admin/model/system/SystemFile.php
Normal file
23
application/admin/model/system/SystemFile.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/13
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 附件管理model
|
||||
* Class SystemAttachment
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemFile extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
|
||||
}
|
||||
31
application/admin/model/system/SystemGroup.php
Normal file
31
application/admin/model/system/SystemGroup.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/13
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 数据组model
|
||||
* Class SystemGroup
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemGroup extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 根据id获取当前记录中的fields值
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public static function getField($id){
|
||||
$fields = json_decode(self::where('id',$id)->value("fields"),true);
|
||||
return compact('fields');
|
||||
}
|
||||
}
|
||||
112
application/admin/model/system/SystemGroupData.php
Normal file
112
application/admin/model/system/SystemGroupData.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/13
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 数据列表 model
|
||||
* Class SystemGroupData
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemGroupData extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 根据where条件获取当前表中的前20条数据
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public static function getList($params){
|
||||
$model = new self;
|
||||
if($params['gid'] !== '') $model = $model->where('gid',$params['gid']);
|
||||
if($params['status'] !== '') $model = $model->where('status',$params['status']);
|
||||
return self::page($model,function($item,$key){
|
||||
$info = json_decode($item->value,true);
|
||||
foreach ($info as $index => $value) {
|
||||
if($value["type"] == "checkbox")$info[$index]["value"] = implode(",",$value["value"]);
|
||||
if($value["type"] == "upload" || $value["type"] == "uploads"){
|
||||
$html_img = '';
|
||||
if(is_array($value["value"])){
|
||||
foreach ($value["value"] as $img) {
|
||||
$html_img .= '<img class="image" data-image="'.$img.'" width="45" height="45" src="'.$img.'" /><br>';
|
||||
}
|
||||
}else{
|
||||
$html_img = '<img class="image" data-image="'.$value["value"].'" width="45" height="45" src="'.$value["value"].'" />';
|
||||
}
|
||||
$info[$index]["value"] = $html_img;
|
||||
}
|
||||
}
|
||||
$item->value = $info;
|
||||
});
|
||||
}
|
||||
|
||||
public static function getGroupData($config_name,$limit = 0)
|
||||
{
|
||||
$group = SystemGroup::where('config_name',$config_name)->field('name,info,config_name')->find();
|
||||
if(!$group) return false;
|
||||
$group['data'] = self::getAllValue($config_name,$limit);
|
||||
return $group;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个值
|
||||
* @param $config_name
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAllValue($config_name,$limit = 0){
|
||||
$model = new self;
|
||||
$model->alias('a')->field('a.*,b.config_name')->join('system_group b','a.gid = b.id')->where(array("b.config_name"=>$config_name,"a.status"=>1))->order('sort desc,id ASC');
|
||||
if($limit > 0) $model->limit($limit);
|
||||
$data = [];
|
||||
$result = $model->select();
|
||||
if(!$result) return $data;
|
||||
foreach ($result as $key => $value) {
|
||||
$data[$key]["id"] = $value["id"];
|
||||
$fields = json_decode($value["value"],true);
|
||||
foreach ($fields as $index => $field) {
|
||||
// $data[$key][$index] = $field['type'] == 'upload' ? (isset($field["value"][0]) ? $field["value"][0]: ''):$field["value"];
|
||||
$data[$key][$index] = $field["value"];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function tidyList($result)
|
||||
{
|
||||
$data = [];
|
||||
if(!$result) return $data;
|
||||
foreach ($result as $key => $value) {
|
||||
$data[$key]["id"] = $value["id"];
|
||||
$fields = json_decode($value["value"],true);
|
||||
foreach ($fields as $index => $field) {
|
||||
$data[$key][$index] = $field['type'] == 'upload' ? (isset($field["value"][0]) ? $field["value"][0]: ''):$field["value"];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取当前记录中的数据
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getDateValue($id){
|
||||
$value = self::alias('a')->where(array("id"=>$id))->find();
|
||||
$data["id"] = $value["id"];
|
||||
$fields = json_decode($value["value"],true);
|
||||
foreach ($fields as $index => $field) {
|
||||
$data[$index] = $field["value"];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
101
application/admin/model/system/SystemLog.php
Normal file
101
application/admin/model/system/SystemLog.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/28
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use think\Request;
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
|
||||
/**
|
||||
* 管理员操作记录
|
||||
* Class SystemLog
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemLog extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员访问记录
|
||||
* @param Request $request
|
||||
*/
|
||||
public static function adminVisit($adminId,$adminName,$type)
|
||||
{
|
||||
$request = Request::instance();
|
||||
$module = $request->module();
|
||||
$controller = $request->controller();
|
||||
$action = $request->action();
|
||||
$route = $request->route();
|
||||
$data = [
|
||||
'method'=>$request->method(),
|
||||
'admin_id'=>$adminId,
|
||||
'admin_name'=>$adminName,
|
||||
'path'=>SystemMenus::getAuthName($action,$controller,$module,$route),
|
||||
'page'=>SystemMenus::getVisitName($action,$controller,$module,$route)?:'未知',
|
||||
'ip'=>$request->ip(),
|
||||
'type'=>$type
|
||||
];
|
||||
return self::set($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动添加管理员当前页面访问记录
|
||||
* @param array $adminInfo
|
||||
* @param string $page 页面名称
|
||||
* @return object
|
||||
*/
|
||||
public static function setCurrentVisit($adminInfo, $page)
|
||||
{
|
||||
$request = Request::instance();
|
||||
$module = $request->module();
|
||||
$controller = $request->controller();
|
||||
$action = $request->action();
|
||||
$route = $request->route();
|
||||
$data = [
|
||||
'method'=>$request->method(),
|
||||
'admin_id'=>$adminInfo['id'],
|
||||
'path'=>SystemMenus::getAuthName($action,$controller,$module,$route),
|
||||
'page'=>$page,
|
||||
'ip'=>$request->ip()
|
||||
];
|
||||
return self::set($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员访问记录
|
||||
* */
|
||||
public static function systemPage($where = array()){
|
||||
$model = new self;
|
||||
$model = $model->alias('l');
|
||||
if($where['pages'] !== '') $model = $model->where('l.page','LIKE',"%$where[pages]%");
|
||||
if($where['admin_id'] != '')
|
||||
$adminIds = $where['admin_id'];
|
||||
else
|
||||
$adminIds = SystemAdmin::where('level','>=',$where['level'])->column('id');
|
||||
$model = $model->where('l.admin_id','IN',$adminIds);
|
||||
if($where['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$where['data']);
|
||||
$model = $model->where('l.add_time','>',strtotime($startTime));
|
||||
$model = $model->where('l.add_time','<',strtotime($endTime));
|
||||
}
|
||||
$model->where('l.type','system');
|
||||
$model = $model->order('l.id desc');
|
||||
return self::page($model,$where);
|
||||
}
|
||||
}
|
||||
150
application/admin/model/system/SystemMenus.php
Normal file
150
application/admin/model/system/SystemMenus.php
Normal file
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use think\Url;
|
||||
|
||||
/**
|
||||
* 菜单 model
|
||||
* Class SystemMenus
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemMenus extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static $isShowStatus = [1=>'显示',0=>'不显示'];
|
||||
|
||||
public static $accessStatus = [1=>'管理员可用',0=>'管理员不可用'];
|
||||
|
||||
public static function legalWhere($where = [])
|
||||
{
|
||||
$where['is_show'] = 1;
|
||||
}
|
||||
|
||||
public function setParamsAttr($value)
|
||||
{
|
||||
$value = $value ? explode('/',$value) : [];
|
||||
$params = array_chunk($value,2);
|
||||
$data = [];
|
||||
foreach ($params as $param){
|
||||
if(isset($param[0]) && isset($param[1])) $data[$param[0]] = $param[1];
|
||||
}
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
protected function setControllerAttr($value)
|
||||
{
|
||||
return lcfirst($value);
|
||||
}
|
||||
|
||||
public function getParamsAttr($_value)
|
||||
{
|
||||
return json_decode($_value,true);
|
||||
}
|
||||
|
||||
public function getPidAttr($value)
|
||||
{
|
||||
return !$value ? '顶级' : self::get($value)['menu_name'];
|
||||
}
|
||||
|
||||
public static function getParentMenu($field='*',$filter=false)
|
||||
{
|
||||
$where = ['pid'=>0];
|
||||
$query = self::field($field);
|
||||
$query = $filter ? $query->where(self::legalWhere($where)) : $query->where($where);
|
||||
return $query->order('sort DESC')->select();
|
||||
}
|
||||
|
||||
public static function menuList()
|
||||
{
|
||||
$menusList = self::where('is_show','1')->where('access','1')->order('sort DESC')->select();
|
||||
return self::tidyMenuTier(true,$menusList);
|
||||
}
|
||||
|
||||
public static function ruleList()
|
||||
{
|
||||
$ruleList = self::order('sort DESC')->select();
|
||||
return self::tidyMenuTier(false,$ruleList);
|
||||
}
|
||||
|
||||
public static function rolesByRuleList($rules)
|
||||
{
|
||||
$res = SystemRole::where('id','IN',$rules)->field('GROUP_CONCAT(rules) as ids')->find();
|
||||
$ruleList = self::where('id','IN',$res['ids'])->whereOr('pid',0)->order('sort DESC')->select();
|
||||
return self::tidyMenuTier(false,$ruleList);
|
||||
}
|
||||
|
||||
public static function getAuthName($action,$controller,$module,$route)
|
||||
{
|
||||
return strtolower($module.'/'.$controller.'/'.$action.'/'.SystemMenus::paramStr($route));
|
||||
}
|
||||
|
||||
public static function tidyMenuTier($adminFilter = false,$menusList,$pid = 0,$navList = [])
|
||||
{
|
||||
static $allAuth = null;
|
||||
static $adminAuth = null;
|
||||
if($allAuth === null) $allAuth = $adminFilter == true ? SystemRole::getAllAuth() : [];//所有的菜单
|
||||
if($adminAuth === null) $adminAuth = $adminFilter == true ? SystemAdmin::activeAdminAuthOrFail() : [];//当前登录用户的菜单
|
||||
foreach ($menusList as $k=>$menu){
|
||||
$menu = $menu->getData();
|
||||
if($menu['pid'] == $pid){
|
||||
unset($menusList[$k]);
|
||||
$params = json_decode($menu['params'],true);//获取参数
|
||||
$authName = self::getAuthName($menu['action'],$menu['controller'],$menu['module'],$params);// 按钮链接
|
||||
if($pid != 0 && $adminFilter && in_array($authName,$allAuth) && !in_array($authName,$adminAuth)) continue;
|
||||
$menu['child'] = self::tidyMenuTier($adminFilter,$menusList,$menu['id']);
|
||||
if($pid != 0 && !count($menu['child']) && !$menu['controller'] && !$menu['action']) continue;
|
||||
$menu['url'] = !count($menu['child']) ? Url::build($menu['module'].'/'.$menu['controller'].'/'.$menu['action'],$params) : 'javascript:void(0);';
|
||||
if($pid == 0 && !count($menu['child'])) continue;
|
||||
$navList[] = $menu;
|
||||
}
|
||||
}
|
||||
return $navList;
|
||||
}
|
||||
|
||||
public static function delMenu($id)
|
||||
{
|
||||
if(self::where('pid',$id)->count())
|
||||
return self::setErrorInfo('请先删除改菜单下的子菜单!');
|
||||
return self::del($id);
|
||||
}
|
||||
|
||||
public static function getAdminPage($params)
|
||||
{
|
||||
$model = new self;
|
||||
if($params['is_show'] !== '') $model = $model->where('is_show',$params['is_show']);
|
||||
// if($params['access'] !== '') $model = $model->where('access',$params['access']);//子管理员是否可用
|
||||
if($params['pid'] !== ''&& !$params['keyword'] ) $model = $model->where('pid',$params['pid']);
|
||||
if($params['keyword'] !== '') $model = $model->where('menu_name|id|pid','LIKE',"%$params[keyword]%");
|
||||
$model = $model->order('sort DESC,id DESC');
|
||||
return self::page($model,$params);
|
||||
}
|
||||
|
||||
public static function paramStr($params)
|
||||
{
|
||||
if(!is_array($params)) $params = json_decode($params,true)?:[];
|
||||
$p = [];
|
||||
foreach ($params as $key => $param){
|
||||
$p[] = $key;
|
||||
$p[] = $param;
|
||||
}
|
||||
return implode('/',$p);
|
||||
}
|
||||
|
||||
public static function getVisitName($action,$controller,$module,array $route = [])
|
||||
{
|
||||
$params = json_encode($route);
|
||||
return self::where('action',$action)
|
||||
->where('controller',lcfirst($controller))
|
||||
->where('module',lcfirst($module))
|
||||
->where('params',['=',$params],['=','[]'],'or')->order('id DESC')->value('menu_name');
|
||||
}
|
||||
|
||||
}
|
||||
121
application/admin/model/system/SystemNotice.php
Normal file
121
application/admin/model/system/SystemNotice.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 后台通知model
|
||||
* Class SystemNotice
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemNotice extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected function setResultAttr($value)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
|
||||
protected function setTableTitleAttr($value)
|
||||
{
|
||||
$list = [];
|
||||
if(!empty($value)){
|
||||
$group = explode(',',$value);
|
||||
$list = array_map(function($v){
|
||||
list($title,$key) = explode('-',$v);
|
||||
return compact('title','key');
|
||||
},$group);
|
||||
}
|
||||
return json_encode($list);
|
||||
}
|
||||
|
||||
protected function getTableTitleAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
|
||||
protected function getResultAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
|
||||
protected function setPushAdminAttr($value)
|
||||
{
|
||||
$value = is_array($value) ? array_unique(array_filter($value)) : [];
|
||||
return implode(',',$value);
|
||||
}
|
||||
|
||||
protected function getPushAdminAttr($value)
|
||||
{
|
||||
return array_filter(explode(',',$value));
|
||||
}
|
||||
|
||||
public static function typeByAdminList($type,$field = 'id')
|
||||
{
|
||||
return self::where('type',$type)->field($field)->find();
|
||||
}
|
||||
|
||||
public static function systemNoticeAdminDb()
|
||||
{
|
||||
return Db::name('SystemNoticeAdmin');
|
||||
}
|
||||
|
||||
public static function adminMessage($notice_type,$admin_id,$link_id,array $table_data = [])
|
||||
{
|
||||
$table_data = json_encode($table_data);
|
||||
$add_time = time();
|
||||
return self::systemNoticeAdminDb()->insert(compact('notice_type','admin_id','link_id','table_data','add_time'));
|
||||
}
|
||||
|
||||
public static function noticeMessage($noticeType,$linkId,array $tableData = [])
|
||||
{
|
||||
$noticeInfo = self::get(['type'=>$noticeType]);
|
||||
if(!$noticeInfo) return self::setErrorInfo('通知模板消息不存在!');
|
||||
$adminIds = array_merge(array_map(function($v){
|
||||
return $v['id'];
|
||||
},SystemAdmin::getTopAdmin('id')->toArray())?:[],self::typeByAdminList($noticeType,'push_admin')->push_admin?:[]);
|
||||
$adminIds = array_unique(array_filter($adminIds));
|
||||
if(!count($adminIds)) return self::setErrorInfo('没有有效的通知用户!');
|
||||
foreach ($adminIds as $id){
|
||||
self::adminMessage($noticeType,$id,$linkId,$tableData);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getAdminNoticeTotal($adminId)
|
||||
{
|
||||
$list = self::alias('A')->join('__SYSTEM_NOTICE_ADMIN__ B','B.notice_type = A.type')
|
||||
->where('A.status',1)->where('B.is_visit',0)->where('B.is_click',0)->where('B.admin_id',$adminId)
|
||||
->field('count(B.id) total')->group('A.id')->select()->toArray();
|
||||
if(!$list) return 0;
|
||||
return array_reduce($list,function($initial,$res){
|
||||
return $initial+$res['total'];
|
||||
},0);
|
||||
}
|
||||
|
||||
public static function getAdminNotice($adminId)
|
||||
{
|
||||
$list = self::alias('A')->join('__SYSTEM_NOTICE_ADMIN__ B','B.notice_type = A.type')
|
||||
->where('A.status',1)->where('B.is_visit',0)->where('B.is_click',0)->where('B.admin_id',$adminId)
|
||||
->field('A.id,A.type,A.title,A.icon,count(B.id) total,A.template,max(B.add_time) as last_time')
|
||||
->group('A.id')->having('total > 0')->select()->toArray();
|
||||
$noticeTypeList = [];
|
||||
array_walk($list,function(&$notice) use(&$noticeTypeList){
|
||||
$notice['message'] = sprintf($notice['template'],$notice['total']);
|
||||
$noticeTypeList[] = $notice['type'];
|
||||
});
|
||||
if(count($noticeTypeList))
|
||||
self::systemNoticeAdminDb()->where('notice_type','IN',$noticeTypeList)->where('admin_id',$adminId)
|
||||
->update(['is_visit'=>1,'visit_time'=>time()]);
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
81
application/admin/model/system/SystemRole.php
Normal file
81
application/admin/model/system/SystemRole.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/13
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* 身份管理 model
|
||||
* Class SystemRole
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemRole extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function setRulesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择管理员身份
|
||||
* @param int $level
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public static function getRole($level = 0 ,$field='id,role_name')
|
||||
{
|
||||
return self::where('status',1)->where('level','=',$level)->column($field);
|
||||
}
|
||||
|
||||
|
||||
public static function rolesByAuth($rules)
|
||||
{
|
||||
if(empty($rules)) return [];
|
||||
$rules = self::where('id','IN',$rules)->where('status','1')->column('rules');
|
||||
$rules = array_unique(explode(',',implode(',',$rules)));
|
||||
$_auth = SystemMenus::all(function($query) use($rules){
|
||||
$query->where('id','IN',$rules)
|
||||
->where('controller|action','<>','')
|
||||
->field('module,controller,action,params');
|
||||
});
|
||||
return self::tidyAuth($_auth?:[]);
|
||||
}
|
||||
|
||||
public static function getAllAuth()
|
||||
{
|
||||
static $auth = null;
|
||||
$auth === null && ($auth = self::tidyAuth(SystemMenus::all(function($query){
|
||||
$query->where('controller|action','<>','')->field('module,controller,action,params');
|
||||
})?:[]));
|
||||
return $auth;
|
||||
}
|
||||
|
||||
protected static function tidyAuth($_auth)
|
||||
{
|
||||
$auth = [];
|
||||
foreach ($_auth as $k=>$val){
|
||||
$auth[] = SystemMenus::getAuthName($val['action'],$val['controller'],$val['module'],$val['params']);
|
||||
}
|
||||
return $auth;
|
||||
}
|
||||
|
||||
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['role_name'] != '') $model = $model->where('role_name','LIKE',"%$where[role_name]%");
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
$model->where('level','=',bcadd($where['level'],1,0));
|
||||
return self::page($model,(function($item,$key){
|
||||
$item->rules = SystemMenus::where('id','IN',$item->rules)->column('menu_name');
|
||||
}),$where);
|
||||
}
|
||||
|
||||
}
|
||||
62
application/admin/model/ump/StoreCoupon.php
Normal file
62
application/admin/model/ump/StoreCoupon.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* Class StoreCategory
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreCoupon extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
// if($where['is_del'] != '') $model = $model->where('is_del',$where['is_del']);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->order('sort desc,id desc');
|
||||
return self::page($model,$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPageCoupon($where){
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
if($where['title'] != '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
// if($where['is_del'] != '') $model = $model->where('is_del',$where['is_del']);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->where('status',1);
|
||||
$model = $model->order('sort desc,id desc');
|
||||
return self::page($model,$where);
|
||||
}
|
||||
|
||||
public static function editIsDel($id){
|
||||
$data['status'] = 0;
|
||||
self::beginTrans();
|
||||
$res1 = self::edit($data,$id);
|
||||
$res2 = false !== StoreCouponUser::where('cid',$id)->setField('is_fail',1);
|
||||
$res3 = false !== StoreCouponIssue::where('cid',$id)->setField('status',-1);
|
||||
$res = $res1 && $res2 && $res3;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
|
||||
}
|
||||
}
|
||||
40
application/admin/model/ump/StoreCouponIssue.php
Normal file
40
application/admin/model/ump/StoreCouponIssue.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/17
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponIssue extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
public static function stsypage($where){
|
||||
$model = self::alias('A')->field('A.*,B.title')->join('__STORE_COUPON__ B','A.cid = B.id')->where('A.is_del',0)->order('A.add_time DESC');
|
||||
if(isset($where['status']) && $where['status']!=''){
|
||||
$model=$model->where('A.status',$where['status']);
|
||||
}
|
||||
if(isset($where['coupon_title']) && $where['coupon_title']!=''){
|
||||
$model=$model->where('B.title','LIKE',"%$where[coupon_title]%");
|
||||
}
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
protected function setAddTimeAttr()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function setIssue($cid,$total_count = 0,$start_time = 0,$end_time = 0,$remain_count = 0,$status = 0)
|
||||
{
|
||||
return self::set(compact('cid','start_time','end_time','total_count','remain_count','status'));
|
||||
}
|
||||
}
|
||||
29
application/admin/model/ump/StoreCouponIssueUser.php
Normal file
29
application/admin/model/ump/StoreCouponIssueUser.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/23
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreCouponIssueUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function systemCouponIssuePage($issue_coupon_id)
|
||||
{
|
||||
$model = self::alias('A')->field('B.nickname,B.avatar,A.add_time')
|
||||
->join('__USER__ B','A.uid = B.uid')
|
||||
->where('A.issue_coupon_id',$issue_coupon_id);
|
||||
return self::page($model,function($item){
|
||||
$item['add_time'] = $item['add_time'] == 0 ? '未知' : date('Y/m/d H:i',$item['add_time']);
|
||||
return $item;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
69
application/admin/model/ump/StoreCouponUser.php
Normal file
69
application/admin/model/ump/StoreCouponUser.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
|
||||
/**
|
||||
* Class StoreCategory
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreCouponUser extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
if($where['is_fail'] != '') $model = $model->where('status',$where['is_fail']);
|
||||
if($where['coupon_title'] != '') $model = $model->where('coupon_title','LIKE',"%$where[coupon_title]%");
|
||||
if($where['nickname'] != ''){
|
||||
$uid = UserModel::where('nickname','LIKE',"%$where[nickname]%")->column('uid');
|
||||
$model = $model->where('uid','IN',implode(',',$uid));
|
||||
};
|
||||
// $model = $model->where('is_del',0);
|
||||
$model = $model->order('id desc');
|
||||
return self::page($model,function ($item){
|
||||
$item['nickname'] = UserModel::where('uid',$item['uid'])->value('nickname');
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给用户发放优惠券
|
||||
* @param $coupon
|
||||
* @param $user
|
||||
* @return int|string
|
||||
*/
|
||||
public static function setCoupon($coupon,$user){
|
||||
$data = array();
|
||||
foreach ($user as $k=>$v){
|
||||
$data[$k]['cid'] = $coupon['id'];
|
||||
$data[$k]['uid'] = $v;
|
||||
$data[$k]['coupon_title'] = $coupon['title'];
|
||||
$data[$k]['coupon_price'] = $coupon['coupon_price'];
|
||||
$data[$k]['use_min_price'] = $coupon['use_min_price'];
|
||||
$data[$k]['add_time'] = time();
|
||||
$data[$k]['end_time'] = $data[$k]['add_time']+$coupon['coupon_time']*86400;
|
||||
}
|
||||
$data_num = array_chunk($data,30);
|
||||
self::beginTrans();
|
||||
$res = true;
|
||||
foreach ($data_num as $k=>$v){
|
||||
$res = $res && self::insertAll($v);
|
||||
}
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
331
application/admin/model/ump/StoreSeckill.php
Normal file
331
application/admin/model/ump/StoreSeckill.php
Normal file
@ -0,0 +1,331 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\store\StoreProductRelation;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use service\PHPExcelService;
|
||||
|
||||
/**
|
||||
* Class StoreSeckill
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreSeckill extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 秒杀产品过滤条件
|
||||
* @param $model
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public static function setWhereType($model,$type){
|
||||
switch ($type){
|
||||
case 1:
|
||||
$data = ['status'=>0,'is_del'=>0];
|
||||
break;
|
||||
case 2:
|
||||
$data = ['status'=>1,'is_del'=>0];
|
||||
break;
|
||||
case 3:
|
||||
$data = ['status'=>1,'is_del'=>0,'stock'=>0];
|
||||
break;
|
||||
case 4:
|
||||
$data = ['status'=>1,'is_del'=>0,'stock'=>['elt',1]];
|
||||
break;
|
||||
case 5:
|
||||
$data = ['is_del'=>1];
|
||||
break;
|
||||
}
|
||||
if(isset($data)) $model = $model->where($data);
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀产品数量 图标展示
|
||||
* @param $type
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public static function getChatrdata($type,$data){
|
||||
$legdata = ['销量','数量','点赞','收藏'];
|
||||
$model = self::setWhereType(self::order('id desc'),$type);
|
||||
$list = self::getModelTime(compact('data'),$model)
|
||||
->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(id) as count,sum(sales) as sales')
|
||||
->group('un_time')
|
||||
->distinct(true)
|
||||
->select()
|
||||
->each(function($item) use($data){
|
||||
$item['collect']=self::getModelTime(compact('data'),new StoreProductRelation)->where(['type'=>'collect'])->count();
|
||||
$item['like']=self::getModelTime(compact('data'),new StoreProductRelation())->where(['type'=>'like'])->count();
|
||||
})->toArray();
|
||||
$chatrList=[];
|
||||
$datetime=[];
|
||||
$data_item=[];
|
||||
$itemList=[0=>[],1=>[],2=>[],3=>[]];
|
||||
foreach ($list as $item){
|
||||
$itemList[0][]=$item['sales'];
|
||||
$itemList[1][]=$item['count'];
|
||||
$itemList[2][]=$item['like'];
|
||||
$itemList[3][]=$item['collect'];
|
||||
array_push($datetime,$item['un_time']);
|
||||
}
|
||||
foreach ($legdata as $key=>$leg){
|
||||
$data_item['name']=$leg;
|
||||
$data_item['type']='line';
|
||||
$data_item['data']=$itemList[$key];
|
||||
$chatrList[]=$data_item;
|
||||
unset($data_item);
|
||||
}
|
||||
unset($leg);
|
||||
$badge = self::getbadge(compact('data'),$type);
|
||||
$count = self::setWhereType(self::getModelTime(compact('data'),new self()),$type)->count();
|
||||
return compact('datetime','chatrList','legdata','badge','count');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀产品数量
|
||||
* @param $where
|
||||
* @param $type
|
||||
* @return array
|
||||
*/
|
||||
public static function getbadge($where,$type){
|
||||
$StoreOrderModel = new StoreOrder();
|
||||
$replenishment_num = SystemConfig::getValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$stock1 = self::getModelTime($where,new self())->where('stock','<',$replenishment_num)->column('stock');
|
||||
$sum_stock = self::where('stock','<',$replenishment_num)->column('stock');
|
||||
$stk=[];
|
||||
foreach ($stock1 as $item){
|
||||
$stk[]=$replenishment_num-$item;
|
||||
}
|
||||
$lack=array_sum($stk);
|
||||
$sum=[];
|
||||
foreach ($sum_stock as $val){
|
||||
$sum[]=$replenishment_num-$val;
|
||||
}
|
||||
return [
|
||||
[
|
||||
'name'=>'商品数量',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(new self(),$type)->where('add_time','<',mktime(0,0,0,date('m'),date('d'),date('Y')))->sum('stock'),
|
||||
'content'=>'商品数量总数',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>self::sum('stock'),
|
||||
'class'=>'fa fa fa-ioxhost',
|
||||
],
|
||||
[
|
||||
'name'=>'新增商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(self::getModelTime($where,new self),$type)->sum('stock'),
|
||||
'content'=>'新增商品总数',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::where('status',1)->sum('stock'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'活动商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::getModelTime($where,$StoreOrderModel)->where('seckill_id','NEQ',0)->sum('total_num'),
|
||||
'content'=>'活动商品总数',
|
||||
'background_color'=>'layui-bg-green',
|
||||
'sum'=>$StoreOrderModel->sum('total_num'),
|
||||
'class'=>'fa fa-bar-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'缺货商品',
|
||||
'field'=>'件',
|
||||
'count'=>$lack,
|
||||
'content'=>'总商品数量',
|
||||
'background_color'=>'layui-bg-orange',
|
||||
'sum'=>array_sum($sum),
|
||||
'class'=>'fa fa-cube',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 销量排行 top 10
|
||||
* layui-bg-red 红 layui-bg-orange 黄 layui-bg-green 绿 layui-bg-blue 蓝 layui-bg-cyan 黑
|
||||
*/
|
||||
public static function getMaxList($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model=StoreOrder::alias('a')->join('store_seckill b','b.id=a.seckill_id')->where('a.paid',1);
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('a.seckill_id')->order('p_count desc')->limit(10)
|
||||
->field(['count(a.seckill_id) as p_count','b.title as store_name','sum(b.price) as sum_price'])->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
unset($item);
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['p_count'],$sum_count,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name']);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀利润
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function ProfityTop10($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model = StoreOrder::alias('a')->join('store_seckill b','b.id = a.seckill_id')->where('a.paid',1);
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('a.seckill_id')->order('profity desc')->limit(10)
|
||||
->field(['count(a.seckill_id) as p_count','b.title as store_name','sum(b.price) as sum_price','(b.price-b.cost) as profity'])
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['sum_price'],$sum_price,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name'],30);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀缺货
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getLackList($where){
|
||||
$replenishment_num = SystemConfig::getValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$list=self::where('stock','<',$replenishment_num)->field(['id','title as store_name','stock','price'])->page((int)$where['page'],(int)$where['limit'])->order('stock asc')->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$count=self::where('stock','<',$replenishment_num)->count();
|
||||
return ['count'=>$count,'data'=>$list];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀产品评价
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getNegativeList($where = array()){
|
||||
$replenishment_num = 3;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 秒杀产品退货
|
||||
* @param array $where
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getBargainRefundList($where = array()){
|
||||
$model = StoreOrder::alias('a')->join('store_seckill b','b.id=a.seckill_id');
|
||||
$list = self::getModelTime($where,$model,'a.add_time')->where('a.refund_status','NEQ',0)->group('a.seckill_id')->order('count desc')->page((int)$where['page'],(int)$where['limit'])
|
||||
->field(['count(a.seckill_id) as count','b.title as store_name','sum(b.price) as sum_price'])->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
$model = $model->alias('s');
|
||||
// $model = $model->join('StoreProduct p','p.id=s.product_id');
|
||||
if($where['status'] != '') $model = $model->where('s.status',$where['status']);
|
||||
if($where['store_name'] != '') $model = $model->where('s.title|s.id','LIKE',"%$where[store_name]%");
|
||||
$model = $model->page(bcmul($where['page'],$where['limit'],0),$where['limit']);
|
||||
$model = $model->order('s.id desc');
|
||||
$model = $model->where('s.is_del',0);
|
||||
return self::page($model,function($item){
|
||||
$item['store_name'] = StoreProduct::where('id',$item['product_id'])->value('store_name');
|
||||
if($item['status']){
|
||||
if($item['start_time'] > time())
|
||||
$item['start_name'] = '活动未开始';
|
||||
else if($item['stop_time'] < time())
|
||||
$item['start_name'] = '活动已结束';
|
||||
else if($item['stop_time'] > time() && $item['start_time'] < time())
|
||||
$item['start_name'] = '正在进行中';
|
||||
}else $item['start_name'] = '关闭';
|
||||
|
||||
},$where,$where['limit']);
|
||||
}
|
||||
public static function SaveExcel($where){
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('status',$where['status']);
|
||||
if($where['store_name'] != '') $model = $model->where('title|id','LIKE',"%$where[store_name]%");
|
||||
$list = $model->order('id desc')->where('is_del',0)->select();
|
||||
count($list) && $list=$list->toArray();
|
||||
$excel=[];
|
||||
foreach ($list as $item){
|
||||
$item['store_name'] = StoreProduct::where('id',$item['product_id'])->value('store_name');
|
||||
if($item['status']){
|
||||
if($item['start_time'] > time())
|
||||
$item['start_name'] = '活动未开始';
|
||||
else if($item['stop_time'] < time())
|
||||
$item['start_name'] = '活动已结束';
|
||||
else if($item['stop_time'] > time() && $item['start_time'] < time())
|
||||
$item['start_name'] = '正在进行中';
|
||||
}else $item['start_name'] = '关闭';
|
||||
$excel[]=[
|
||||
$item['id'],
|
||||
$item['title'],
|
||||
$item['info'],
|
||||
$item['ot_price'],
|
||||
$item['price'],
|
||||
$item['stock'],
|
||||
$item['start_name'],
|
||||
$item['stop_time'],
|
||||
$item['stop_time'],
|
||||
$item['status']? '开启':'关闭',
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['编号','活动标题','活动简介','原价','秒杀价','库存','秒杀状态','结束时间','状态'])
|
||||
->setExcelTile('秒杀产品导出',' ',' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($excel)
|
||||
->ExcelSave();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀产品id
|
||||
* @return array
|
||||
*/
|
||||
public static function getSeckillIdAll(){
|
||||
return self::where('is_del',0)->column('id','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取秒杀的所有产品
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getSeckillCount(){
|
||||
return self::where('is_del',0)->count();
|
||||
}
|
||||
}
|
||||
114
application/admin/model/ump/StoreSeckillAttr.php
Normal file
114
application/admin/model/ump/StoreSeckillAttr.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreSeckillAttr extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected function setAttrValuesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function getAttrValuesAttr($value)
|
||||
{
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
|
||||
public static function createProductAttr($attrList,$valueList,$productId)
|
||||
{
|
||||
$result = ['attr'=>$attrList,'value'=>$valueList];
|
||||
$attrValueList = [];
|
||||
$attrNameList = [];
|
||||
foreach ($attrList as $index=>$attr){
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!');
|
||||
$attr['value'] = trim($attr['value']);
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!!');
|
||||
if(!isset($attr['detail']) || !count($attr['detail'])) return self::setErrorInfo('请输入属性名称!');
|
||||
foreach ($attr['detail'] as $k=>$attrValue){
|
||||
$attrValue = trim($attrValue);
|
||||
if(empty($attrValue)) return self::setErrorInfo('请输入正确的属性');
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
$attrValueList[] = $attrValue;
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
}
|
||||
$attrNameList[] = $attr['value'];
|
||||
$attrList[$index] = $attr;
|
||||
}
|
||||
$attrCount = count($attrList);
|
||||
foreach ($valueList as $index=>$value){
|
||||
if(!isset($value['detail']) || count($value['detail']) != $attrCount) return self::setErrorInfo('请填写正确的商品信息');
|
||||
if(!isset($value['price']) || !is_numeric($value['price']) || floatval($value['price']) != $value['price'])
|
||||
return self::setErrorInfo('请填写正确的商品价格');
|
||||
if(!isset($value['sales']) || !is_numeric($value['sales']) || intval($value['sales']) != $value['sales'])
|
||||
return self::setErrorInfo('请填写正确的商品库存');
|
||||
if(!isset($value['pic']) || empty($value['pic']))
|
||||
return self::setErrorInfo('请上传商品图片');
|
||||
foreach ($value['detail'] as $attrName=>$attrValue){
|
||||
$attrName = trim($attrName);
|
||||
$attrValue = trim($attrValue);
|
||||
if(!in_array($attrName,$attrNameList,true)) return self::setErrorInfo($attrName.'规则不存在');
|
||||
if(!in_array($attrValue,$attrValueList,true)) return self::setErrorInfo($attrName.'属性不存在');
|
||||
if(empty($attrName)) return self::setErrorInfo('请输入正确的属性');
|
||||
$value['detail'][$attrName] = $attrValue;
|
||||
}
|
||||
$valueList[$index] = $value;
|
||||
}
|
||||
$attrGroup = [];
|
||||
$valueGroup = [];
|
||||
foreach ($attrList as $k=>$value){
|
||||
$attrGroup[] = [
|
||||
'product_id'=>$productId,
|
||||
'attr_name'=>$value['value'],
|
||||
'attr_values'=>$value['detail']
|
||||
];
|
||||
}
|
||||
foreach ($valueList as $k=>$value){
|
||||
ksort($value['detail'],SORT_STRING);
|
||||
$suk = implode(',',$value['detail']);
|
||||
$valueGroup[$suk] = [
|
||||
'product_id'=>$productId,
|
||||
'suk'=>$suk,
|
||||
'price'=>$value['price'],
|
||||
'stock'=>$value['sales'],
|
||||
'image'=>$value['pic']
|
||||
];
|
||||
}
|
||||
if(!count($attrGroup) || !count($valueGroup)) return self::setErrorInfo('请设置至少一个属性!');
|
||||
$attrModel = new self;
|
||||
$attrValueModel = new StoreSeckillAttrValue;
|
||||
self::beginTrans();
|
||||
if(!self::clearProductAttr($productId)) return false;
|
||||
$res = false !== $attrModel->saveAll($attrGroup)
|
||||
&& false !== $attrValueModel->saveAll($valueGroup)
|
||||
&& false !== StoreSeckillAttrResult::setResult($result,$productId);
|
||||
self::checkTrans($res);
|
||||
if($res)
|
||||
return true;
|
||||
else
|
||||
return self::setErrorInfo('编辑商品属性失败!');
|
||||
}
|
||||
|
||||
public static function clearProductAttr($productId)
|
||||
{
|
||||
if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
|
||||
$res = false !== self::where('product_id',$productId)->delete()
|
||||
&& false !== StoreSeckillAttrValue::clearProductAttrValue($productId);
|
||||
if(!$res)
|
||||
return self::setErrorInfo('编辑属性失败,清除旧属性失败!');
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
47
application/admin/model/ump/StoreSeckillAttrResult.php
Normal file
47
application/admin/model/ump/StoreSeckillAttrResult.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/09
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreSeckillAttrResult extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['change_time'];
|
||||
|
||||
protected static function setChangeTimeAttr($value)
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
protected static function setResultAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
|
||||
public static function setResult($result,$product_id)
|
||||
{
|
||||
$result = self::setResultAttr($result);
|
||||
$change_time = self::setChangeTimeAttr(0);
|
||||
return self::insert(compact('product_id','result','change_time'),true);
|
||||
}
|
||||
|
||||
public static function getResult($productId)
|
||||
{
|
||||
return json_decode(self::where('product_id',$productId)->value('result'),true) ?: [];
|
||||
}
|
||||
|
||||
public static function clearResult($productId)
|
||||
{
|
||||
return self::del($productId);
|
||||
}
|
||||
|
||||
}
|
||||
49
application/admin/model/ump/StoreSeckillAttrValue.php
Normal file
49
application/admin/model/ump/StoreSeckillAttrValue.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\ump;
|
||||
|
||||
|
||||
use basic\ModelBasic;
|
||||
use traits\ModelTrait;
|
||||
|
||||
class StoreSeckillAttrValue extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['unique'];
|
||||
|
||||
protected function setSukAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function setUniqueAttr($value,$data)
|
||||
{
|
||||
if(is_array($data['suk'])) $data['suk'] = $this->setSukAttr($data['suk']);
|
||||
return self::uniqueId($data['product_id'].$data['suk'].uniqid(true));
|
||||
}
|
||||
|
||||
public static function decProductAttrStock($productId,$unique,$num)
|
||||
{
|
||||
return false !== self::where('product_id',$productId)->where('unique',$unique)
|
||||
->dec('stock',$num)->inc('sales',$num)->update();
|
||||
}
|
||||
|
||||
|
||||
public static function uniqueId($key)
|
||||
{
|
||||
return substr(md5($key),12,8);
|
||||
}
|
||||
|
||||
public static function clearProductAttrValue($productId)
|
||||
{
|
||||
return self::where('product_id',$productId)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
1
application/admin/model/user/User.php
Normal file
1
application/admin/model/user/User.php
Normal file
File diff suppressed because one or more lines are too long
276
application/admin/model/user/UserBill.php
Normal file
276
application/admin/model/user/UserBill.php
Normal file
@ -0,0 +1,276 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model\user;
|
||||
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
|
||||
/**
|
||||
* 用户消费新增金额明细 model
|
||||
* Class User
|
||||
* @package app\admin\model\user
|
||||
*/
|
||||
|
||||
class UserBill extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
public static function income($title,$uid,$category,$type,$number,$link_id = 0,$balance = 0,$mark = '',$status = 1){
|
||||
$pm = 1;
|
||||
return self::set(compact('title','uid','link_id','category','type','number','balance','mark','status','pm'));
|
||||
}
|
||||
|
||||
//获取柱状图和饼状图数据
|
||||
public static function getUserBillChart($where,$category='now_money',$type='brokerage',$pm=1,$zoom=15){
|
||||
$model=self::getModelTime($where,new self());
|
||||
$list=$model->field(['FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time','sum(number) as sum_number'])
|
||||
->order('un_time asc')
|
||||
->where(['category'=>$category,'type'=>$type,'pm'=>$pm])
|
||||
->group('un_time')
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$legdata=[];
|
||||
$listdata=[];
|
||||
$dataZoom='';
|
||||
foreach ($list as $item){
|
||||
$legdata[]=$item['un_time'];
|
||||
$listdata[]=$item['sum_number'];
|
||||
}
|
||||
if(count($legdata)>=$zoom) $dataZoom=$legdata[$zoom-1];
|
||||
//获取用户分布钱数
|
||||
$fenbulist=self::getModelTime($where,new self(),'a.add_time')
|
||||
->alias('a')
|
||||
->join('user r','a.uid=r.uid')
|
||||
->field(['a.uid','sum(a.number) as sum_number','r.nickname'])
|
||||
->where(['a.category'=>$category,'a.type'=>$type,'a.pm'=>$pm])
|
||||
->order('sum_number desc')
|
||||
->group('a.uid')
|
||||
->limit(8)
|
||||
->select();
|
||||
//获取用户当前时间段总钱数
|
||||
$sum_number=self::getModelTime($where,new self())
|
||||
->where(['category'=>$category,'type'=>$type,'pm'=>$pm])
|
||||
->sum('number');
|
||||
if(count($fenbulist)) $fenbulist=$fenbulist->toArray();
|
||||
$fenbudate=[];
|
||||
$fenbu_legend=[];
|
||||
$color=['#ffcccc','#99cc00','#fd99cc','#669966','#66CDAA','#ADFF2F','#00BFFF','#00CED1','#66cccc','#ff9900','#ffcc00','#336699','#cccc00','#99ccff','#990066'];
|
||||
foreach ($fenbulist as $key=>$value){
|
||||
$fenbu_legend[]=$value['nickname'];
|
||||
$items['name']=$value['nickname'];
|
||||
$items['value']=bcdiv($value['sum_number'],$sum_number,2)*100;
|
||||
$items['itemStyle']['color']=$color[$key];
|
||||
$fenbudate[]=$items;
|
||||
}
|
||||
return compact('legdata','listdata','fenbudate','fenbu_legend','dataZoom');
|
||||
}
|
||||
//获取头部信息
|
||||
public static function getRebateBadge($where){
|
||||
$datawhere=['category'=>'now_money','type'=>'brokerage','pm'=>1];
|
||||
return [
|
||||
[
|
||||
'name'=>'返利数(笔)',
|
||||
'field'=>'个',
|
||||
'count'=>self::getModelTime($where,new self())->where($datawhere)->count(),
|
||||
'content'=>'返利总笔数',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>self::where($datawhere)->count(),
|
||||
'class'=>'fa fa-bar-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'返利金额(元)',
|
||||
'field'=>'个',
|
||||
'count'=>self::getModelTime($where,new self())->where($datawhere)->sum('number'),
|
||||
'content'=>'返利总金额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::where($datawhere)->sum('number'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
];
|
||||
}
|
||||
//获取返佣用户信息列表
|
||||
public static function getFanList($where){
|
||||
$datawhere=['a.category'=>'now_money','a.type'=>'brokerage','a.pm'=>1];
|
||||
$list=self::alias('a')->join('user r','a.uid=r.uid')
|
||||
->where($datawhere)
|
||||
->order('a.number desc')
|
||||
->join('store_order o','o.id=a.link_id')
|
||||
->field(['o.order_id','FROM_UNIXTIME(a.add_time,"%Y-%c-%d") as add_time','a.uid','o.uid as down_uid','r.nickname','r.avatar','r.spread_uid','r.level','a.number'])
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
return $list;
|
||||
}
|
||||
//获取返佣用户总人数
|
||||
public static function getFanCount(){
|
||||
$datawhere=['a.category'=>'now_money','a.type'=>'brokerage','a.pm'=>1];
|
||||
return self::alias('a')->join('user r','a.uid=r.uid')->join('store_order o','o.id=a.link_id')->where($datawhere)->count();
|
||||
}
|
||||
//获取用户充值数据
|
||||
public static function getEchartsRecharge($where,$limit=15){
|
||||
$datawhere=['category'=>'now_money','pm'=>1];
|
||||
$list=self::getModelTime($where,self::where($datawhere)->where('type','in',['recharge','system_add']))
|
||||
->field(['sum(number) as sum_money','FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time','count(id) as count'])
|
||||
->group('un_time')
|
||||
->order('un_time asc')
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$sum_count=self::getModelTime($where,self::where($datawhere)->where('type','in',['recharge','system_add']))->count();
|
||||
$xdata=[];
|
||||
$seriesdata=[];
|
||||
$data=[];
|
||||
$zoom='';
|
||||
foreach ($list as $value){
|
||||
$xdata[]=$value['un_time'];
|
||||
$seriesdata[]=$value['sum_money'];
|
||||
$data[]=$value['count'];
|
||||
}
|
||||
if(count($xdata)>$limit){
|
||||
$zoom=$xdata[$limit-5];
|
||||
}
|
||||
return compact('xdata','seriesdata','data','zoom');
|
||||
}
|
||||
//获取佣金提现列表
|
||||
public static function getExtrctOneList($where,$uid){
|
||||
$list=self::setOneWhere($where,$uid)
|
||||
->field(['number','link_id','mark','FROM_UNIXTIME(add_time,"%Y-%m-%d %H:%i:%s") as _add_time','status'])
|
||||
->select();
|
||||
count($list) && $list=$list->toArray();
|
||||
$count=self::setOneWhere($where,$uid)->count();
|
||||
foreach ($list as &$value){
|
||||
$value['order_id']=db('store_order')->where(['order_id'=>$value['link_id']])->value('order_id');
|
||||
}
|
||||
return ['data'=>$list,'count'=>$count];
|
||||
}
|
||||
//设置单个用户查询
|
||||
public static function setOneWhere($where,$uid){
|
||||
$model=self::where(['uid'=>$uid,'category'=>'now_money','type'=>'brokerage']);
|
||||
$time['data']='';
|
||||
if($where['start_time']!='' && $where['end_time']!=''){
|
||||
$time['data']=$where['start_time'].' - '.$where['end_time'];
|
||||
$model=self::getModelTime($time,$model);
|
||||
}
|
||||
if($where['nickname']!=''){
|
||||
$model=$model->where('link_id|mark','like',"%$where[nickname]%");
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
//查询积分个人明细
|
||||
public static function getOneIntegralList($where){
|
||||
return self::setWhereList(
|
||||
$where,
|
||||
['deduction','system_add'],
|
||||
['title','number','balance','mark','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']
|
||||
);
|
||||
}
|
||||
//查询个人签到明细
|
||||
public static function getOneSignList($where){
|
||||
return self::setWhereList(
|
||||
$where,'sign',
|
||||
['title','number','mark','FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time']
|
||||
);
|
||||
}
|
||||
//查询个人余额变动记录
|
||||
public static function getOneBalanceChangList($where){
|
||||
$list=self::setWhereList(
|
||||
$where,
|
||||
['system_add','pay_product','extract','pay_product_refund','system_sub'],
|
||||
['FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time','title','type','mark','number','balance','pm','status'],
|
||||
'now_money'
|
||||
);
|
||||
foreach ($list as &$item){
|
||||
switch ($item['type']){
|
||||
case 'system_add':
|
||||
$item['_type']='系统添加';
|
||||
break;
|
||||
case 'pay_product':
|
||||
$item['_type']='商品购买';
|
||||
break;
|
||||
case 'extract':
|
||||
$item['_type']='提现';
|
||||
break;
|
||||
case 'pay_product_refund':
|
||||
$item['_type']='退款';
|
||||
break;
|
||||
case 'system_sub':
|
||||
$item['_type']='系统减少';
|
||||
break;
|
||||
}
|
||||
$item['_pm']=$item['pm']==1 ? '获得': '支出';
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
//设置where条件分页.返回数据
|
||||
public static function setWhereList($where,$type='',$field=[],$category='integral'){
|
||||
$models=self::where('uid',$where['uid'])
|
||||
->where('category',$category)
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->field($field);
|
||||
if(is_array($type)){
|
||||
$models=$models->where('type','in',$type);
|
||||
}else{
|
||||
$models=$models->where('type',$type);
|
||||
}
|
||||
return ($list=$models->select()) && count($list) ? $list->toArray():[];
|
||||
}
|
||||
//获取积分统计头部信息
|
||||
public static function getScoreBadgeList($where){
|
||||
return [
|
||||
[
|
||||
'name'=>'总积分',
|
||||
'field'=>'个',
|
||||
'count'=>self::getModelTime($where,new self())->where('category','integral')->where('type','in',['gain','system_sub','deduction','sign'])->sum('number'),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>4,
|
||||
],
|
||||
[
|
||||
'name'=>'已使用积分',
|
||||
'field'=>'个',
|
||||
'count'=>self::getModelTime($where,new self())->where('category','integral')->where('type','deduction')->sum('number'),
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'col'=>4,
|
||||
],
|
||||
[
|
||||
'name'=>'未使用积分',
|
||||
'field'=>'个',
|
||||
'count'=>self::getModelTime($where,db('user'))->sum('integral'),
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'col'=>4,
|
||||
],
|
||||
];
|
||||
}
|
||||
//获取积分统计曲线图和柱状图
|
||||
public static function getScoreCurve($where){
|
||||
//发放积分趋势图
|
||||
$list=self::getModelTime($where,self::where('category','integral')
|
||||
->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(number) as sum_number'])
|
||||
->group('_add_time')->order('_add_time asc'))->select()->toArray();
|
||||
$date=[];
|
||||
$zoom='';
|
||||
$seriesdata=[];
|
||||
foreach ($list as $item){
|
||||
$date[]=$item['_add_time'];
|
||||
$seriesdata[]=$item['sum_number'];
|
||||
}
|
||||
unset($item);
|
||||
if(count($date)>$where['limit']){
|
||||
$zoom=$date[$where['limit']-5];
|
||||
}
|
||||
//使用积分趋势图
|
||||
$deductionlist=self::getModelTime($where,self::where('category','integral')->where('type','deduction')
|
||||
->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(number) as sum_number'])
|
||||
->group('_add_time')->order('_add_time asc'))->select()->toArray();
|
||||
$deduction_date=[];
|
||||
$deduction_zoom='';
|
||||
$deduction_seriesdata=[];
|
||||
foreach ($deductionlist as $item){
|
||||
$deduction_date[]=$item['_add_time'];
|
||||
$deduction_seriesdata[]=$item['sum_number'];
|
||||
}
|
||||
if(count($deductionlist)>$where['limit']){
|
||||
$deduction_zoom=$deductionlist[$where['limit']-5];
|
||||
}
|
||||
return compact('date','seriesdata','zoom','deduction_date','deduction_zoom','deduction_seriesdata');
|
||||
}
|
||||
}
|
||||
262
application/admin/model/user/UserExtract.php
Normal file
262
application/admin/model/user/UserExtract.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lianghuan
|
||||
* Date: 2018-03-03
|
||||
* Time: 16:47
|
||||
*/
|
||||
|
||||
namespace app\admin\model\user;
|
||||
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use think\Url;
|
||||
use traits\ModelTrait;
|
||||
use basic\ModelBasic;
|
||||
use service\WechatTemplateService;
|
||||
/**
|
||||
* 用户提现管理 model
|
||||
* Class User
|
||||
* @package app\admin\model\user
|
||||
*/
|
||||
class UserExtract extends ModelBasic
|
||||
{
|
||||
use ModelTrait;
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where)
|
||||
{
|
||||
$model = new self;
|
||||
if($where['status'] != '') $model = $model->where('a.status',$where['status']);
|
||||
if($where['extract_type'] != '') $model = $model->where('a.extract_type',$where['extract_type']);
|
||||
if($where['nireid'] != '') $model = $model->where('a.real_name|a.id|b.nickname|a.bank_code|a.alipay_code','like',"%$where[nireid]%");
|
||||
$model = $model->alias('a');
|
||||
$model = $model->field('a.*,b.nickname');
|
||||
$model = $model->join('__USER__ b','b.uid=a.uid','LEFT');
|
||||
$model = $model->order('a.id desc');
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
public static function changeFail($id,$fail_msg)
|
||||
{
|
||||
$fail_time = time();
|
||||
$data =self::get($id);
|
||||
$extract_number=$data['extract_price'];
|
||||
$mark='提现失败,退回佣金'.$extract_number.'元';
|
||||
$uid=$data['uid'];
|
||||
$status = -1;
|
||||
$User= User::find(['uid'=>$uid])->toArray();
|
||||
UserBill::income('提现失败',$uid,'now_money','extract',$extract_number,$id,$User['now_money'],$mark);
|
||||
|
||||
User::bcInc($uid,'now_money',$extract_number,'uid');
|
||||
WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid),WechatTemplateService::USER_BALANCE_CHANGE,[
|
||||
'first'=> $mark,
|
||||
'keyword1'=>'佣金提现',
|
||||
'keyword2'=>date('Y-m-d H:i:s',time()),
|
||||
'keyword3'=>$extract_number,
|
||||
'remark'=>'错误原因:'.$fail_msg
|
||||
],Url::build('wap/my/user_pro',[],true,true));
|
||||
return self::edit(compact('fail_time','fail_msg','status'),$id);
|
||||
}
|
||||
|
||||
public static function changeSuccess($id)
|
||||
{
|
||||
$status = 1;
|
||||
$data =self::get($id);
|
||||
$extract_number=$data['extract_price'];
|
||||
$mark='成功提现佣金'.$extract_number.'元';
|
||||
$uid=$data['uid'];
|
||||
WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid),WechatTemplateService::USER_BALANCE_CHANGE,[
|
||||
'first'=> $mark,
|
||||
'keyword1'=>'佣金提现',
|
||||
'keyword2'=>date('Y-m-d H:i:s',time()),
|
||||
'keyword3'=>$extract_number,
|
||||
'remark'=>'点击查看我的佣金明细'
|
||||
],Url::build('wap/my/user_pro',[],true,true));
|
||||
return self::edit(compact('status'),$id);
|
||||
}
|
||||
//测试数据
|
||||
public static function test(){
|
||||
$uids=User::order('uid desc')->limit(2,20)->field(['uid','nickname'])->select()->toArray();
|
||||
$type=['bank','alipay','weixin'];
|
||||
foreach ($uids as $item){
|
||||
$data=[
|
||||
'uid'=>$item['uid'],
|
||||
'real_name'=>$item['nickname'],
|
||||
'extract_type'=>isset($type[rand(0,2)]) ? $type[rand(0,2)] :'alipay',
|
||||
'bank_code'=>rand(1000000,999999999),
|
||||
'bank_address'=>'中国',
|
||||
'alipay_code'=>rand(1000,9999999),
|
||||
'extract_price'=>rand(100,9999),
|
||||
'mark'=>'测试数据',
|
||||
'add_time'=>time(),
|
||||
'status'=>1,
|
||||
'wechat'=>rand(999,878788).$item['uid'],
|
||||
];
|
||||
self::set($data);
|
||||
}
|
||||
}
|
||||
//获取头部提现信息
|
||||
public static function getExtractHead(){
|
||||
//本月提现人数
|
||||
$month=self::getModelTime(['data'=>'month'],self::where(['status'=>1]))->group('uid')->count();
|
||||
//本月提现笔数
|
||||
$new_month=self::getModelTime(['data'=>'month'],self::where(['status'=>1]))->distinct(true)->count();
|
||||
//上月提现人数
|
||||
$last_month=self::whereTime('add_time','last month')->where('status',1)->group('uid')->distinct(true)->count();
|
||||
//上月提现笔数
|
||||
$last_count=self::whereTime('add_time','last month')->where('status',1)->count();
|
||||
//本月提现金额
|
||||
$extract_price=self::getModelTime(['data'=>'month'],self::where(['status'=>1]))->sum('extract_price');
|
||||
//上月提现金额
|
||||
$last_extract_price=self::whereTime('add_time','last month')->where('status',1)->sum('extract_price');
|
||||
|
||||
return [
|
||||
[
|
||||
'name'=>'总提现人数',
|
||||
'field'=>'个',
|
||||
'count'=>self::where(['status'=>1])->group('uid')->count(),
|
||||
'content'=>'',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>'',
|
||||
'class'=>'fa fa-bar-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'总提现笔数',
|
||||
'field'=>'笔',
|
||||
'count'=>self::where(['status'=>1])->distinct(true)->count(),
|
||||
'content'=>'',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>'',
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'本月提现人数',
|
||||
'field'=>'人',
|
||||
'count'=>$month,
|
||||
'content'=>'',
|
||||
'background_color'=>'layui-bg-orange',
|
||||
'sum'=>'',
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'本月提现笔数',
|
||||
'field'=>'笔',
|
||||
'count'=>$new_month,
|
||||
'content'=>'',
|
||||
'background_color'=>'layui-bg-green',
|
||||
'sum'=>'',
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'本月提现金额',
|
||||
'field'=>'元',
|
||||
'count'=>$extract_price,
|
||||
'content'=>'提现总金额',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::where(['status'=>1])->sum('extract_price'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'上月提现人数',
|
||||
'field'=>'个',
|
||||
'count'=>$last_month,
|
||||
'content'=>'环比增幅',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>$last_month==0 ? '100%' :bcdiv($month,$last_month,2)*100,
|
||||
'class'=>$last_month==0 ? 'fa fa-level-up':'fa fa-level-down',
|
||||
],
|
||||
[
|
||||
'name'=>'上月提现笔数',
|
||||
'field'=>'笔',
|
||||
'count'=>$last_count,
|
||||
'content'=>'环比增幅',
|
||||
'background_color'=>'layui-bg-black',
|
||||
'sum'=>$last_count==0 ? '100%':bcdiv($new_month,$last_count,2)*100,
|
||||
'class'=>$last_count==0 ? 'fa fa-level-up':'fa fa-level-down',
|
||||
],
|
||||
[
|
||||
'name'=>'上月提现金额',
|
||||
'field'=>'元',
|
||||
'count'=>$last_extract_price,
|
||||
'content'=>'环比增幅',
|
||||
'background_color'=>'layui-bg-gray',
|
||||
'sum'=>$last_extract_price==0 ? '100%':bcdiv($extract_price,$last_extract_price,2)*100,
|
||||
'class'=>$last_extract_price==0 ? 'fa fa-level-up':'fa fa-level-down',
|
||||
],
|
||||
];
|
||||
}
|
||||
//获取提现分布图和提现人数金额曲线图
|
||||
public static function getExtractList($where,$limit=15){
|
||||
$legdata=['提现人数','提现金额'];
|
||||
$list=self::getModelTime($where,self::where('status',1))
|
||||
->field([
|
||||
'FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time',
|
||||
'count(uid) as count',
|
||||
'sum(extract_price) as sum_price',
|
||||
])->group('un_time')->order('un_time asc')->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$xdata=[];
|
||||
$itemList=[0=>[],1=>[]];
|
||||
$chatrList=[];
|
||||
$zoom='';
|
||||
foreach ($list as $value){
|
||||
$xdata[]=$value['un_time'];
|
||||
$itemList[0][]=$value['count'];
|
||||
$itemList[1][]=$value['sum_price'];
|
||||
}
|
||||
foreach ($legdata as $key=>$name){
|
||||
$item['name']=$name;
|
||||
$item['type']='line';
|
||||
$item['data']=$itemList[$key];
|
||||
$chatrList[]=$item;
|
||||
}
|
||||
unset($item,$name,$key);
|
||||
if(count($xdata)>$limit) $zoom=$xdata[$limit-5];
|
||||
//饼状图
|
||||
$cake=['支付宝','银行卡','微信'];
|
||||
$fenbulist=self::getModelTime($where,self::where('status',1))
|
||||
->field(['count(uid) as count','extract_type'])->group('extract_type')->order('count asc')->select();
|
||||
if(count($fenbulist)) $fenbulist=$fenbulist->toArray();
|
||||
$sum_count=self::getModelTime($where,self::where('status',1))->count();
|
||||
$color=['#FB7773','#81BCFE','#91F3FE'];
|
||||
$fenbudata=[];
|
||||
foreach ($fenbulist as $key=>$item){
|
||||
if($item['extract_type']=='bank'){
|
||||
$item_date['name']='银行卡';
|
||||
}else if($item['extract_type']=='alipay'){
|
||||
$item_date['name']='支付宝';
|
||||
}else if($item['extract_type']=='weixin'){
|
||||
$item_date['name']='微信';
|
||||
}
|
||||
$item_date['value']=bcdiv($item['count'],$sum_count,2)*100;
|
||||
$item_date['itemStyle']['color']=$color[$key];
|
||||
$fenbudata[]=$item_date;
|
||||
}
|
||||
return compact('xdata','chatrList','legdata','zoom','cake','fenbudata');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户累计提现金额
|
||||
* @param int $uid
|
||||
* @return int|mixed
|
||||
*/
|
||||
public static function getUserCountPrice($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
$price = self::where('uid',$uid)->where('status',1)->field('sum(extract_price) as price')->find()['price'];
|
||||
return $price ? $price : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户累计提现次数
|
||||
* @param int $uid
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getUserCountNum($uid = 0){
|
||||
if(!$uid) return 0;
|
||||
return self::where('uid',$uid)->count();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user