liufumingren e8605149c0 初始化
2026-08-06 17:04:35 +08:00

249 lines
12 KiB
PHP

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Config;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['init','appver','appver2','richtext','appver3','appver4'];
protected $noNeedRight = ['init','appver','pages','appver2','works','richtext','appver3','appver4','upload_cos_params','upload_cos_notify'];
/**
* 首页
*
*/
public function index(){
$params=$this->request->post();
$WAREHOUSEID = $params['WAREHOUSEID'];
$orderModel = new \app\common\model\wms\Order;
try {
$where = 'POSTNUM=\'\'';
$dfp = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PRINTTIMES=0 and POSTFLAG=1';
$ddy = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PRINTTIMES=1 and OPERATERECORDS not like \'%领料%\'';
$dll = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PICKINGFLAG=0 and OPERATERECORDS like \'%领料%\'';
$djh = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PICKINGFLAG=3 and PLSENDFLAG=0';
$dfh = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PLSENDFLAG=1 and WEIGHT = \'\'';
$dcz = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PLSENDFLAG=1 and OPERATERECORDS not like \'%打包%\'';
$ddb = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = '';
$yjd = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'POSTFLAG=1';
$yfp = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PRINTTIMES=1';
$ydy = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'OPERATERECORDS like \'%领料%\' or PICKINGFLAG=3';
$yll = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PICKINGFLAG=3';
$yjh = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'PLSENDFLAG=1';
$yfh = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'WEIGHT <> \'\'';
$ycz = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'OPERATERECORDS like \'%打包%\'';
$ydb = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$where = 'FLAG=1';
$ylj = $orderModel->where($where)->where('cast(CREATIONDATE as signed) >= '.strtotime(date("Y-m-d",strtotime("-30 day")))*1000)->where(['WAREHOUSEID'=>$WAREHOUSEID])->count();
$this->success('获取成功',['dfp'=>$dfp,'ddy'=>$ddy,'dll'=>$dll,'djh'=>$djh,'dfh'=>$dfh,'dcz'=>$dcz,'ddb'=>$ddb,'yjd'=>$yjd,'yfp'=>$yfp,'ydy'=>$ydy,'yll'=>$yll,'yjh'=>$yjh,'yfh'=>$yfh,'ydb'=>$ydb,'ycz'=>$ycz,'ylj'=>$ylj]);
} catch (Exception $e) {
$this->error($e);
}
}
public function init()
{
$platform = $this->request->header('platform'); // 获取平台标识
$appid = $this->request->get('appid');
if (!in_array($platform, ['H5', 'App', 'wxMiniProgram', 'wxOfficialAccount'])) {
$this->error('请使用正确客户端访问');
}
$data = []; // 设置信息
$configFields = ['shopro', 'share', 'chat', 'store', $platform]; // 定义设置字段
$configModel = new \addons\shopro\model\Config;
$config = $configModel->where('name', 'in', $configFields)->column('value', 'name');
// 商城基本设置
$shoproConfig = json_decode($config['shopro'], true);
$shoproConfig['logo'] = cdnurl($shoproConfig['logo'], true);
$data['shop'] = $shoproConfig;
// 支付设置
$payment = $configModel->where('group', 'payment')->select();
$paymentConfig = [];
foreach ($payment as $key => $v) {
$val = json_decode($v->value, true);
if ($val && in_array($platform, $val['platform'])) {
$paymentConfig[] = $v->name;
}
}
$data['payment'] = $paymentConfig; // 平台支持的支付方式
// 平台设置
$platformConfig = json_decode($config[$platform], true);
if (in_array($platform, ['wxOfficialAccount', 'wxMiniProgram'])) {
if (isset($platformConfig['auto_login']) && $platformConfig['auto_login'] == 1) {
$autologin = true;
} else {
$autologin = false;
}
$data['wechat'] = [
'appid' => isset($appid) ? $appid : '',
'autologin' => $autologin,
];
}
// 分享设置
$shareConfig = json_decode($config['share'], true);
$data['share'] = [
'title' => $shareConfig['title'],
'image' => isset($shareConfig['image']) ? cdnurl($shareConfig['image'], true) : '',
'goods_poster_bg' => isset($shareConfig['goods_poster_bg']) ? cdnurl($shareConfig['goods_poster_bg'], true) : '',
'user_poster_bg' => isset($shareConfig['user_poster_bg']) ? cdnurl($shareConfig['user_poster_bg'], true) : '',
'groupon_poster_bg' => isset($shareConfig['groupon_poster_bg']) ? cdnurl($shareConfig['groupon_poster_bg'], true) : '',
];
// 插件设置
$data['addons'] = array_keys(get_addon_list());
// 客服设置
$data['chat'] = isset($config['chat']) ? json_decode($config['chat'], true) : [];
// 门店配置
$data['store'] = isset($config['store']) ? json_decode($config['store'], true) : [];
$this->success('初始化数据', $data);
}
public function gztappver(){
$data = array(
"ver"=>Config::get('site.appversion'),
"aApkUrl"=>Config::get('site.aApkUrl'),
"updateDescription"=>Config::get('site.updateDescription'),
"isForce"=>Config::get('site.isForce')
);
$this->success('版本信息',$data);
}
public function appver2(){
$data = array(
"ver"=>Config::get('site.appversion2'),
"aApkUrl"=>Config::get('site.cdn').Config::get('site.apk'),
"updateDescription"=>Config::get('site.updateDescription'),
"isForce"=>Config::get('site.isForce')
);
$this->success('版本信息',$data);
}
public function appver4(){
$data = array(
"ver"=>Config::get('site.appversion'),
"aApkUrl"=>Config::get('site.cdn').Config::get('site.apk1'),
"updateDescription"=>Config::get('site.updateDescription'),
"isForce"=>Config::get('site.isForce')
);
$this->success('版本信息',$data);
}
public function appver3(){
$data = array(
"ver"=>Config::get('site.appversion3'),
"aApkUrl"=>Config::get('site.cdn').Config::get('site.apk3'),
"updateDescription"=>Config::get('site.updateDescription3'),
"isForce"=>Config::get('site.isForce3')
);
$this->success('版本信息',$data);
}
public function appver(){
$data = array(
"ver"=>Config::get('site.appversion'),
"aApkUrl"=>Config::get('site.apk1'),
"updateDescription"=>Config::get('site.updateDescription'),
"isForce"=>Config::get('site.isForce')
);
$this->success('版本信息',$data);
}
public function pages(){
$model = model('UserGroup');
$row = $model->get($this->auth->group_id);
if (!$row) {
$this->error(__('No Results were found'));
}
$rules = explode(',', $row['rules']);
$nodeList = \app\admin\model\UserRule::getTreeList($rules,2,"remark");
$this->success('获取成功',$nodeList);
}
public function works(){
$model = model('UserGroup');
$row = $model->get($this->auth->group_id);
if (!$row) {
$this->error(__('No Results were found'));
}
$rules = explode(',', $row['rules']);
$nodeList = \app\admin\model\UserRule::getTreeList($rules,4,"remark");
$this->success('获取成功',$nodeList);
}
public function richtext(){
$id = $this->request->get('id');
$data = \addons\shopro\model\Richtext::get(['id' => $id]);
$this->success($data->title, $data);
}
public function upload_cos_params(){
$params = $this->request->post();
$cosController = new \addons\cos\controller\Index;
[$name,$type] = $this->getFileInfoFromPath($params['path']);
$upload = Config::get("upload");
$result = $cosController->paramsApi($params['md5'],$name,$type,$params['size'],$upload['chunking'],$upload['chunksize'],$upload['multipart']['costoken']);
$this->success("1", ["params"=>$result,"costoken"=>$upload['multipart']['costoken'],"type"=>$type,"name"=>$name]);
}
public function upload_cos_notify(){
$uid = $this->auth->id;
$params = $this->request->post();
$cosController = new \addons\cos\controller\Index;
$result = $cosController->noticeApi($params['size'],$params['name'],$params['md5'],$params['type'],"/".$params['url'],$params['width'],$params['height'],$params['category'],$params['costoken'],$uid);
$this->success("1", $result);
}
private function getFileInfoFromPath($path) {
// 获取文件名
$pathInfo = pathinfo($path);
$name = $pathInfo['basename'];
// 根据扩展名推断文件类型
$extension = strtolower($pathInfo['extension'] ?? '');
$typeMap = [
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'webp' => 'image/webp',
'pdf' => 'application/pdf',
'doc' => 'application/msword',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xls' => 'application/vnd.ms-excel',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'txt' => 'text/plain',
'mp3' => 'audio/mpeg',
'mp4' => 'video/mp4',
'zip' => 'application/zip',
];
$type = $typeMap[$extension] ?? 'application/octet-stream';
return [
$name,
$type
];
}
}