初始化项目
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Account as AccountModel;
|
||||
use app\store\model\store\User;
|
||||
|
||||
/**
|
||||
* 公司用户控制器
|
||||
* Class Account
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Account extends Controller
|
||||
{
|
||||
/**
|
||||
* 公司列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new AccountModel();
|
||||
$getData = $this->request->param();
|
||||
$user = $this->store['user'];
|
||||
if($user['is_super'] == 0) {
|
||||
$getData['store_user_id'] = User::getScope($user);
|
||||
}
|
||||
/*if(!empty($this->store['user']['company_id']) && $this->store['user']['is_super'] == 0){
|
||||
$filter[] = ['company_id', 'in', json_decode($this->store['user']['company_id'],true)];
|
||||
}*/
|
||||
$list = $model->getList($getData);
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Article as ArticleModel;
|
||||
|
||||
/**
|
||||
* 文章模型
|
||||
* Class Article
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Article extends ArticleModel
|
||||
{
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'title' => '', // 文章标题
|
||||
'categoryId' => 0, // 文章分类id
|
||||
'status' => -1, // 文章状态
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 文章标题
|
||||
!empty($params['title']) && $filter[] = ['title', 'like', "%{$params['title']}%"];
|
||||
// 文章分类id
|
||||
$params['categoryId'] > 0 && $filter[] = ['category_id', '=', $params['categoryId']];
|
||||
// 文章状态
|
||||
$params['status'] > -1 && $filter[] = ['status', '=', $params['status']];
|
||||
// 查询列表数据
|
||||
return $this->with(['image', 'category'])
|
||||
->withoutField(['content'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort' => 'asc', 'create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
if (empty($data['image_id'])) {
|
||||
$this->error = '请上传封面图';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['content'])) {
|
||||
$this->error = '请输入文章内容';
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
if (empty($data['image_id'])) {
|
||||
$this->error = '请上传封面图';
|
||||
return false;
|
||||
}
|
||||
if (empty($data['content'])) {
|
||||
$this->error = '请输入文章内容';
|
||||
return false;
|
||||
}
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文章总数量
|
||||
* @param array $where
|
||||
* @return int|string
|
||||
*/
|
||||
public static function getArticleTotal(array $where = [])
|
||||
{
|
||||
return (new static)->where($where)->where('is_delete', '=', 0)->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\store\User;
|
||||
use app\store\model\Bank as BankModel;
|
||||
|
||||
/**
|
||||
* 物流公司管理控制器
|
||||
* Class Goods
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Bank extends Controller
|
||||
{
|
||||
/**
|
||||
* 银行账户列表
|
||||
* @param null $status
|
||||
* @param string $search_name
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index($status = null, $search_name = '')
|
||||
{
|
||||
// 银行账户列表
|
||||
$model = new BankModel;
|
||||
$list = $model->getList($status, $search_name, 'all',false,15,$this->powerScope());
|
||||
return $this->fetch('index', compact('list'));
|
||||
}
|
||||
/**
|
||||
* 添加账户列表
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!$this->request->isAjax()) {
|
||||
// 人员列表
|
||||
$admin = User::getAll();
|
||||
$user = $this->getUserInfo();
|
||||
return $this->fetch('add',compact('admin','user'));
|
||||
}
|
||||
$model = new BankModel;
|
||||
$bank_id = $model->add($this->postData('bank'));
|
||||
if ($bank_id !== false) {
|
||||
if($this->postData('bank')['status'] == 1) {
|
||||
$BankModel = new BankModel;
|
||||
$BankModel->setOtherStatus($bank_id,$this->postData('bank')['store_user_id']);
|
||||
}
|
||||
return $this->renderSuccess('添加成功', url('bank/index'));
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改账户列表状态
|
||||
* @param $bank_id
|
||||
* @param boolean $status
|
||||
* @return array
|
||||
*/
|
||||
public function state($bank_id, $status)
|
||||
{
|
||||
// 商品详情
|
||||
$model = BankModel::detail($bank_id);
|
||||
if (!$model->setStatus($status)) {
|
||||
return $this->renderError('操作失败');
|
||||
}
|
||||
if($status == 1) {
|
||||
$BankModel = new BankModel;
|
||||
$BankModel->setOtherStatus($bank_id,$model['store_user_id']);
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
/**
|
||||
* 银行账户编辑
|
||||
* @param $bank_id
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit($bank_id)
|
||||
{
|
||||
// 物流公司详情
|
||||
$model = BankModel::detail($bank_id);
|
||||
if (!$this->request->isAjax()) {
|
||||
// 人员列表
|
||||
$admin = User::getAll();
|
||||
$user = $this->getUserInfo();
|
||||
return $this->fetch('edit', compact('model','admin','user'));
|
||||
}
|
||||
// 更新记录
|
||||
if ($model->edit($this->postData('bank'))) {
|
||||
if($this->postData('bank')['status'] == 1) {
|
||||
$BankModel = new BankModel;
|
||||
$BankModel->setOtherStatus($bank_id,$model['store_user_id']);
|
||||
}
|
||||
return $this->renderSuccess('更新成功', url('bank/index'));
|
||||
}
|
||||
$error = $model->getError() ?: '更新失败';
|
||||
return $this->renderError($error);
|
||||
}
|
||||
/**
|
||||
* 删除银行账户
|
||||
* @param $bank_id
|
||||
* @return array
|
||||
*/
|
||||
public function delete($bank_id)
|
||||
{
|
||||
// 商品详情
|
||||
$model = BankModel::detail($bank_id);
|
||||
if (!$model->setDelete($bank_id)) {
|
||||
return $this->renderError('删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Card as CardModel;
|
||||
use app\store\model\card\CardPrint as CardPrintModel;
|
||||
use think\facade\Filesystem;
|
||||
use think\response\Json;
|
||||
use Picqer\Barcode\BarcodeGeneratorPNG;
|
||||
use setasign\Fpdi\Fpdi;
|
||||
use setasign\Fpdi\PdfReader\PdfReader;
|
||||
|
||||
/**
|
||||
* 充值卡控制器
|
||||
* Class Card
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Card extends Controller
|
||||
{
|
||||
/**
|
||||
* 充值卡列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new CardModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['card_number']) && !empty($getData['card_number'])) {
|
||||
$data[] = ['card_number', 'like', "%{$getData['card_number']}%"];
|
||||
}
|
||||
if (isset($getData['batch']) && !empty($getData['batch'])) {
|
||||
$data[] = ['batch', 'like', "%{$getData['batch']}%"];
|
||||
}
|
||||
if (isset($getData['user_id']) && $getData['user_id']) {
|
||||
$data[] = ['user_id', 'like', "%{$getData['user_id']}%"];
|
||||
}
|
||||
if (isset($getData['is_used']) && $getData['is_used'] > 0) {
|
||||
$data[] = ['is_used', '=', "{$getData['is_used']}"];
|
||||
}
|
||||
if (isset($getData['is_print']) && $getData['is_print'] > -1) {
|
||||
$data[] = ['is_print', '=', "{$getData['is_print']}"];
|
||||
}
|
||||
$data[] = ['is_delete', '=', 0];
|
||||
$list = $model->getList($data);
|
||||
return $this->renderSuccess(['list'=>$list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有充值卡
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$list = CardModel::getAll($user);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值卡详情
|
||||
* @param int $cardId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $cardId): Json
|
||||
{
|
||||
$cardInfo = CardModel::detail($cardId);
|
||||
return $this->renderSuccess(compact('cardInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除充值卡
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
foreach ((array)$arr as $val){
|
||||
$model = CardModel::detail($val);
|
||||
$model->setDelete();
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
public function generateRandomString($length = 12, $big = false) {
|
||||
$bytes = openssl_random_pseudo_bytes($length * 2); // 生成足够长的字节数
|
||||
return $big ? strtoupper(substr(bin2hex($bytes), 0, $length)) : substr(bin2hex($bytes), 0, $length); // 转换并截取所需长度
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加充值卡
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function addCards()
|
||||
{
|
||||
$data = $this->postForm();
|
||||
$pattern = '/^[1-9]\d*$/';
|
||||
$amount = $data['amount'];
|
||||
if(!preg_match($pattern,(string)$amount)){
|
||||
return $this->renderError('充值卡金额必须是正整数');
|
||||
}
|
||||
if($amount <= 0){
|
||||
return $this->renderError('充值卡金额不能小于等于0');
|
||||
}
|
||||
if($amount > 1000){
|
||||
return $this->renderError('充值卡金额不能大于1000');
|
||||
}
|
||||
$cards = [];
|
||||
$data = [];
|
||||
$batch = $this->generateBatchNumber();
|
||||
for ($i = 1;$i <= 18;$i++){
|
||||
$cardNumber = $this->generateCardNumber(12,$cards); // 生成12位卡号
|
||||
$plainSecretKey = $this->generateRandomString(16, true); // 生成16个字符长度的大写密钥
|
||||
|
||||
$data[] = [
|
||||
'batch' => $batch,
|
||||
'card_number' => $cardNumber,
|
||||
'secret_key' => $plainSecretKey,
|
||||
'amount' => $amount,
|
||||
'file_path' => $this->generateBarcode($plainSecretKey),
|
||||
];
|
||||
$cards[] = $cardNumber;
|
||||
}
|
||||
$model = new CardModel;
|
||||
// 新增记录
|
||||
if (!$model->add($data,$this->store['user'])) {
|
||||
return $this->renderError('添加充值卡失败');
|
||||
}
|
||||
$this->pdf($cards, $amount, $batch);
|
||||
return $this->renderSuccess('成功添加18张充值卡');
|
||||
}
|
||||
|
||||
/** 生成12位卡号
|
||||
* @param int $length
|
||||
* @param array $cards
|
||||
* @return false|string
|
||||
*/
|
||||
public function generateCardNumber($length = 12, $cards = []) {
|
||||
$timestamp = substr((string)(microtime(true) * 10000), -6); // 从时间戳中获取6位数
|
||||
$randomNumber = str_pad((string)rand(0, 999999), 6, '0', STR_PAD_LEFT); // 随机生成6位数
|
||||
|
||||
// 合成卡号
|
||||
$cardNumber = $timestamp . $randomNumber;
|
||||
// 确保长度
|
||||
$cardNumber = substr((string)$cardNumber, 0, $length);
|
||||
// 校验数据库是否存在该卡号
|
||||
if ($this->checkCardExists($cardNumber, $cards)) {
|
||||
return $this->generateCardNumber($length, $cards); // 如果卡号已存在,重新生成
|
||||
}
|
||||
|
||||
return $cardNumber;
|
||||
}
|
||||
/** 检查卡号是否存在
|
||||
* @param string $cardNumber
|
||||
* @param array $cards
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCardExists($cardNumber, $cards) {
|
||||
return !(!in_array($cardNumber, $cards) && !CardModel::detail(['card_number'=>$cardNumber]));
|
||||
}
|
||||
|
||||
/** 生成批次号
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
function generateBatchNumber($prefix = 'CARD') {
|
||||
$date = date('Ymd');
|
||||
$randomNumber = str_pad((string)rand(0, 9999), 4, '0', STR_PAD_LEFT);
|
||||
|
||||
// 合成批次号,前缀 + 日期 + 随机数
|
||||
return $prefix . $date . $randomNumber;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改充值卡使用状态
|
||||
* @return String
|
||||
*/
|
||||
public function generateBarcode($key) {
|
||||
// 确保密钥长度一致
|
||||
$key = str_pad($key, 16, '0', STR_PAD_LEFT);
|
||||
|
||||
$generator = new BarcodeGeneratorPNG();
|
||||
// 选择适当的条形码类型,例如 C128
|
||||
$barcode = $generator->getBarcode($key, $generator::TYPE_CODE_128);
|
||||
$name = $key.'.png';
|
||||
$path = $this->getCardPath().$name;
|
||||
|
||||
|
||||
|
||||
// 在图像上绘制条形码
|
||||
$barcodeImage = imagecreatefromstring($barcode);
|
||||
|
||||
// 创建一个空白图像,用于绘制条形码和编码文本
|
||||
$barcodeWidth = imagesx($barcodeImage)+5;
|
||||
$barcodeHeight = imagesy($barcodeImage);
|
||||
$fontSize = 18; // 字体大小
|
||||
$letterSpacing = 5; // 设置字符间距
|
||||
$text = $key;
|
||||
|
||||
$image = imagecreate($barcodeWidth, $barcodeHeight + 20); // 额外留出20px高度用于编码文本
|
||||
$backgroundColor = imagecolorallocate($image, 255, 255, 255); // 白色背景
|
||||
$textColor = imagecolorallocate($image, 0, 0, 0); // 黑色文字
|
||||
|
||||
imagecopy($image, $barcodeImage, 0, 0, 0, 0, imagesx($barcodeImage), imagesy($barcodeImage));
|
||||
|
||||
// 在图像下方绘制编码文本
|
||||
// 计算文本的总宽度(考虑字符间距)
|
||||
$textWidth = (imagefontwidth($fontSize) + $letterSpacing) * strlen($text) - $letterSpacing;
|
||||
|
||||
// 计算文本的起始X坐标,使文本居中
|
||||
$textX = ($barcodeWidth - $textWidth) / 2;
|
||||
$textY = $barcodeHeight;
|
||||
//imagestring($image, $fontSize, $textX, $textY, $text, $textColor);
|
||||
|
||||
// 绘制文本,逐个字符添加间距
|
||||
for ($i = 0; $i < strlen($text); $i++) {
|
||||
$xPos = intval($textX + ($i * (imagefontwidth($fontSize) + $letterSpacing)));
|
||||
imagestring($image, $fontSize, $xPos, $textY, $text[$i], $textColor);
|
||||
}
|
||||
|
||||
// 将图像保存为文件
|
||||
imagepng($image, public_path().$path);
|
||||
|
||||
// 销毁图像资源
|
||||
imagedestroy($image);
|
||||
imagedestroy($barcodeImage);
|
||||
|
||||
|
||||
// 将条形码保存为文件或输出
|
||||
//file_put_contents(public_path().$path, $barcode);
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取兑换卡保存路径
|
||||
* @return string
|
||||
*/
|
||||
private function getCardPath(): string
|
||||
{
|
||||
$filePath = 'uploads/card/' . date("Ymd") . '/';
|
||||
!is_dir($filePath) && mkdir($filePath, 0755, true);
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改充值卡使用状态
|
||||
* @return Json
|
||||
*/
|
||||
public function changeState(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$is_used = $post['state']?20:10;
|
||||
// 商品详情
|
||||
foreach ((array)$post['cardIds'] as $card_id) {
|
||||
$model = CardModel::detail($card_id);
|
||||
if (!$model->changeStatus($is_used)) {
|
||||
return $this->renderError('修改状态失败');
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
|
||||
/** 填充pdf
|
||||
* @param $cards
|
||||
* @param $amount
|
||||
* @param $batch
|
||||
* @return string
|
||||
*/
|
||||
public function pdf($cards, $amount, $batch)
|
||||
{
|
||||
/*$sum = 0;
|
||||
$money = 0;
|
||||
// 商品详情
|
||||
foreach ((array)$cards as $card_number) {
|
||||
$model = CardModel::detail(['card_number'=>$card_number]);
|
||||
if($money == 0){
|
||||
$money = $model['amount'];
|
||||
}
|
||||
if($model['amount'] != $money){
|
||||
return $this->renderError('请选择同一面额的兑换卡进行打印');
|
||||
}
|
||||
if ($model['is_used'] == 10 && $model['is_delete'] == 0 && $model['is_print'] == 0) {
|
||||
$sum++;
|
||||
}
|
||||
}
|
||||
if($sum != 18){
|
||||
return $this->renderError('请选择18张兑换卡');
|
||||
}*/
|
||||
$result = [];
|
||||
// 商品详情
|
||||
foreach ((array)$cards as $card_number) {
|
||||
$model = CardModel::detail(['card_number'=>$card_number]);
|
||||
if ($model['is_used'] == 10 && $model['is_delete'] == 0 && $model['is_print'] == 0) {
|
||||
$result[] = ['card_number'=>$model['card_number'],'file_path'=>$model['file_path'],'amount'=>(int)$model['amount']];
|
||||
}
|
||||
}
|
||||
$url = $this->fillPdfTemplate($result, $amount);
|
||||
CardPrintModel::add([
|
||||
'file_path' => $url,
|
||||
'amount' => $amount,
|
||||
'batch' => $batch,
|
||||
'num' => 18,
|
||||
'store_user_id' => $this->store['user']['store_user_id'],
|
||||
'store_id' => $this->storeId,
|
||||
]);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function fillPdfTemplate($result, $amount)
|
||||
{
|
||||
// 创建 FPDI 对象
|
||||
$pdf = new FPDI();
|
||||
|
||||
// 设置要导入的 PDF 模板文件路径
|
||||
$templateFile = public_path().'uploads/template/template_'.$amount.'.pdf';
|
||||
|
||||
// 设置要导入的 PDF 模板文件
|
||||
$pageCount = $pdf->setSourceFile($templateFile);
|
||||
|
||||
// import page 1
|
||||
$tplIdx = $pdf->importPage(1);
|
||||
// get the width and height of the template
|
||||
$specs = $pdf->getTemplateSize($tplIdx);
|
||||
// add a page
|
||||
$pdf->AddPage($specs['orientation'], array($specs['width'], $specs['height']));
|
||||
// use the imported page as the template
|
||||
$pdf->useTemplate($tplIdx, 0, 0);
|
||||
// now write some text above the imported page
|
||||
|
||||
$chunkedArray = array_chunk($result, 3);
|
||||
|
||||
// 初始坐标
|
||||
$numberX = 24;
|
||||
$numberY = 45;
|
||||
|
||||
$nxIncrement = 88.5;
|
||||
$nyIncrement = 56.5;
|
||||
|
||||
$keyX = 46;
|
||||
$keyY = 44;
|
||||
// x坐标和y坐标的增量
|
||||
$kxIncrement = 88.5;
|
||||
$kyIncrement = 56.5;
|
||||
|
||||
|
||||
|
||||
// 循环每一排
|
||||
for ($row = 0; $row < 6; $row++) {
|
||||
|
||||
// 计算当前行的y坐标
|
||||
$ny = $numberY + $row * $nyIncrement;
|
||||
$ky = $keyY + $row * $kyIncrement;
|
||||
|
||||
|
||||
|
||||
// 循环每一列
|
||||
for ($col = 0; $col < 3; $col++) {
|
||||
// 计算当前列的x坐标
|
||||
$nx = $numberX + $col * $nxIncrement;
|
||||
$kx = $keyX + $col * $kxIncrement;
|
||||
|
||||
// 输出结果
|
||||
|
||||
// 设置字体并填充文本
|
||||
$pdf->SetFont('Arial', 'B', 7);
|
||||
$pdf->SetXY($nx, $ny);
|
||||
$pdf->Cell(0, 10, $chunkedArray[$row][$col]['card_number']);
|
||||
|
||||
// 填充图片
|
||||
$imageFile = public_path().$chunkedArray[$row][$col]['file_path'];
|
||||
|
||||
$pdf->Image($imageFile, $kx, $ky, 55, 8);
|
||||
}
|
||||
}
|
||||
$url = 'uploads/pdf/'.time().'.pdf';
|
||||
// 输出填充后的 PDF
|
||||
$pdf->Output('F', public_path().$url);
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 商品分类
|
||||
* Class Category
|
||||
* @package app\store\controller\goods
|
||||
*/
|
||||
class Category extends Controller
|
||||
{
|
||||
/**
|
||||
* 商品分类列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new CategoryModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分类
|
||||
* @param $categoryId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $categoryId)
|
||||
{
|
||||
// 分类详情
|
||||
$model = CategoryModel::detail($categoryId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品分类
|
||||
* @return array|string
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new CategoryModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品分类
|
||||
* @param int $categoryId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(int $categoryId)
|
||||
{
|
||||
// 分类详情
|
||||
$model = CategoryModel::detail($categoryId, ['image']);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\User as StoreUserModel;
|
||||
use app\store\model\Deduct as DeductModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\Merchant as MerchantModel;
|
||||
|
||||
/**
|
||||
* 订单数据统计类
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Census extends Controller
|
||||
{
|
||||
/**
|
||||
* 用户列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
$model = new MerchantModel;
|
||||
$list = $model->getMerchantStatistics($this->store['user'],$get);
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计数据
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function stat()
|
||||
{
|
||||
$get = $this->request->get();
|
||||
//订单总金额
|
||||
$orderModel = new OrderModel;
|
||||
$filter = [];
|
||||
if(isset($get['name']) && !empty($get['name'])){
|
||||
$new = [];
|
||||
$new[] = ['name', 'like', "%{$get['name']}%"];
|
||||
$merchants = MerchantModel::getQuery($new);
|
||||
$filter[] = ['merchant_id', 'in', array_column($merchants,'merchant_id')];
|
||||
}
|
||||
$user = $this->store['user'];
|
||||
if($user['is_super'] == 0){
|
||||
$merchant_idArr = $user['merchant_id']?json_decode($user['merchant_id'],true):[];
|
||||
$filter[] = ['merchant_id', 'in', $merchant_idArr];
|
||||
}
|
||||
if(isset($get['betweenTime'])) {
|
||||
$times = between_time($get['betweenTime']);
|
||||
if (!empty($times['start_time'])) {
|
||||
$filter[] = ['create_time', '>=', $times['start_time']];
|
||||
}
|
||||
if (!empty($times['end_time'])) {
|
||||
$filter[] = ['create_time','<', $times['end_time'] + 86400];
|
||||
}
|
||||
}
|
||||
$filter[] = ['order_status', '=', 20];
|
||||
$totalMoney = $orderModel->getOrderTotalPriceCustom($filter);
|
||||
return $this->renderSuccess(['totalMoney'=>$totalMoney]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Checkout as CheckoutModel;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 结账控制器
|
||||
* Class Checkout
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Checkout extends Controller
|
||||
{
|
||||
/**
|
||||
* 结账列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new CheckoutModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['search']) && !empty($getData['search'])) {
|
||||
$data[] = ['checkout_id', 'like', "%{$getData['search']}%"];
|
||||
}
|
||||
$list = $model->getList($data);
|
||||
return $this->renderSuccess(['list'=>$list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有结账
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$list = CheckoutModel::getAll();
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 结账
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function checkout()
|
||||
{
|
||||
$model = new CheckoutModel;
|
||||
$data = $this->postForm();
|
||||
// 新增记录
|
||||
if ($model->checkout($data, $this->store['user'])) {
|
||||
return $this->renderSuccess('结账成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '结账失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
foreach ((array)$arr as $val){
|
||||
$model = CheckoutModel::detail($val);
|
||||
$model->setDelete();
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Code as CodeModel;
|
||||
use app\store\model\Shop as ShopModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\store\User;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Request;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 产码控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Code extends Controller
|
||||
{
|
||||
/**
|
||||
* 店铺列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index(): Json
|
||||
{
|
||||
$model = new CodeModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['status']) && (int)$getData['status']>=0) {
|
||||
$data[] = ['status', '=', (int)$getData['status']];
|
||||
}
|
||||
if (isset($getData['pay_status']) && (int)$getData['pay_status']>=0) {
|
||||
$data[] = ['pay_status', '=', (int)$getData['pay_status']];
|
||||
}
|
||||
if (isset($getData['code_account']) && !empty($getData['code_account'])) {
|
||||
$data[] = ['code_account', 'like', "%{$getData['code_account']}%"];
|
||||
}
|
||||
if (isset($getData['order_no']) && !empty($getData['order_no'])) {
|
||||
$data[] = ['order_no', 'like', "%{$getData['order_no']}%"];
|
||||
}
|
||||
if (isset($getData['passageway']) && $getData['passageway'] != -1) {
|
||||
$data[] = ['passageway', '=', $getData['passageway']];
|
||||
}
|
||||
if (isset($getData['state']) && $getData['state'] != -1) {
|
||||
$data[] = ['state', '=', $getData['state']];
|
||||
}
|
||||
if($this->store['user']['is_super'] == 0) {
|
||||
$data[] = ['store_user_id', 'in', User::getScope($this->store['user'])];
|
||||
}
|
||||
$list = $model->getList($data)->toArray();
|
||||
$domain = Request::instance()->domain();
|
||||
$url = $domain . '/wxScanPng.php';
|
||||
$data = [];
|
||||
foreach ((array)$list['data'] as $val){
|
||||
$val['qrcode'] = $url . '?url=' . urlencode(htmlspecialchars_decode($val['link']));
|
||||
$data[] = $val;
|
||||
}
|
||||
$list['data'] = $data;
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 统计数据列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function stat(): Json
|
||||
{
|
||||
$model = new CodeModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['status']) && (int)$getData['status']>=0) {
|
||||
$data[] = ['status', '=', (int)$getData['status']];
|
||||
}
|
||||
if (isset($getData['pay_status']) && (int)$getData['pay_status']>=0) {
|
||||
$data[] = ['pay_status', '=', (int)$getData['pay_status']];
|
||||
}
|
||||
if (isset($getData['code_account']) && !empty($getData['code_account'])) {
|
||||
$data[] = ['code_account', 'like', "%{$getData['code_account']}%"];
|
||||
}
|
||||
if (isset($getData['order_no']) && !empty($getData['order_no'])) {
|
||||
$data[] = ['order_no', 'like', "%{$getData['order_no']}%"];
|
||||
}
|
||||
if (isset($getData['passageway']) && $getData['passageway'] != -1) {
|
||||
$data[] = ['passageway', '=', $getData['passageway']];
|
||||
}
|
||||
if (isset($getData['state']) && $getData['state'] != -1) {
|
||||
$data[] = ['state', '=', $getData['state']];
|
||||
}
|
||||
if($this->store['user']['is_super'] == 0) {
|
||||
$data[] = ['store_user_id', 'in', User::getScope($this->store['user'])];
|
||||
}
|
||||
$money_list = SettingModel::getItem('trade')['money_list'];
|
||||
$money_arr = explode(',',$money_list);
|
||||
$arr = [];
|
||||
foreach ((array)$money_arr as $val){
|
||||
$arr[] = [
|
||||
'money' => $val,
|
||||
'num' => $model->getCodeTotal(array_merge([['money', '=', (float)$val]],$data))
|
||||
];
|
||||
}
|
||||
return $this->renderSuccess(['money'=>$arr]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加支付码
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new CodeModel;
|
||||
$data = $this->postForm();
|
||||
$codeModel = CodeModel::detail(['order_no'=>$data['order_no']]);
|
||||
if(isset($codeModel['code_id'])){
|
||||
return $this->renderError('苏宁单号重复');
|
||||
}
|
||||
$data['store_user_id'] = $this->store['user']['store_user_id'];
|
||||
$data['money'] = round($data['money'],2);
|
||||
// 新增记录
|
||||
if ($model->add($data)) {
|
||||
if($data['state'] == 1) {
|
||||
//写入队列
|
||||
$code_queue = ['code_id' => (int)$model->{$model->getPk()}, 'expire_time' => time() + (float)$data['expiration_time']]; // 过期时间
|
||||
$queue_name = $data['passageway'] . '_' . round($data['money'],2);
|
||||
//先清楚队列再加入,避免重复
|
||||
Cache::store('redis')->lRem($queue_name, json_encode($code_queue, 320), 1);
|
||||
Cache::store('redis')->rPush($queue_name, json_encode($code_queue, 320));
|
||||
|
||||
/*$queue_name = $data['shop_id'] . '_' . $data['passageway'] . '_' . round($data['money'],2);
|
||||
//店铺加入队列
|
||||
$shop_queue = 'shop_list';
|
||||
$elements = Cache::store('redis')->lRange($shop_queue, 0, -1);
|
||||
if(!in_array($data['shop_id'],$elements)){
|
||||
Cache::store('redis')->rPush($shop_queue, $data['shop_id']);
|
||||
}
|
||||
//先清楚队列再加入,避免重复
|
||||
Cache::store('redis')->lRem($queue_name, json_encode($code_queue, 320), 1);
|
||||
Cache::store('redis')->rPush($queue_name, json_encode($code_queue, 320));*/
|
||||
}
|
||||
/*$string = Cache::store('redis')->rPop($data['passageway'].'_'.$data['money']);
|
||||
var_dump($string);
|
||||
var_dump(json_decode($string,true));
|
||||
die();*/
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 产码详情
|
||||
* @param int $codeId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $codeId): Json
|
||||
{
|
||||
$codeInfo = CodeModel::detail($codeId);
|
||||
$domain = Request::instance()->domain();
|
||||
$url = $domain . '/wxScanPng.php';
|
||||
$codeInfo['qrcode'] = $url . '?url=' . urlencode(htmlspecialchars_decode($codeInfo['link']));
|
||||
return $this->renderSuccess(compact('codeInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑产码
|
||||
* @param int $codeId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $codeId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = CodeModel::detail($codeId);
|
||||
$data = $this->postForm();
|
||||
// 更新记录
|
||||
if ($model->edit($data)) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除支付码
|
||||
* @return array
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$orderModel = new OrderModel();
|
||||
$arr = $this->postData();
|
||||
foreach ((array)$arr as $code_id) {
|
||||
$model = CodeModel::detail($code_id);
|
||||
if ($model->setDelete()) {
|
||||
$orderModel->overtimeUpdate(['code_id' => $code_id, 'order_status' => 10]);
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产码列表状态
|
||||
* @return Json
|
||||
*/
|
||||
public function changeState(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$status = $post['state']?1:2;
|
||||
// 商品详情
|
||||
foreach ((array)$post['codeIds'] as $code_id) {
|
||||
$model = CodeModel::detail($code_id);
|
||||
$warn = $model->changeStatus($status);
|
||||
if ($warn !== true) {
|
||||
return $this->renderError($warn);
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换支付码的启停状态
|
||||
* @return Json
|
||||
*/
|
||||
public function stateSwitch(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$state = $post['state']?1:2;
|
||||
// 商品详情
|
||||
foreach ((array)$post['codeIds'] as $code_id) {
|
||||
$model = CodeModel::detail($code_id);
|
||||
if($state != $model['state']) {
|
||||
$warn = $model->stateSwitch($state);
|
||||
if ($warn !== true) {
|
||||
return $this->renderError($warn);
|
||||
}
|
||||
// 未使用才进行处理
|
||||
if ($model['status'] == 1) {
|
||||
$create_time = is_numeric($model['create_time']) ? $model['create_time'] : strtotime($model['create_time']);
|
||||
$code_queue = ['code_id' => (int)$model['code_id'], 'expire_time' => $create_time + (float)$model['expiration_time']]; // 过期时间
|
||||
$code_json = json_encode($code_queue, 320);
|
||||
$queue_name = $model['passageway'] . '_' . round($model['money'], 2);
|
||||
if ($state == 1) {
|
||||
//加入队列
|
||||
Cache::store('redis')->rPush($queue_name, $code_json);
|
||||
} else {
|
||||
//清楚队列
|
||||
Cache::store('redis')->lRem($queue_name, $code_json, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\Comment as CommentModel;
|
||||
use app\store\model\CommentImage as CommentImageModel;
|
||||
|
||||
/**
|
||||
* 商品评价模型
|
||||
* Class Comment
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Comment extends CommentModel
|
||||
{
|
||||
/**
|
||||
* 获取评价列表
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$query = $this->setQueryFilter($param);
|
||||
// 查询列表数据
|
||||
return $query->with(['user.avatar', 'orderGoods' => ['image']])
|
||||
->alias($this->name)
|
||||
->field(["$this->name.*"])
|
||||
->join('goods', "goods.goods_id = {$this->name}.goods_id")
|
||||
->join('order', "order.order_id = {$this->name}.order_id")
|
||||
->join('user', "user.user_id = {$this->name}.user_id")
|
||||
->where("{$this->name}.is_delete", '=', 0)
|
||||
->order(["{$this->name}.sort" => 'asc', "{$this->name}.create_time" => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return \think\db\BaseQuery
|
||||
*/
|
||||
private function setQueryFilter(array $param)
|
||||
{
|
||||
// 实例化查询对象
|
||||
$query = $this->getNewQuery();
|
||||
// 查询参数
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'score' => 0, // 评分 (10好评 20中评 30差评)
|
||||
'goodsName' => '', // 商品名称/编码
|
||||
'orderNo' => '', // 订单号
|
||||
'userId' => 0, // 用户id
|
||||
'status' => -1 // 评价状态 -1全部
|
||||
]);
|
||||
// 评分
|
||||
$params['score'] > 0 && $query->where("{$this->name}.score", '=', $params['score']);
|
||||
// 商品名称/编码
|
||||
!empty($params['goodsName']) && $query->where('goods.goods_name|goods.goods_no', 'like', "%{$params['goodsName']}%");
|
||||
// 订单号
|
||||
!empty($params['orderNo']) && $query->where('order.order_no', 'like', "%{$params['orderNo']}%");
|
||||
// 用户id
|
||||
$params['userId'] > 0 && $query->where("{$this->name}.user_id", '=', $params['userId']);
|
||||
// 评价状态
|
||||
$params['status'] > -1 && $query->where("{$this->name}.status", '=', $params['status']);
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评价详情
|
||||
* @param int $commentId
|
||||
* @return Comment|array|null
|
||||
*/
|
||||
public function getDetail(int $commentId)
|
||||
{
|
||||
// 评价详情
|
||||
$detail = static::detail($commentId, ['images.file']);
|
||||
// 图片ID集
|
||||
$detail['imageIds'] = helper::getArrayColumn($detail['images'], 'image_id');
|
||||
// 图片列表
|
||||
$detail['imageList'] = helper::getArrayColumn($detail['images'], 'file');
|
||||
return $detail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->transaction(function () use ($data) {
|
||||
// 更新商品图片记录
|
||||
CommentImageModel::updates((int)$this['comment_id'], $data['imageIds']);
|
||||
// 是否为图片评价
|
||||
$data['is_picture'] = !empty($data['images']);
|
||||
// 更新评论记录
|
||||
return $this->save($data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 软删除
|
||||
* @return false|int
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取评价总数量
|
||||
* @return int|string
|
||||
*/
|
||||
public function getCommentTotal()
|
||||
{
|
||||
return $this->where(['is_delete' => 0])->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\CommentImage as CommentImageModel;
|
||||
|
||||
/**
|
||||
* 商品评价图片模型
|
||||
* Class GoodsImage
|
||||
* @package app\store\model
|
||||
*/
|
||||
class CommentImage extends CommentImageModel
|
||||
{
|
||||
/**
|
||||
* 批量写入记录
|
||||
* @param int $commentId
|
||||
* @param array $imageIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $commentId, array $imageIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($imageIds as $imageId) {
|
||||
$dataset[] = [
|
||||
'image_id' => $imageId,
|
||||
'comment_id' => $commentId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新记录
|
||||
* @param $commentId
|
||||
* @param array $imageIds 新的图片集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $commentId, array $imageIds)
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['comment_id' => $commentId]);
|
||||
// 批量写入商品图片记录
|
||||
return static::increased($commentId, $imageIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\service\SybOil;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\Account as AccountModel;
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\store\model\store\User;
|
||||
use dashing\generator\Generator;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
use app\common\service\Random;
|
||||
use app\common\service\QueueService;
|
||||
|
||||
/**
|
||||
* 公司控制器
|
||||
* Class Company
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Company extends Controller
|
||||
{
|
||||
/**
|
||||
* 公司列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new CompanyModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['name']) && !empty($getData['name'])) {
|
||||
$data[] = ['name', 'like', "%{$getData['name']}%"];
|
||||
}
|
||||
$user = $this->store['user'];
|
||||
if($user['is_super'] == 0) {
|
||||
$data[] = ['store_user_id', 'in', User::getScope($user)];
|
||||
}
|
||||
/*if(!empty($this->store['user']['company_id']) && $this->store['user']['is_super'] == 0){
|
||||
$filter[] = ['company_id', 'in', json_decode($this->store['user']['company_id'],true)];
|
||||
}*/
|
||||
$list = $model->getList($data);
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有公司
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$list = CompanyModel::getAll($user);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加公司
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new CompanyModel;
|
||||
$data = $this->postForm();
|
||||
// 新增记录
|
||||
if ($model->add($data,$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 公司详情
|
||||
* @param int $companyId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $companyId): Json
|
||||
{
|
||||
$companyInfo = CompanyModel::detail($companyId);
|
||||
return $this->renderSuccess(compact('companyInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑公司
|
||||
* @param int $companyId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $companyId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = CompanyModel::detail($companyId);
|
||||
$data = $this->postForm();
|
||||
// 更新记录
|
||||
if ($model->edit($data)) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值
|
||||
* @param int $companyId
|
||||
* @param string $target
|
||||
* @return array
|
||||
*/
|
||||
public function recharge(int $companyId, string $target)
|
||||
{
|
||||
// 用户详情
|
||||
$model = CompanyModel::detail($companyId);
|
||||
if ($model->recharge($target, $this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除公司
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
foreach ((array)$arr as $val){
|
||||
$model = CompanyModel::detail($val);
|
||||
$model->setDelete();
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加公司用户
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function addAccount()
|
||||
{
|
||||
$queueService = new QueueService();
|
||||
$data = $this->postForm();
|
||||
if($data['users'] > 10000){
|
||||
return $this->renderSuccess('单次最多生成10000条用户');
|
||||
}
|
||||
$users = (int)$data['users'];
|
||||
$success = 0;
|
||||
for ($i = 1;$i <= $users;$i++){
|
||||
$model = new AccountModel;
|
||||
$info = [
|
||||
'userName' => Random::generateName(),
|
||||
'mobile' => Random::getMobile(),
|
||||
'userIdCard' => Random::getIdcard(),
|
||||
'company_id' => $data['company_id'],
|
||||
];
|
||||
// 新增记录
|
||||
if ($model->add($info,$this->store['user'])) {
|
||||
$account_id = $model->account_id;
|
||||
// $queueService->push('account_queue', $account_id);
|
||||
$success++;
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess('成功添加'.$success.'用户');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改店铺列表状态
|
||||
* @return Json
|
||||
*/
|
||||
public function changeState(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$status = $post['state']?10:20;
|
||||
// 商品详情
|
||||
foreach ((array)$post['companyIds'] as $company_id) {
|
||||
$model = CompanyModel::detail($company_id);
|
||||
$warn = $model->changeStatus($status);
|
||||
if ($warn !== true) {
|
||||
return $this->renderError($warn);
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orgNo
|
||||
* @return array
|
||||
*/
|
||||
public function getGoodsNo($orgNo): array
|
||||
{
|
||||
switch ($orgNo) {
|
||||
case 'umQZhIHKofyA':
|
||||
return ['djgdface100','djgdface200','djgdface300'];
|
||||
case 'HpWqXIgYvTBg':
|
||||
return ['jmgxyyface100','jmgxyyface200','jmgxyyface300','jmgzface100','jmgzface200','jmgzface300','jmfjface100','jmfjface200','jmfjface300'];
|
||||
case 'NKJBgaaRNdiL':
|
||||
return ['face003'];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新公司商品库存
|
||||
* @return Json
|
||||
*/
|
||||
public function stock(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
// 商品详情
|
||||
foreach ((array)$arr as $company_id) {
|
||||
$company = CompanyModel::detail($company_id);
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$goodsNo = $this->getGoodsNo($company['orgNo']);
|
||||
$goodsList = GoodsModel::getAll([['goods_no','in',$goodsNo]]);
|
||||
$canOrderNum = $unUseNum = $useNum = 0;
|
||||
foreach ($goodsList as $array){
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->stockList(['goodsNo' => $array['goods_no']], $company);
|
||||
// 更新记录
|
||||
if ($res['code'] == '1') {
|
||||
/*$res['data']['canOrderNum'] = $res['data']['canOrderNum']?:0;
|
||||
$res['data']['unUseNum'] = $res['data']['unUseNum']?:0;
|
||||
$res['data']['useNum'] = $res['data']['useNum']?:0;
|
||||
$canOrderNum += $res['data']['canOrderNum'];
|
||||
$unUseNum += $res['data']['unUseNum'];
|
||||
$useNum += $res['data']['useNum'];
|
||||
Db::name('goods')
|
||||
->where('goods_id', $array['goods_id'])
|
||||
->update(['stock_total' => $res['data']['canOrderNum'], 'unUseNum' => $res['data']['unUseNum'], 'useNum' => $res['data']['useNum']]);
|
||||
|
||||
Db::name('goods_sku')
|
||||
->where('goods_id', $array['goods_id'])
|
||||
->update(['stock_num' => $res['data']['canOrderNum'], 'unUseNum' => $res['data']['unUseNum'], 'useNum' => $res['data']['useNum']]);
|
||||
*/
|
||||
$res['data']['quantity'] = $res['data']['quantity']?:0;
|
||||
$canOrderNum += $res['data']['quantity'];
|
||||
Db::name('goods')
|
||||
->where('goods_id', $array['goods_id'])
|
||||
->update(['stock_total' => $res['data']['quantity']]);
|
||||
|
||||
Db::name('goods_sku')
|
||||
->where('goods_id', $array['goods_id'])
|
||||
->update(['stock_num' => $res['data']['quantity']]);
|
||||
}
|
||||
}
|
||||
$company->save(['canOrderNum'=>$canOrderNum,'unUseNum'=>$unUseNum,'useNum'=>$useNum]);
|
||||
|
||||
}
|
||||
return $this->renderSuccess($arr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\crypto\Crypto;
|
||||
use app\store\model\store\User;
|
||||
use cores\BaseController;
|
||||
use app\store\service\Auth as AuthService;
|
||||
use app\common\service\store\User as StoreUserService;
|
||||
use app\common\exception\BaseException;
|
||||
use think\response\Json;
|
||||
use think\Session;
|
||||
|
||||
use app\common\service\SybOil;
|
||||
|
||||
/**
|
||||
* 商户后台控制器基类
|
||||
* Class Controller
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
// 商家登录信息
|
||||
protected $store;
|
||||
|
||||
// 当前商城ID
|
||||
protected $storeId;
|
||||
|
||||
// 当前控制器名称
|
||||
protected $controller = '';
|
||||
|
||||
// 当前方法名称
|
||||
protected $action = '';
|
||||
|
||||
// 当前路由uri
|
||||
protected $routeUri = '';
|
||||
|
||||
// 当前路由:分组名称
|
||||
protected $group = '';
|
||||
|
||||
// 登录验证白名单
|
||||
protected $allowAllAction = [
|
||||
'passport/login',
|
||||
'passport/logout',
|
||||
'passport/detail',
|
||||
'merchant/all',
|
||||
];
|
||||
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* 例: [ 'login' => 'POST' ]
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [];
|
||||
|
||||
/**
|
||||
* 后台初始化
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
// 当前商城id
|
||||
$this->storeId = $this->getStoreId();
|
||||
// 设置管理员登录信息
|
||||
$this->setStoreInfo();
|
||||
// 当前路由信息
|
||||
$this->getRouteInfo();
|
||||
// 验证登录状态
|
||||
$this->checkLogin();
|
||||
// 验证当前API权限
|
||||
$this->checkPrivilege();
|
||||
// 强制验证当前访问的控制器方法method
|
||||
$this->checkMethodRules();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置管理员登录信息
|
||||
*/
|
||||
private function setStoreInfo()
|
||||
{
|
||||
$this->store = StoreUserService::getLoginInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前路由权限
|
||||
* @return bool
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function checkPrivilege(): bool
|
||||
{
|
||||
// 在开发模式下, 建议把此处代码暂时屏蔽, 开发完成后在超管后台新增菜单和api
|
||||
if (!AuthService::getInstance()->checkPrivilege('/' . $this->routeUri)) {
|
||||
throwError('很抱歉,没有当前api的访问权限 ' . $this->routeUri);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析当前路由参数 (分组名称、控制器名称、方法名)
|
||||
*/
|
||||
protected function getRouteInfo()
|
||||
{
|
||||
// 控制器名称
|
||||
$this->controller = uncamelize($this->request->controller());
|
||||
// 方法名称
|
||||
$this->action = $this->request->action();
|
||||
// 控制器分组 (用于定义所属模块)
|
||||
$group = strstr($this->controller, '.', true);
|
||||
$this->group = $group !== false ? $group : $this->controller;
|
||||
// 当前uri
|
||||
$this->routeUri = "{$this->controller}/$this->action";
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证登录状态
|
||||
* @return bool
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkLogin(): bool
|
||||
{
|
||||
// 验证当前请求是否在白名单
|
||||
if (in_array($this->routeUri, $this->allowAllAction)) {
|
||||
return true;
|
||||
}
|
||||
// 验证登录状态
|
||||
if (empty($this->store) || (int)$this->store['is_login'] !== 1) {
|
||||
throwError('请先登录后再访问', config('status.not_logged'));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前store_id
|
||||
* @return int|null
|
||||
*/
|
||||
protected function getStoreId(): ?int
|
||||
{
|
||||
// app/store/common.php
|
||||
return getStoreId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @param int|null $status 状态码
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderData(int $status = null, string $message = '', array $data = []): Json
|
||||
{
|
||||
is_null($status) && $status = config('status.success');
|
||||
return json(compact('status', 'message', 'data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作成功json
|
||||
* @param array|string $data
|
||||
* @param string $message
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderSuccess($data = [], string $message = 'success'): Json
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$message = $data;
|
||||
$data = [];
|
||||
}
|
||||
return $this->renderData(config('status.success'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作失败json
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderError(string $message = 'error', array $data = []): Json
|
||||
{
|
||||
return $this->renderData(config('status.error'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postData($key = null)
|
||||
{
|
||||
return $this->request->post(empty($key) ? '' : "{$key}/a");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postForm(string $key = 'form')
|
||||
{
|
||||
return $this->postData($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getData($key = null)
|
||||
{
|
||||
return $this->request->get(is_null($key) ? '' : $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* @return bool
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkMethodRules(): bool
|
||||
{
|
||||
if (!isset($this->methodRules[$this->action])) {
|
||||
return true;
|
||||
}
|
||||
$methodRule = $this->methodRules[$this->action];
|
||||
$currentMethod = $this->request->method();
|
||||
if (empty($methodRule)) {
|
||||
return true;
|
||||
}
|
||||
if (is_array($methodRule) && in_array($currentMethod, $methodRule)) {
|
||||
return true;
|
||||
}
|
||||
if (is_string($methodRule) && $methodRule == $currentMethod) {
|
||||
return true;
|
||||
}
|
||||
throwError('illegal request method');
|
||||
return false;
|
||||
}
|
||||
|
||||
public function mk_dir_store($dir, $mode = 0777)
|
||||
{
|
||||
if (is_dir($dir) || @mkdir($dir,$mode)) return true;
|
||||
if (!$this->mk_dir_store(dirname($dir),$mode)) return false;
|
||||
return @mkdir($dir,$mode);
|
||||
}
|
||||
|
||||
/** 记录日志
|
||||
* @param $data
|
||||
*/
|
||||
public function saveLogStore($data){
|
||||
$SybOil = new SybOil();
|
||||
$SybOil->saveLogStore($data);
|
||||
}
|
||||
|
||||
public function sendRequest($company, $url, $businessParams = [], $appendHeaders = [], $file = null)
|
||||
{
|
||||
$crypto = new Crypto($company);
|
||||
// 签名并组合header,并加密数据
|
||||
$this->saveLogStore(json_encode($businessParams,320));
|
||||
$requestData = $crypto->prepareRequest($appendHeaders, $businessParams);
|
||||
$businessParams = $requestData['encryptData'];
|
||||
// 构建默认的公共参数头
|
||||
$headers = [];
|
||||
foreach ($requestData['header'] as $k=>$val){
|
||||
$headers[] = $k.': '.$val;
|
||||
}
|
||||
$this->saveLogStore(json_encode($requestData['header'],320));
|
||||
$this->saveLogStore(json_encode($businessParams,320));
|
||||
// 使用 cURL 发送请求
|
||||
$ch = curl_init();
|
||||
|
||||
// 设置请求 URL
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
// 设置请求方式为 POST
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
// 返回结果而不是输出
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// 包含响应头在输出中
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
$headers[] = 'Charset: UTF-8';
|
||||
if ($file) {
|
||||
// 如果有文件上传,设置 multipart/form-data 表单
|
||||
$filePath = $file->getPathname();
|
||||
$fileName = $file->getOriginalName();
|
||||
$fileMime = $file->getMimeType();
|
||||
$postFields = [
|
||||
'file' => new \CURLFile($filePath, $fileMime, $fileName),
|
||||
'businessParams' => json_encode($businessParams, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
} else {
|
||||
// 如果没有文件上传,直接发送业务参数的 JSON 数据
|
||||
$postFields = json_encode($businessParams, JSON_UNESCAPED_UNICODE);
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// 执行请求
|
||||
$response = curl_exec($ch);
|
||||
$this->saveLogStore('接口返回值:'.$response);
|
||||
// 检查是否有错误
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ['code' => '01', 'message' => $error_msg];
|
||||
}
|
||||
|
||||
// 获取响应头大小
|
||||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
|
||||
// 分离响应头和响应体
|
||||
$headerString = substr($response, 0, $header_size);
|
||||
$bodyString = substr($response, $header_size);
|
||||
|
||||
// 关闭 cURL 句柄
|
||||
curl_close($ch);
|
||||
|
||||
// 解析响应头为数组
|
||||
$headerArray = [];
|
||||
foreach (explode("\r\n", $headerString) as $header) {
|
||||
if (trim($header) !== '' && strpos($header, ':') !== false) {
|
||||
list($key, $value) = explode(': ', $header, 2);
|
||||
$headerArray[strtolower(trim($key))] = trim($value);
|
||||
}
|
||||
}
|
||||
$res = $crypto->processResponse(['header'=>$headerArray,'encryptData'=>json_decode($bodyString, true)]);
|
||||
if(!$res){
|
||||
return ['code' => '01', 'message' => $bodyString];
|
||||
}
|
||||
// 返回结果
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Coupon as CouponModel;
|
||||
use app\common\enum\coupon\CouponType as CouponTypeEnum;
|
||||
use app\common\enum\coupon\ExpireType as ExpireTypeEnum;
|
||||
use app\common\enum\coupon\ApplyRange as ApplyRangeEnum;
|
||||
|
||||
/**
|
||||
* 优惠券模型
|
||||
* Class Coupon
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Coupon extends CouponModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = []): \think\Paginator
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 查询列表数据
|
||||
return $this->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', 'create_time' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = []): array
|
||||
{
|
||||
// 默认查询条件
|
||||
$param = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($param['search']) && $filter[] = ['name', 'like', "%{$param['search']}%"];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return bool|false
|
||||
*/
|
||||
public function add(array $data): bool
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($this->createData($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
return $this->save($this->createData($data)) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
private function createData(array $data): array
|
||||
{
|
||||
// 折扣券记录有效期
|
||||
// 领取后生效
|
||||
if ($data['expire_type'] == ExpireTypeEnum::RECEIVE) {
|
||||
$data['start_time'] = $data['end_time'] = 0;
|
||||
} // 固定时间
|
||||
elseif ($data['expire_type'] == ExpireTypeEnum::FIXED_TIME) {
|
||||
$times = between_time($data['betweenTime']);
|
||||
$data['start_time'] = $times['start_time'];
|
||||
$data['end_time'] = $times['end_time'] + (86400 - 1);
|
||||
$data['expire_day'] = 1;
|
||||
}
|
||||
// 适用范围
|
||||
if ($data['apply_range'] == ApplyRangeEnum::ALL) {
|
||||
$data['apply_range_config'] = [];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录 (软删除)
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete(): bool
|
||||
{
|
||||
return $this->save(['is_delete' => 1]) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\common\model\Delivery as DeliveryModel;
|
||||
use app\store\model\DeliveryRule as DeliveryRuleModel;
|
||||
|
||||
/**
|
||||
* 配送模板模型
|
||||
* Class Delivery
|
||||
* @package app\common\model
|
||||
*/
|
||||
class Delivery extends DeliveryModel
|
||||
{
|
||||
/**
|
||||
* 获取全部
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function getAll()
|
||||
{
|
||||
$model = new static;
|
||||
return $model->order(['sort', $model->getPk()])->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList($param = [])
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, ['search' => '']);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
!empty($params['search']) && $filter[] = ['name', 'like', "%{$params['search']}%"];
|
||||
// 查询列表数据
|
||||
return $this->with(['rule'])
|
||||
->where($filter)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['sort', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
// 表单验证
|
||||
if (!$this->onValidate($data)) {
|
||||
return false;
|
||||
}
|
||||
$data['store_id'] = self::$storeId;
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 保存数据
|
||||
$this->save($data);
|
||||
// 添加模板区域及运费
|
||||
DeliveryRuleModel::increased((int)$this['delivery_id'], $data['rules']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 表单验证
|
||||
if (!$this->onValidate($data)) {
|
||||
return false;
|
||||
}
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($data) {
|
||||
// 保存数据
|
||||
$this->save($data);
|
||||
// 更新模板区域及运费
|
||||
DeliveryRuleModel::updates((int)$this['delivery_id'], $data['rules']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 表单验证
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
private function onValidate(array $data)
|
||||
{
|
||||
if (!isset($data['rules']) || empty($data['rules'])) {
|
||||
$this->error = '请选择可配送区域';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 验证运费模板是否被商品使用
|
||||
if (!$this->checkIsUseGoods($this['delivery_id'])) {
|
||||
return false;
|
||||
}
|
||||
// 删除运费模板
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证运费模板是否被商品使用
|
||||
* @param int $deliveryId
|
||||
* @return bool
|
||||
*/
|
||||
private function checkIsUseGoods(int $deliveryId)
|
||||
{
|
||||
// 判断是否存在商品
|
||||
$goodsCount = (new GoodsModel)->getGoodsTotal(['delivery_id' => $deliveryId]);
|
||||
if ($goodsCount > 0) {
|
||||
$this->error = "该模板被{$goodsCount}个商品使用,不允许删除";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\DeliveryRule as DeliveryRuleModel;
|
||||
|
||||
/**
|
||||
* 配送模板区域及运费模型
|
||||
* Class DeliveryRule
|
||||
* @package app\store\model
|
||||
*/
|
||||
class DeliveryRule extends DeliveryRuleModel
|
||||
{
|
||||
/**
|
||||
* 批量写入记录
|
||||
* @param int $deliveryId
|
||||
* @param array $rules
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $deliveryId, array $rules)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($rules as $ruleItem) {
|
||||
$dataset[] = [
|
||||
'delivery_id' => $deliveryId,
|
||||
'region' => $ruleItem['region'],
|
||||
'region_text' => $ruleItem['region_text'],
|
||||
'first' => $ruleItem['first'],
|
||||
'first_fee' => $ruleItem['first_fee'],
|
||||
'additional' => $ruleItem['additional'],
|
||||
'additional_fee' => $ruleItem['additional_fee'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param $deliveryId
|
||||
* @param array $rules 新的图片集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $deliveryId, array $rules)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['delivery_id' => $deliveryId]);
|
||||
// 批量写入记录
|
||||
return static::increased($deliveryId, $rules);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Express as ExpressModel;
|
||||
|
||||
class Express extends ExpressModel
|
||||
{
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断当前物流公司是否已被订单使用
|
||||
$Order = new Order;
|
||||
if ($orderCount = $Order->where(['express_id' => $this['express_id']])->count()) {
|
||||
$this->error = '当前物流公司已被' . $orderCount . '个订单使用,不允许删除';
|
||||
return false;
|
||||
}
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\store\model\UploadFile as UploadFileModel;
|
||||
use cores\library\Version;
|
||||
|
||||
/**
|
||||
* 文件库管理
|
||||
* Class Files
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Files extends Controller
|
||||
{
|
||||
/**
|
||||
* 文件列表
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$this->env();
|
||||
$model = new UploadFileModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文件
|
||||
* @param int $fileId
|
||||
* @return Json
|
||||
*/
|
||||
public function edit(int $fileId): Json
|
||||
{
|
||||
// 文件详情
|
||||
$model = UploadFileModel::detail($fileId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件(批量)
|
||||
* @param array $fileIds 文件id集
|
||||
* @return Json
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function delete(array $fileIds): Json
|
||||
{
|
||||
$model = new UploadFileModel;
|
||||
if (!$model->setDelete($fileIds)) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件到指定分组(批量)
|
||||
* @param int $groupId
|
||||
* @param array $fileIds
|
||||
* @return Json
|
||||
*/
|
||||
public function moveGroup(int $groupId, array $fileIds): Json
|
||||
{
|
||||
$model = new UploadFileModel;
|
||||
if (!$model->moveGroup($groupId, $fileIds)) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 临时方法:环境检测并删除废弃的库文件
|
||||
* 文件:vendor/topthink/framework/src/think/Filesystem.php
|
||||
* 文件:vendor/topthink/framework/src/think/facade/Filesystem.php
|
||||
* 文件:vendor/topthink/framework/tests/FilesystemTest.php
|
||||
* 目录:vendor/topthink/framework/src/think/filesystem
|
||||
* @return void
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
private function env()
|
||||
{
|
||||
// 判断当前版本小于2.2.7则不执行
|
||||
if (Version::compare(Version::getVersion(), '2.2.7') === -1) {
|
||||
return;
|
||||
}
|
||||
// 要删除的文件列表
|
||||
$files = [
|
||||
'vendor/topthink/framework/src/think/Filesystem.php',
|
||||
'vendor/topthink/framework/src/think/facade/Filesystem.php',
|
||||
'vendor/topthink/framework/tests/FilesystemTest.php'
|
||||
];
|
||||
foreach ($files as $file) {
|
||||
$filePath = root_path() . $file;
|
||||
file_exists($filePath) && unlink($filePath);
|
||||
}
|
||||
// 要删除的目录列表
|
||||
$folders = ['vendor/topthink/framework/src/think/filesystem/'];
|
||||
foreach ($folders as $folder) {
|
||||
$folderPath = root_path() . $folder;
|
||||
is_dir($folderPath) && $this->deleteFolder($folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 临时方法:递归删除指定目录下所有文件
|
||||
* @param $path
|
||||
* @return void
|
||||
*/
|
||||
private function deleteFolder($path): void
|
||||
{
|
||||
if (!is_dir($path)) {
|
||||
return;
|
||||
}
|
||||
// 扫描一个文件夹内的所有文件夹和文件
|
||||
foreach (scandir($path) as $val) {
|
||||
// 排除目录中的.和..
|
||||
if (!in_array($val, ['.', '..', '.gitignore'])) {
|
||||
// 如果是目录则递归子目录,继续操作
|
||||
if (is_dir($path . $val)) {
|
||||
// 子目录中操作删除文件夹和文件
|
||||
$this->deleteFolder($path . $val . '/');
|
||||
// 目录清空后删除空文件夹
|
||||
rmdir($path . $val . '/');
|
||||
} else {
|
||||
// 如果是文件直接删除
|
||||
unlink($path . $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\api\model\Company as CompanyModel;
|
||||
use app\common\library\helper;
|
||||
use app\common\model\Coupon as CouponModel;
|
||||
use app\common\model\UserCoupon as UserCouponModel;
|
||||
use think\response\Json;
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use app\common\exception\BaseException;
|
||||
use app\console\model\Setting as SettingModel;
|
||||
use app\common\service\SybOil;
|
||||
|
||||
/**
|
||||
* 商品管理控制器
|
||||
* Class Goods
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Goods extends Controller
|
||||
{
|
||||
/**
|
||||
* 商品列表
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
// 获取列表记录
|
||||
$model = new GoodsModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品ID集获取列表记录
|
||||
* @param array $goodsIds
|
||||
* @return Json
|
||||
*/
|
||||
public function listByIds(array $goodsIds): Json
|
||||
{
|
||||
// 获取列表记录
|
||||
$model = new GoodsModel;
|
||||
$list = $model->getListByIds($goodsIds);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情
|
||||
* @param int $goodsId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $goodsId): Json
|
||||
{
|
||||
// 获取商品详情
|
||||
$model = new GoodsModel;
|
||||
$goodsInfo = $model->getDetail($goodsId);
|
||||
return $this->renderSuccess(compact('goodsInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function add(): Json
|
||||
{
|
||||
$model = new GoodsModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
* @param int $goodsId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $goodsId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = GoodsModel::detail($goodsId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商品状态(上下架)
|
||||
* @param array $goodsIds 商品id集
|
||||
* @param bool $state 为true表示上架
|
||||
* @return Json
|
||||
*/
|
||||
public function state(array $goodsIds, bool $state): Json
|
||||
{
|
||||
$model = new GoodsModel;
|
||||
if (!$model->setStatus($goodsIds, $state)) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param array $goodsIds
|
||||
* @return Json
|
||||
*/
|
||||
public function delete(array $goodsIds): Json
|
||||
{
|
||||
$model = new GoodsModel;
|
||||
if (!$model->setDelete($goodsIds)) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取省份
|
||||
* @return Json
|
||||
*/
|
||||
public function province(): Json
|
||||
{
|
||||
$province_list = SettingModel::getItem('trade', $this->storeId)['province_list'];
|
||||
$list = explode(',',$province_list);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
/**
|
||||
* 获取所有产品
|
||||
* @param string $province
|
||||
* @param string $oilCardType
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all($province, $oilCardType): Json
|
||||
{
|
||||
/*if (!$province) {
|
||||
return $this->renderSuccess('请选择省份');
|
||||
}*/
|
||||
if (!$oilCardType) {
|
||||
return $this->renderSuccess('请选择卡券类型');
|
||||
}
|
||||
$where = [
|
||||
['province', '=', $province],
|
||||
['oilCardType', '=', $oilCardType],
|
||||
];
|
||||
$list = GoodsModel::getAll($where);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商品
|
||||
* @param int $goodsId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function onReloadStock(int $goodsId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = GoodsModel::detail($goodsId);
|
||||
$company = CompanyModel::detail(['status'=>10]);
|
||||
$SybOil = new SybOil();
|
||||
// 对接平台接口
|
||||
$res = $SybOil->stockList(['goodsNo' => $model['goods_no']], $company);
|
||||
// 更新记录
|
||||
if ($res['code'] == '00') {
|
||||
return $this->renderSuccess($res['data']);
|
||||
}
|
||||
return $this->renderError($model->getError() ?: $res['errMessage']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有产品
|
||||
* @param string $oilCardType
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function oilAll($oilCardType): Json
|
||||
{
|
||||
if (!$oilCardType) {
|
||||
return $this->renderSuccess('请选择卡券类型');
|
||||
}
|
||||
$where = [
|
||||
['oilCardType', '=', $oilCardType],
|
||||
];
|
||||
$list = GoodsModel::getAll($where);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
|
||||
|
||||
/**
|
||||
* 商品与分类关系模型
|
||||
* Class GoodsCategoryRel
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsCategoryRel extends GoodsCategoryRelModel
|
||||
{
|
||||
/**
|
||||
* 根据分类ID获取记录总数量
|
||||
* @param int $categoryId
|
||||
* @return int
|
||||
*/
|
||||
public static function getCountByCategoryId(int $categoryId)
|
||||
{
|
||||
return (new static)->alias('m')
|
||||
->join('goods', 'goods.goods_id = m.goods_id')
|
||||
->where('m.category_id', '=', $categoryId)
|
||||
->where('goods.is_delete', '=', 0)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品分类ID集
|
||||
* @param int $goodsId
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategoryIds(int $goodsId)
|
||||
{
|
||||
return (new static)->where('goods_id', '=', $goodsId)->column('category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入商品分类记录
|
||||
* @param int $goodsId
|
||||
* @param array $categoryIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $categoryIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($categoryIds as $categoryId) {
|
||||
$dataset[] = [
|
||||
'category_id' => $categoryId,
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param $goodsId
|
||||
* @param array $categoryIds 新的分类集
|
||||
* @return array|false
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updates(int $goodsId, $categoryIds)
|
||||
{
|
||||
// 已分配的分类集
|
||||
$assignCategoryIds = self::getCategoryIdsByGoodsId($goodsId);
|
||||
// 找出删除的分类
|
||||
$deleteCategoryIds = array_diff($assignCategoryIds, $categoryIds);
|
||||
if (!empty($deleteCategoryIds)) {
|
||||
static::deleteAll([
|
||||
['goods_id', '=', $goodsId],
|
||||
['category_id', 'in', $deleteCategoryIds]
|
||||
]);
|
||||
}
|
||||
// 找出添加的分类
|
||||
$newCategoryIds = array_diff($categoryIds, $assignCategoryIds);
|
||||
$dataset = [];
|
||||
foreach ($newCategoryIds as $categoryId) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'category_id' => $categoryId,
|
||||
'store_id' => self::$storeId,
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定商品的所有分类id
|
||||
* @param int $goodsId
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategoryIdsByGoodsId(int $goodsId)
|
||||
{
|
||||
return (new static)->where('goods_id', '=', $goodsId)->column('category_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsImage as GoodsImageModel;
|
||||
|
||||
/**
|
||||
* 商品图片模型
|
||||
* Class GoodsImage
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsImage extends GoodsImageModel
|
||||
{
|
||||
/**
|
||||
* 批量写入商品图片记录
|
||||
* @param int $goodsId
|
||||
* @param array $imageIds
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $imageIds)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($imageIds as $imageId) {
|
||||
$dataset[] = [
|
||||
'image_id' => $imageId,
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $imageIds 新的图片集
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $goodsId, array $imageIds)
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 批量写入商品图片记录
|
||||
return static::increased($goodsId, $imageIds);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\GoodsSku as GoodsSkuModel;
|
||||
use app\common\enum\goods\SpecType as SpecTypeEnum;
|
||||
|
||||
/**
|
||||
* 商品规格模型
|
||||
* Class GoodsSku
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsSku extends GoodsSkuModel
|
||||
{
|
||||
/**
|
||||
* 获取库存总数量 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return float|int
|
||||
*/
|
||||
public static function getStockTotal(array $skuList)
|
||||
{
|
||||
return (int)helper::getArrayColumnSum($skuList, 'stock_num');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品价格高低区间 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getGoodsPrices(array $skuList): array
|
||||
{
|
||||
$goodsPriceArr = helper::getArrayColumn($skuList, 'goods_price');
|
||||
return empty($goodsPriceArr) ? [0, 0] : [min($goodsPriceArr), max($goodsPriceArr)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取划线价格高低区间 (根据sku列表数据)
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getLinePrices(array $skuList): array
|
||||
{
|
||||
$linePriceArr = helper::getArrayColumn($skuList, 'line_price');
|
||||
return empty($linePriceArr) ? [0, 0] : [min($linePriceArr), max($linePriceArr)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成skuList数据(写入goods_sku_id)
|
||||
* @param array $newSpecList
|
||||
* @param array $skuList
|
||||
* @return array
|
||||
*/
|
||||
public static function getNewSkuList(array $newSpecList, array $skuList): array
|
||||
{
|
||||
foreach ($skuList as &$skuItem) {
|
||||
$skuItem['specValueIds'] = static::getSpecValueIds($newSpecList, $skuItem['skuKeys']);
|
||||
$skuItem['goodsProps'] = static::getGoodsProps($newSpecList, $skuItem['skuKeys']);
|
||||
$skuItem['goods_sku_id'] = implode('_', $skuItem['specValueIds']);
|
||||
}
|
||||
return $skuList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据$skuKeys生成规格值id集
|
||||
* @param array $newSpecList
|
||||
* @param array $skuKeys
|
||||
* @return array
|
||||
*/
|
||||
private static function getSpecValueIds(array $newSpecList, array $skuKeys): array
|
||||
{
|
||||
$goodsSkuIdArr = [];
|
||||
foreach ($skuKeys as $skuKey) {
|
||||
$groupItem = helper::arraySearch($newSpecList, 'key', $skuKey['groupKey']);
|
||||
$specValueItem = helper::arraySearch($groupItem['valueList'], 'key', $skuKey['valueKey']);
|
||||
$goodsSkuIdArr[] = $specValueItem['spec_value_id'];
|
||||
}
|
||||
return $goodsSkuIdArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据$skuKeys生成规格属性记录
|
||||
* @param array $newSpecList
|
||||
* @param array $skuKeys
|
||||
* @return array
|
||||
*/
|
||||
private static function getGoodsProps(array $newSpecList, array $skuKeys): array
|
||||
{
|
||||
$goodsPropsArr = [];
|
||||
foreach ($skuKeys as $skuKey) {
|
||||
$groupItem = helper::arraySearch($newSpecList, 'key', $skuKey['groupKey']);
|
||||
$specValueItem = helper::arraySearch($groupItem['valueList'], 'key', $skuKey['valueKey']);
|
||||
$goodsPropsArr[] = [
|
||||
'group' => ['name' => $groupItem['spec_name'], 'id' => $groupItem['spec_id']],
|
||||
'value' => ['name' => $specValueItem['spec_value'], 'id' => $specValueItem['spec_value_id']]
|
||||
];
|
||||
}
|
||||
return $goodsPropsArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param array $newSkuList
|
||||
* @param int $specType
|
||||
* @return array|bool|false
|
||||
*/
|
||||
public static function add(int $goodsId, int $specType = SpecTypeEnum::SINGLE, array $newSkuList = [])
|
||||
{
|
||||
// 单规格模式
|
||||
if ($specType === SpecTypeEnum::SINGLE) {
|
||||
return (new static)->save(array_merge($newSkuList, [
|
||||
'goods_id' => $goodsId,
|
||||
'goods_sku_id' => 0,
|
||||
'store_id' => self::$storeId
|
||||
]));
|
||||
} // 多规格模式
|
||||
elseif ($specType === SpecTypeEnum::MULTI) {
|
||||
// 批量写入商品sku记录
|
||||
return static::increasedFroMulti($goodsId, $newSkuList);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param int $specType
|
||||
* @param array $skuList
|
||||
* @return array|bool|false
|
||||
*/
|
||||
public static function edit(int $goodsId, int $specType = SpecTypeEnum::SINGLE, array $skuList = [])
|
||||
{
|
||||
// 删除所有的sku记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 新增商品sku记录
|
||||
return static::add($goodsId, $specType, $skuList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量写入商品sku记录
|
||||
* @param int $goodsId
|
||||
* @param array $skuList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increasedFroMulti(int $goodsId, array $skuList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($skuList as $skuItem) {
|
||||
$dataset[] = array_merge($skuItem, [
|
||||
'goods_sku_id' => $skuItem['goods_sku_id'],
|
||||
'line_price' => $skuItem['line_price'] ?: 0.00,
|
||||
'goods_sku_no' => $skuItem['goods_sku_no'] ?: '',
|
||||
'stock_num' => $skuItem['stock_num'] ?: 0,
|
||||
'goods_weight' => $skuItem['goods_weight'] ?: 0,
|
||||
'goods_props' => $skuItem['goodsProps'],
|
||||
'spec_value_ids' => $skuItem['specValueIds'],
|
||||
'goods_id' => $goodsId,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\GoodsSpecRel as GoodsSpecRelModel;
|
||||
|
||||
/**
|
||||
* 商品规格关系模型
|
||||
* Class GoodsSpecRel
|
||||
* @package app\store\model
|
||||
*/
|
||||
class GoodsSpecRel extends GoodsSpecRelModel
|
||||
{
|
||||
/**
|
||||
* 批量写入商品与规格值关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $specList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function increased(int $goodsId, array $specList)
|
||||
{
|
||||
$dataset = [];
|
||||
foreach ($specList as $item) {
|
||||
foreach ($item['valueList'] as $specValueItem) {
|
||||
$dataset[] = [
|
||||
'goods_id' => $goodsId,
|
||||
'spec_id' => $item['spec_id'],
|
||||
'spec_value_id' => $specValueItem['spec_value_id'],
|
||||
'store_id' => self::$storeId
|
||||
];
|
||||
}
|
||||
}
|
||||
return (new static)->addAll($dataset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新商品与规格值关系记录
|
||||
* @param int $goodsId
|
||||
* @param array $specList
|
||||
* @return array|false
|
||||
*/
|
||||
public static function updates(int $goodsId, array $specList)
|
||||
{
|
||||
// 删除所有的记录
|
||||
static::deleteAll(['goods_id' => $goodsId]);
|
||||
// 批量新增记录
|
||||
return static::increased($goodsId, $specList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\Help as HelpModel;
|
||||
|
||||
/**
|
||||
* 模型类:帮助中心
|
||||
* Class Help
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Help extends HelpModel
|
||||
{
|
||||
/**
|
||||
* 新增记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
$data['store_id'] = self::$storeId;
|
||||
return $this->save($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param array $data
|
||||
* @return bool|int
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @return bool
|
||||
*/
|
||||
public function setDelete()
|
||||
{
|
||||
return $this->save(['is_delete' => 1]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\service\Home as HomeService;
|
||||
|
||||
/**
|
||||
* 后台首页
|
||||
* Class Home
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Home extends Controller
|
||||
{
|
||||
/**
|
||||
* 后台首页
|
||||
* @return array
|
||||
*/
|
||||
public function data()
|
||||
{
|
||||
// 获取首页数据
|
||||
$model = new HomeService;
|
||||
$data = $model->getData($this->store['user']);
|
||||
return $this->renderSuccess(compact('data'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\api\service\User as UserService;
|
||||
use app\common\library\wechat\Qrcode as WechatQrcodeApi;
|
||||
use app\common\model\wxapp\Setting as WxappSettingModel;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Merchant as MerchantModel;
|
||||
use app\store\model\merchant\MerchantOrder as MerchantOrderModel;
|
||||
use app\store\model\store\User;
|
||||
use cores\exception\BaseException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 商户控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Merchant extends Controller
|
||||
{
|
||||
/**
|
||||
* 商户列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new MerchantModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['name']) && !empty($getData['name'])) {
|
||||
$data[] = ['name', 'like', "%{$getData['name']}%"];
|
||||
}
|
||||
$user = $this->store['user'];
|
||||
/*if($user['is_super'] == 0) {
|
||||
$data[] = ['store_user_id', 'in', User::getScope($user)];
|
||||
}*/
|
||||
if(!empty($user['merchant_id']) && $user['is_super'] == 0){
|
||||
$data[] = function ($query) use ($user) {
|
||||
$query->where('merchant_id', '=', $user['merchant_id'])
|
||||
->whereOr('parent_merchant_id', '=', $user['merchant_id']);
|
||||
};
|
||||
}
|
||||
$list = $model->getList($data)->toArray();
|
||||
$newList = [];
|
||||
$MerchantOrderModel = new MerchantOrderModel();
|
||||
$date = date("Y-m-d");
|
||||
foreach ($list['data'] as $val){
|
||||
$val['day_money'] =$MerchantOrderModel->getOrderTotalPrice($date, $date, $val);
|
||||
$val['total_money'] =$MerchantOrderModel->getOrderTotalPrice(null, null, $val);
|
||||
$newList[] = $val;
|
||||
}
|
||||
$list['data'] = $newList;
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有商户
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$list = MerchantModel::getAll($user);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商户
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new MerchantModel;
|
||||
$data = $this->postForm();
|
||||
// 新增记录
|
||||
if ($model->add($data,$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户详情
|
||||
* @param int $merchantId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $merchantId): Json
|
||||
{
|
||||
$merchantInfo = MerchantModel::detail($merchantId);
|
||||
return $this->renderSuccess(compact('merchantInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商户
|
||||
* @param int $merchantId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $merchantId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = MerchantModel::detail($merchantId);
|
||||
$data = $this->postForm();
|
||||
// 更新记录
|
||||
if ($model->edit($data)) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值
|
||||
* @param int $merchantId
|
||||
* @param string $target
|
||||
* @return array
|
||||
*/
|
||||
public function recharge(int $merchantId, string $target)
|
||||
{
|
||||
// 用户详情
|
||||
$model = MerchantModel::detail($merchantId);
|
||||
if ($model->recharge($target, $this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
$userModel = new User();
|
||||
foreach ((array)$arr as $val){
|
||||
$model = MerchantModel::detail($val);
|
||||
if ($model->setDelete()) {
|
||||
$userModel->where([
|
||||
['level','=',1],
|
||||
['merchant_id','like','%'.$val.'%'],
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推广码
|
||||
* @param int $merchantId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function qrCode(int $merchantId): Json
|
||||
{
|
||||
// 生成二维码
|
||||
try {
|
||||
$file = public_path().'uploads/qrcode/'.$merchantId.'.png';
|
||||
if(!file_exists($file)) {
|
||||
// 小程序配置信息
|
||||
$wxConfig = WxappSettingModel::getWxappConfig();
|
||||
// 请求API数据
|
||||
$WechatQrcodeApi = new WechatQrcodeApi($wxConfig['app_id'], $wxConfig['app_secret']);
|
||||
$data = $WechatQrcodeApi->getQrcode('uid:'.$merchantId, 'pages/category/index'); // pages/index/index
|
||||
|
||||
file_put_contents($file, $data);
|
||||
// $base64Image = base64_encode($data);
|
||||
$this->createShare($merchantId);
|
||||
}
|
||||
$fp = fopen($file,"rb");
|
||||
$gambar = fread($fp,filesize($file));
|
||||
fclose($fp);
|
||||
$base64Image = base64_encode($gambar);
|
||||
// 生成 data URI
|
||||
$dataUri = 'data:image/png;base64,' . $base64Image;
|
||||
// 返回生成的二维码链接
|
||||
return $this->renderSuccess(['data'=>$dataUri]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->renderError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function createShare($merchantId){
|
||||
$model = MerchantModel::detail($merchantId);
|
||||
// 设置路径
|
||||
$bgPath = public_path().'assets/store/img/qrcode/bg.jpg'; // 背景图路径
|
||||
$qrPath = public_path().'uploads/qrcode/'.$merchantId.'.png'; // 小程序二维码路径
|
||||
// $outputPath = public_path().'uploads/qrcode/share_image.jpg'; // 输出路径
|
||||
$text = $model['name']; // 要写入的文字
|
||||
|
||||
// 创建背景图资源
|
||||
$bg = imagecreatefromjpeg($bgPath);
|
||||
|
||||
// 创建二维码图资源(可能是 png)
|
||||
$qr = imagecreatefromjpeg($qrPath); // 如果是 png 用 imagecreatefrompng
|
||||
|
||||
// 获取背景图尺寸
|
||||
$bgWidth = imagesx($bg);
|
||||
$bgHeight = imagesy($bg);
|
||||
|
||||
// 设置二维码尺寸和位置(例如宽高 200px,放在右下角)
|
||||
$qrSize = 200;
|
||||
$qrResized = imagecreatetruecolor($qrSize, $qrSize);
|
||||
imagecopyresampled($qrResized, $qr, 0, 0, 0, 0, $qrSize, $qrSize, imagesx($qr), imagesy($qr));
|
||||
|
||||
// 合并二维码到背景图(右下角,留边距 20px)
|
||||
imagecopy($bg, $qrResized, $bgWidth - $qrSize, $bgHeight - $qrSize, 0, 0, $qrSize, $qrSize);
|
||||
|
||||
// 添加文字(使用 TrueType 字体)
|
||||
$fontPath = public_path().'assets/store/fonts/sourcehansans.otf'; // 微软雅黑等 TTF 字体路径
|
||||
$fontSize = 20; // 字号
|
||||
$fontColor = imagecolorallocate($bg, 255, 255, 255); // 黑色
|
||||
|
||||
// 写文字(底部中间)
|
||||
$textBox = imagettfbbox($fontSize, 0, $fontPath, $text);
|
||||
$textWidth = $textBox[2] - $textBox[0];
|
||||
$textX = (int)(($bgWidth - $textWidth) / 2);
|
||||
$textY = (int)($bgHeight - 20);
|
||||
|
||||
imagettftext($bg, $fontSize, 0, $textX, 60, $fontColor, $fontPath, $text);
|
||||
|
||||
// 保存最终图像
|
||||
imagejpeg($bg, $qrPath, 90);
|
||||
|
||||
// 释放资源
|
||||
imagedestroy($bg);
|
||||
imagedestroy($qr);
|
||||
imagedestroy($qrResized);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代理商发券
|
||||
* @param int $merchantId
|
||||
* @return array
|
||||
*/
|
||||
public function sendCoupon(int $merchantId)
|
||||
{
|
||||
// 用户详情
|
||||
$model = MerchantModel::detail($merchantId);
|
||||
if ($model->sendCoupon($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\enum\merchant\balanceLog\Scene as SceneEnum;
|
||||
use app\common\lock\RedisLock;
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\common\service\SybOil;
|
||||
use app\store\model\Code as CodeModel;
|
||||
use app\store\model\Merchant as MerchantModel;
|
||||
use app\store\model\merchant\BalanceLog as BalanceLogModel;
|
||||
use app\store\model\Notify as NotifyModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\OrderGoods as OrderGoodsModel;
|
||||
use app\store\model\Shop as ShopModel;
|
||||
use app\store\model\store\User;
|
||||
use app\store\model\store\User as UserModel;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\company\BalanceLog as CompanyBalanceLogModel;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
use app\common\enum\order\OrderStatus as OrderStatusEnum;
|
||||
|
||||
|
||||
/**
|
||||
* 订单管理
|
||||
* Class Order
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
/**
|
||||
* 订单列表
|
||||
* @param string $dataType
|
||||
* @return array
|
||||
*/
|
||||
public function list(string $dataType): Json
|
||||
{
|
||||
// 订单列表
|
||||
$model = new OrderModel;
|
||||
$user = $this->store['user'];
|
||||
// $merchant = MerchantModel::getAll($user);
|
||||
$list = $model->getList($dataType, $this->request->param(), $user);
|
||||
$list['dataType'] = $dataType;
|
||||
return $this->renderSuccess($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @param int $orderId
|
||||
* @return array
|
||||
*/
|
||||
public function detail(int $orderId): Json
|
||||
{
|
||||
// 订单详情
|
||||
$model = new OrderModel;
|
||||
if (!$detail = $model->getDetail($orderId)) {
|
||||
return $this->renderError('未找到该订单记录');
|
||||
}
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单砖状态
|
||||
* @return array
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function updatestatus(): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
if(empty($postData['status'])){
|
||||
return $this->renderError('请选择订单状态');
|
||||
}
|
||||
$model = OrderModel::detail($postData['order_id']);
|
||||
$NotifyModel = new NotifyModel();
|
||||
if ($model->updateStatus($postData)) {
|
||||
//已支付订单才进行回调通知
|
||||
if ($postData['status'] == 20) {
|
||||
$codeModel = CodeModel::detail(['code_id'=>$model['old_code_id'],'status'=>1]);
|
||||
if($codeModel['code_id']){
|
||||
$codeModel->modifyUsed($model['order_id']);
|
||||
//写入队列
|
||||
$create_time = is_numeric($codeModel['create_time'])?$codeModel['create_time']:strtotime($codeModel['create_time']);
|
||||
$code_queue = ['code_id' => $codeModel['code_id'], 'expire_time' => $create_time + (float)$codeModel['expiration_time']]; // 过期时间
|
||||
$code_json = json_encode($code_queue,320);
|
||||
Cache::store('redis')->lRem($codeModel['passageway'].'_'.round($codeModel['money'],2), $code_json, 1);
|
||||
}
|
||||
if ($NotifyModel->add($model)) {
|
||||
return $this->renderSuccess('修改成功');
|
||||
} else {
|
||||
return $this->renderError($NotifyModel->getError() ?: '修改失败');
|
||||
}
|
||||
}else{
|
||||
return $this->renderSuccess('修改成功');
|
||||
}
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动回调
|
||||
* @param $order_id
|
||||
* @return array
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function callback(): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
$order_id = $postData['order_id'];
|
||||
$password = $postData['password'];
|
||||
//验证密码
|
||||
$user = UserModel::detail($this->store['user']['store_user_id']);
|
||||
if(!password_verify($password, $user['password'])){
|
||||
return $this->renderError('登录密码错误');
|
||||
}
|
||||
$model = OrderModel::detail($order_id);
|
||||
$NotifyModel = new NotifyModel();
|
||||
if ($NotifyModel->add($model)) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
/** 测试发送数据
|
||||
* @return Json
|
||||
*/
|
||||
public function send(): Json
|
||||
{
|
||||
//Gateway::sendToClient('c0a8008a07d000000002',json_encode(['type' => 'test_send']));
|
||||
Gateway::sendToUid($this->store['user']['store_user_id'], json_encode(['type' => 'test_send']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销分油
|
||||
* @param $order_id
|
||||
* @return array
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function cancelShare(): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
$order_goods_id = $postData['order_goods_id'];
|
||||
$password = $postData['password'];
|
||||
//验证密码
|
||||
$user = UserModel::detail($this->store['user']['store_user_id']);
|
||||
if(!password_verify($password, $user['password'])){
|
||||
return $this->renderError('登录密码错误');
|
||||
}
|
||||
$model = OrderGoodsModel::detail($order_goods_id);
|
||||
if ($model['oil_status'] != 1) {
|
||||
return $this->renderError('该订单状态不是已分油状态');
|
||||
}
|
||||
if ($model['use_status'] != 0) {
|
||||
return $this->renderError('油卡已核销,无法撤销');
|
||||
}
|
||||
$order = OrderModel::detail($model['order_id']);
|
||||
$company = CompanyModel::detail($model['company_id']);
|
||||
// 对接平台接口,撤销分油
|
||||
$res = $this->oilOilCardCancelShare(['shareNo'=>$model['shareNo'],'amount'=>$model['goods_price'],'saleOrderNo'=>$order['order_no'],'type'=>'recovery','oilCardType'=>$model['oilCardType']], $company);
|
||||
if($res['code'] == '00'){
|
||||
if ($model->cancelShare($postData)) {
|
||||
// 更新商户余额(增加)
|
||||
MerchantModel::setIncBalance((int)$model['merchant_id'], (float)$model['goods_price']);
|
||||
BalanceLogModel::add(SceneEnum::REFUND, [
|
||||
'merchant_id' => (int)$model['merchant_id'],
|
||||
'money' => (float)$model['goods_price'],
|
||||
], ['saleOrderNo' => $order['order_no']]);
|
||||
// 更新公司余额(增加)
|
||||
CompanyModel::setIncBalance((int)$model['company_id'], (float)$model['goods_price']);
|
||||
CompanyBalanceLogModel::add(SceneEnum::REFUND, [
|
||||
'company_id' => (int)$model['company_id'],
|
||||
'money' => (float)$model['goods_price'],
|
||||
], ['saleOrderNo' => $order['order_no']]);
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}else{
|
||||
return $this->renderError('平台撤销分油失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCode(): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$orderGoods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
if($orderGoods['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
$company = CompanyModel::detail($orderGoods['company_id']);
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$orderGoods['oilCardNo']], $company);
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$orderGoods['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$orderGoods['goods_price'],
|
||||
'order_id'=>$orderGoods['order_id'],
|
||||
'user_id'=>$orderGoods['user_id'],
|
||||
'store_id'=>$orderGoods['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'qrCode'=>$res['data']['useQrCodeUrl']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError($res['errMessage'] ?? $res['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $goodsNo
|
||||
* @return string
|
||||
*/
|
||||
public function getCompany($goodsNo): string
|
||||
{
|
||||
switch ($goodsNo) {
|
||||
case 'djgdface100':
|
||||
case 'djgdface200':
|
||||
case 'djgdface300':
|
||||
return 'umQZhIHKofyA';
|
||||
case 'jmgxyyface100':
|
||||
case 'jmgxyyface200':
|
||||
case 'jmgxyyface300':
|
||||
|
||||
case 'jmgzface100':
|
||||
case 'jmgzface200':
|
||||
case 'jmgzface300':
|
||||
|
||||
case 'jmfjface100':
|
||||
case 'jmfjface200':
|
||||
case 'jmfjface300':
|
||||
return 'HpWqXIgYvTBg';
|
||||
case 'face003':
|
||||
return 'NKJBgaaRNdiL'; // 测试参数
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function processUserOrders($companyId) {
|
||||
$redisLock = new RedisLock('user_order_lock');
|
||||
$maxAttempts = 10; // 最大尝试次数
|
||||
$attempt = 0;
|
||||
$sleepTime = 500000; // 每次尝试失败后的等待时间(微秒),500000微秒 = 0.5秒
|
||||
|
||||
while ($attempt < $maxAttempts) {
|
||||
$lockAcquired = $redisLock->acquireLock();
|
||||
if ($lockAcquired) {
|
||||
break;
|
||||
}
|
||||
|
||||
$attempt++;
|
||||
usleep($sleepTime); // 等待一段时间再尝试
|
||||
}
|
||||
|
||||
if (!$lockAcquired) {
|
||||
throwError('网络繁忙请稍后');
|
||||
}
|
||||
|
||||
$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
// 查找一个未被调用的用户
|
||||
$account = Db::name('account')
|
||||
->alias('a')
|
||||
->join('company c', 'a.company_id = c.company_id')
|
||||
->where('a.last_called_at', '<', $todayStart)
|
||||
->where('a.is_delete', '=', 0)
|
||||
->where('a.state', '=', 0)
|
||||
->where('a.company_id', '=', $companyId)
|
||||
->where('c.status', '=', 10)
|
||||
->field('a.*')
|
||||
->limit(1)
|
||||
->find();
|
||||
if (!$account) {
|
||||
throwError("没有可用的用户");
|
||||
}
|
||||
// 更新用户的 `last_called_at`
|
||||
Db::name('account')
|
||||
->where('account_id', $account['account_id'])
|
||||
->update(['last_called_at' => time(), 'state' => 1]);
|
||||
|
||||
$redisLock->releaseLock();
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动分油
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function share(): Json
|
||||
{
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$goods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
|
||||
if($goods['oil_status'] != 0){
|
||||
return $this->renderError('已分油');
|
||||
}else {
|
||||
if($goods['oilCardType']) {
|
||||
$data['amount'] = $goods['total_price']; // 金额
|
||||
$company = CompanyModel::detail(['orgNo' => $this->getCompany($goods['goods_no'])]);
|
||||
if (!$company) {
|
||||
return $this->renderError('已分油');
|
||||
}
|
||||
try {
|
||||
// 查找一个未被调用的用户
|
||||
$account = $this->processUserOrders($company['company_id']);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->renderError($e->getMessage());
|
||||
}
|
||||
|
||||
// 查询公司余额
|
||||
/*if ($data['amount'] > $company['balance']) {
|
||||
$this->error = '公司余额不足';
|
||||
return false;
|
||||
}*/
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->oilOilCardShare([
|
||||
'goodsNo'=>$goods['goods_no'],
|
||||
'amount'=>$data['amount'],
|
||||
'userNo'=>$account['userNo'],
|
||||
'mobile'=>$account['mobile'],
|
||||
'saleOrderNo'=>$goods['oilCardNo'],
|
||||
'oilCardType'=>$goods['oilCardType']
|
||||
], $company);
|
||||
//$res = json_decode('{"code":"00","message":"请求成功","errCode":null,"errMessage":null,"data":{"oilCardNo":null,"amount":100,"balance":null,"shareNo":"CDV2408021928160001"}}', true);
|
||||
if ($res['code'] != 1) {
|
||||
return $this->renderError($res['errMessage'] ?? $res['message']);
|
||||
}
|
||||
$IdingjuOil->saveLogStore("分油接口结果".json_encode($res,320));
|
||||
$item['account_id'] = $account['account_id'];
|
||||
$item['userNo'] = $account['userNo'];
|
||||
$item['mobile'] = $account['mobile'];
|
||||
$item['company_id'] = $company['company_id'];
|
||||
$item['shareNo'] = $res['data']['trade_no'] ?? '';
|
||||
$item['qrCode'] = $res['data']['useUrl'] ?? '';
|
||||
$item['oil_status_zsy'] = $res['data']['state'] ?? 0;
|
||||
$item['oil_time'] = time();
|
||||
$item['oil_status'] = $item['oil_status_zsy'] == 2 ? 1 : 0; // 已发券 为1
|
||||
$r = $goods->save($item);
|
||||
$IdingjuOil->saveLogStore("保存分油结果".json_encode($r,320));
|
||||
return $this->renderSuccess('分油成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\OrderAddress as OrderAddressModel;
|
||||
|
||||
/**
|
||||
* 订单收货地址模型
|
||||
* Class OrderAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderAddress extends OrderAddressModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\model\OrderGoods as OrderGoodsModel;
|
||||
|
||||
/**
|
||||
* 订单商品模型
|
||||
* Class OrderGoods
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderGoods extends OrderGoodsModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\User as UserModel;
|
||||
use app\common\model\OrderRefund as OrderRefundModel;
|
||||
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
|
||||
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
|
||||
use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
|
||||
use app\common\service\Message as MessageService;
|
||||
use app\common\service\order\Refund as RefundService;
|
||||
|
||||
/**
|
||||
* 售后单模型
|
||||
* Class OrderRefund
|
||||
* @package app\api\model
|
||||
*/
|
||||
class OrderRefund extends OrderRefundModel
|
||||
{
|
||||
/**
|
||||
* 获取售后单列表
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 检索查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->alias('refund')
|
||||
->field('refund.*, order.order_no')
|
||||
->with(['orderGoods.image', 'orderData', 'user.avatar'])
|
||||
->join('order', 'order.order_id = refund.order_id')
|
||||
->join('user', 'user.user_id = order.user_id')
|
||||
->where($filter)
|
||||
->order(['refund.create_time' => 'desc', 'refund.' . $this->getPk()])
|
||||
->paginate(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取售后单详情
|
||||
* @param int $orderRefundId
|
||||
* @return OrderRefund|false|null
|
||||
*/
|
||||
public function getDetail(int $orderRefundId)
|
||||
{
|
||||
return static::detail($orderRefundId, [
|
||||
'orderData', 'images.file', 'orderGoods.image', 'express', 'address', 'user'
|
||||
]) ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检索查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param = []): array
|
||||
{
|
||||
// 默认查询条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'searchType' => '', // 关键词类型 (10订单号 20会员昵称 30会员ID)
|
||||
'searchValue' => '', // 关键词内容
|
||||
'refundType' => -1, // 售后类型
|
||||
'refundStatus' => -1, // 售后单状态
|
||||
'betweenTime' => [], // 申请时间
|
||||
]);
|
||||
// 检查查询条件
|
||||
$filter = [];
|
||||
// 关键词
|
||||
if (!empty($params['searchValue'])) {
|
||||
$searchWhere = [
|
||||
10 => ['order.order_no', 'like', "%{$params['searchValue']}%"],
|
||||
20 => ['user.nick_name', 'like', "%{$params['searchValue']}%"],
|
||||
30 => ['order.user_id', '=', (int)$params['searchValue']]
|
||||
];
|
||||
array_key_exists($params['searchType'], $searchWhere) && $filter[] = $searchWhere[$params['searchType']];
|
||||
}
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['refund.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['refund.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
// 售后类型
|
||||
$params['refundType'] > -1 && $filter[] = ['refund.type', '=', (int)$params['refundType']];
|
||||
// 处理状态
|
||||
$params['refundStatus'] > -1 && $filter[] = ['refund.status', '=', (int)$params['refundStatus']];
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家审核
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function audit(array $data): bool
|
||||
{
|
||||
if ($data['audit_status'] == AuditStatusEnum::REJECTED && empty($data['refuse_desc'])) {
|
||||
$this->error = '请输入拒绝原因';
|
||||
return false;
|
||||
}
|
||||
if ($data['audit_status'] == AuditStatusEnum::REVIEWED && empty($data['address_id'])) {
|
||||
$this->error = '请选择退货地址';
|
||||
return false;
|
||||
}
|
||||
$this->transaction(function () use ($data) {
|
||||
// 拒绝申请, 标记售后单状态为已拒绝
|
||||
$data['audit_status'] == AuditStatusEnum::REJECTED && $data['status'] = RefundStatusEnum::REJECTED;
|
||||
// 同意换货申请, 标记售后单状态为已完成
|
||||
$data['audit_status'] == AuditStatusEnum::REVIEWED && $this['type'] == RefundTypeEnum::EXCHANGE && $data['status'] = RefundStatusEnum::COMPLETED;
|
||||
// 更新退款单状态
|
||||
$this->save($data);
|
||||
// 同意售后申请, 记录退货地址
|
||||
if ($data['audit_status'] == AuditStatusEnum::REVIEWED) {
|
||||
(new OrderRefundAddress)->add((int)$this['order_refund_id'], (int)$data['address_id']);
|
||||
}
|
||||
// 订单详情
|
||||
$order = Order::detail($this['order_id']);
|
||||
// 发送消息通知
|
||||
MessageService::send('order.refund', [
|
||||
'refund' => $this, // 退款单信息
|
||||
'order_no' => $order['order_no'] // 订单信息
|
||||
], $this['store_id']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货并退款
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function receipt(array $data): bool
|
||||
{
|
||||
// 订单详情
|
||||
$order = Order::detail($this['order_id']);
|
||||
if ($data['refund_money'] > min($order['pay_price'], $this['orderGoods']['total_pay_price'])) {
|
||||
$this->error = '退款金额不能大于商品实付款金额';
|
||||
return false;
|
||||
}
|
||||
// 事务处理
|
||||
$this->transaction(function () use ($order, $data) {
|
||||
// 更新售后单状态
|
||||
$this->save([
|
||||
'refund_money' => $data['refund_money'],
|
||||
'is_receipt' => 1,
|
||||
'status' => RefundStatusEnum::COMPLETED
|
||||
]);
|
||||
// 消减用户的实际消费金额
|
||||
// 条件:判断订单是否已结算
|
||||
if ($order['is_settled'] == true) {
|
||||
(new UserModel)->setDecUserExpend($order['user_id'], $data['refund_money']);
|
||||
}
|
||||
// 执行原路退款
|
||||
(new RefundService)->execute($order, (string)$data['refund_money']);
|
||||
// 发送消息通知
|
||||
MessageService::send('order.refund', [
|
||||
'refund' => $this, // 退款单信息
|
||||
'order_no' => $order['order_no'], // 订单信息
|
||||
], $this['store_id']);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待处理售后单数量
|
||||
* @return int
|
||||
*/
|
||||
public function getRefundTotal()
|
||||
{
|
||||
return $this->where('status', '=', RefundStatusEnum::NORMAL)->count();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\store\Address as AddressModel;
|
||||
use app\common\model\OrderRefundAddress as OrderRefundAddressModel;
|
||||
|
||||
/**
|
||||
* 售后单退货地址模型
|
||||
* Class OrderRefundAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class OrderRefundAddress extends OrderRefundAddressModel
|
||||
{
|
||||
/**
|
||||
* 新增售后单退货地址记录
|
||||
* @param int $orderRefundId
|
||||
* @param int $storeAddressId
|
||||
* @return bool
|
||||
*/
|
||||
public function add(int $orderRefundId, int $storeAddressId)
|
||||
{
|
||||
// 获取地址详情
|
||||
$address = AddressModel::detail($storeAddressId);
|
||||
// 新增退货地址记录
|
||||
return $this->save([
|
||||
'order_refund_id' => $orderRefundId,
|
||||
'name' => $address['name'],
|
||||
'phone' => $address['phone'],
|
||||
'province_id' => $address['province_id'],
|
||||
'city_id' => $address['city_id'],
|
||||
'region_id' => $address['region_id'],
|
||||
'detail' => $address['detail'],
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\OrderRefundImage as OrderRefundImageModel;
|
||||
|
||||
class OrderRefundImage extends OrderRefundImageModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Page as PageModel;
|
||||
|
||||
/**
|
||||
* 店铺页面管理
|
||||
* Class Page
|
||||
* @package app\store\controller\wxapp
|
||||
*/
|
||||
class Page extends Controller
|
||||
{
|
||||
/**
|
||||
* 页面列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new PageModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面设计默认数据
|
||||
* @return array
|
||||
*/
|
||||
public function defaultData()
|
||||
{
|
||||
$model = new PageModel;
|
||||
return $this->renderSuccess([
|
||||
'page' => $model->getDefaultPage(),
|
||||
'items' => $model->getDefaultItems()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面详情
|
||||
* @param int $pageId
|
||||
* @return array
|
||||
*/
|
||||
public function detail(int $pageId)
|
||||
{
|
||||
$detail = PageModel::detail($pageId);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增页面
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new PageModel;
|
||||
if (!$model->add($this->postForm())) {
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑页面
|
||||
* @param int $pageId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $pageId)
|
||||
{
|
||||
$model = PageModel::detail($pageId);
|
||||
if (!$model->edit($this->postForm())) {
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除页面
|
||||
* @param int $pageId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $pageId)
|
||||
{
|
||||
// 帮助详情
|
||||
$model = PageModel::detail($pageId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认首页
|
||||
* @param int $pageId
|
||||
* @return array
|
||||
*/
|
||||
public function setHome(int $pageId)
|
||||
{
|
||||
// 帮助详情
|
||||
$model = PageModel::detail($pageId);
|
||||
if (!$model->setHome()) {
|
||||
return $this->renderError($model->getError() ?: '设置失败');
|
||||
}
|
||||
return $this->renderSuccess('设置成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Partners as PartnersModel;
|
||||
use app\store\model\PartnersGoods as PartnersGoodsModel;
|
||||
use app\store\model\partners\Order as OrderModel;
|
||||
use app\store\model\store\User;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 商户控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Partners extends Controller
|
||||
{
|
||||
/**
|
||||
* 商户列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$model = new PartnersModel;
|
||||
$getData = $this->request->param();
|
||||
$data = [];
|
||||
if (isset($getData['name']) && !empty($getData['name'])) {
|
||||
$data[] = ['name', 'like', "%{$getData['name']}%"];
|
||||
}
|
||||
$user = $this->store['user'];
|
||||
if($user['is_super'] == 0) {
|
||||
$data[] = ['store_user_id', 'in', User::getScope($user)];
|
||||
}
|
||||
/*if(!empty($this->store['user']['partners_id']) && $this->store['user']['is_super'] == 0){
|
||||
$filter[] = ['partners_id', 'in', json_decode($this->store['user']['partners_id'],true)];
|
||||
}*/
|
||||
$list = $model->getList($data)->toArray();
|
||||
$newList = [];
|
||||
$OrderModel = new OrderModel();
|
||||
$date = date("Y-m-d");
|
||||
foreach ($list['data'] as $val){
|
||||
$val['day_money'] =$OrderModel->getOrderTotalPrice($date, $date, $val);
|
||||
$val['total_money'] =$OrderModel->getOrderTotalPrice(null, null, $val);
|
||||
$newList[] = $val;
|
||||
}
|
||||
$list['data'] = $newList;
|
||||
return $this->renderSuccess(['list'=>$list,'user'=>$this->store['user']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有商户
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$list = PartnersModel::getAll($user);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商户
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new PartnersModel;
|
||||
$data = $this->postForm();
|
||||
// 新增记录
|
||||
if ($model->add($data,$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 商户详情
|
||||
* @param int $partnersId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $partnersId): Json
|
||||
{
|
||||
$partnersInfo = PartnersModel::detail($partnersId);
|
||||
// 商品列表
|
||||
$partnersInfo['goodsList'] = PartnersGoodsModel::getGoodsList($partnersInfo['partners_id']);
|
||||
// 给每个元素加上 allot_num
|
||||
foreach ($partnersInfo['goodsList'] as &$item) {
|
||||
$item['allot_num'] = 0; // 默认值,可以改成其他逻辑
|
||||
}
|
||||
unset($item); // 解除引用,避免后续误操作
|
||||
return $this->renderSuccess(compact('partnersInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑商户
|
||||
* @param int $partnersId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $partnersId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = PartnersModel::detail($partnersId);
|
||||
$data = $this->postForm();
|
||||
// 更新记录
|
||||
if ($model->edit($data)) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值
|
||||
* @param int $partnersId
|
||||
* @param string $target
|
||||
* @return array
|
||||
*/
|
||||
public function recharge(int $partnersId, string $target)
|
||||
{
|
||||
// 用户详情
|
||||
$model = PartnersModel::detail($partnersId);
|
||||
if ($model->recharge($target, $this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商户
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
$userModel = new User();
|
||||
foreach ((array)$arr as $val){
|
||||
$model = PartnersModel::detail($val);
|
||||
if ($model->setDelete()) {
|
||||
$userModel->where([
|
||||
['level','=',1],
|
||||
['partners_id','like','%'.$val.'%'],
|
||||
])->delete();
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\store\User as StoreUserModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\api\model\Code as CodeModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use think\facade\Cache;
|
||||
use think\response\Json;
|
||||
use think\facade\Request;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
|
||||
/**
|
||||
* 商家后台认证
|
||||
* Class Passport
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Passport extends Controller
|
||||
{
|
||||
/**
|
||||
* 强制验证当前访问的控制器方法method
|
||||
* 例: [ 'login' => 'POST' ]
|
||||
* @var array
|
||||
*/
|
||||
protected $methodRules = [
|
||||
'login' => 'POST',
|
||||
'logout' => 'POST',
|
||||
];
|
||||
|
||||
/**
|
||||
* 商家用户登录
|
||||
* @return array|bool|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$model = new StoreUserModel;
|
||||
$postData = $this->postData();
|
||||
if (($userInfo = $model->login($postData)) === false) {
|
||||
return $this->renderError($model->getError() ?: '登录失败');
|
||||
}
|
||||
return $this->renderSuccess([
|
||||
'userId' => (int)$userInfo['store_user_id'],
|
||||
'token' => $model->getToken()
|
||||
], '登录成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
* @return array
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
// 清空登录状态
|
||||
StoreUserService::logout();
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
|
||||
public function bindUid()
|
||||
{
|
||||
$postData = $this->postData();
|
||||
$uid = $postData['uid'];
|
||||
$clientId = $postData['client_id'];
|
||||
Gateway::bindUid($clientId, $uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单匹配支付码
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $orderId): Json
|
||||
{
|
||||
$domain = Request::instance()->domain();
|
||||
$order = OrderModel::detail($orderId);
|
||||
// 加锁
|
||||
$lock_key = $orderId . '_lock';
|
||||
while (true) {
|
||||
$lock_success = Cache::store('redis')->setnx($lock_key, 1);
|
||||
if (!$lock_success) {
|
||||
// 锁定失败,说明其他客户端已经在处理该队列了,可以直接返回或者等待一段时间后重试
|
||||
continue;
|
||||
}
|
||||
// 设置锁定过期时间,防止锁定无法释放
|
||||
Cache::store('redis')->expire($lock_key, 20);
|
||||
break;
|
||||
}
|
||||
$update_time = 0;
|
||||
if(empty($order['code_id']) && $order['order_status'] == 10) {
|
||||
/**查询支付码**/
|
||||
$CodeModel = new CodeModel();
|
||||
$codeInfo = $CodeModel->getCodeDetail($order['total_price'], $order['passageway'])->toArray();
|
||||
if (empty($codeInfo['code_id'])) {
|
||||
$order->save([
|
||||
'ip' => Request::instance()->ip(),
|
||||
'buyer_remark' => '分配支付码失败',
|
||||
'update_time' => time(),
|
||||
]);
|
||||
$result = ['money'=>0,'qrcode'=>'','seconds'=>0,'passageway'=>$order['passageway']];
|
||||
return $this->renderSuccess($result,'分配支付码失败');
|
||||
} else {
|
||||
$order->save([
|
||||
'ip' => Request::instance()->ip(),
|
||||
'code_id' => $codeInfo['code_id'],
|
||||
'order_no_sn' => $codeInfo['order_no_sn'],
|
||||
'shop_id' => $codeInfo['shop_id'],
|
||||
'store_user_id' => $codeInfo['store_user_id'],
|
||||
'search_url' => $codeInfo['search_url'],
|
||||
'passageway' => $codeInfo['passageway'],
|
||||
'update_time' => time(),
|
||||
]);
|
||||
}
|
||||
$update_time = time();
|
||||
}elseif($order['code_id']){
|
||||
$codeInfo = CodeModel::detail($order['code_id']);
|
||||
$update_time = is_string($order['update_time'])?(int)strtotime($order['update_time']):$order['update_time'];
|
||||
}
|
||||
// 释放锁定
|
||||
Cache::store('redis')->del($lock_key);
|
||||
|
||||
$seconds = ($update_time+300-time())>0?($update_time+300-time()):0;
|
||||
$qrcode = '';
|
||||
if(isset($codeInfo['code_id']) && $seconds>0 && $order['order_status'] == 10) {
|
||||
if($order['passageway'] == 'WX') {
|
||||
$url = $domain . '/wxScanPng.php';
|
||||
//$aa = str_replace("&", "%26", $codeInfo['link']);
|
||||
//$bb = str_replace("amp;", "", $aa);
|
||||
$qrcode = $url . '?url=' . urlencode(htmlspecialchars_decode($codeInfo['link']));
|
||||
}elseif($order['passageway'] == 'SNZFBH5'){
|
||||
$qrcode = htmlspecialchars_decode($codeInfo['alipay']);
|
||||
}else{
|
||||
//$qrcode = htmlspecialchars_decode($codeInfo['alipay']);
|
||||
$qrcode = "alipays://platformapi/startapp?appId=20000067&url=".urlencode(htmlspecialchars_decode($codeInfo['alipay']));
|
||||
}
|
||||
}
|
||||
|
||||
$result = ['money'=>$order['total_price'],'qrcode'=>$qrcode,'seconds'=>$seconds,'passageway'=>$order['passageway']];
|
||||
return $this->renderSuccess($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单点击支付次数
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function clickNum(int $orderId): Json
|
||||
{
|
||||
$order = OrderModel::detail($orderId);
|
||||
if(!empty($order['code_id'])) {
|
||||
$order->save(['click'=>(int)$order['click']+1]);
|
||||
}
|
||||
return $this->renderSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Region as RegionModel;
|
||||
|
||||
/**
|
||||
* 地区管理
|
||||
* Class Region
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Region extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取所有地区
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$list = RegionModel::getCacheAll();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有地区(树状)
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function tree()
|
||||
{
|
||||
$list = RegionModel::getCacheTree();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Setting as SettingModel;
|
||||
use app\common\library\sms\Driver as SmsDriver;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 系统设置
|
||||
* Class Setting
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Setting extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取设置项
|
||||
* @param string $key
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function detail(string $key): Json
|
||||
{
|
||||
$values = SettingModel::getItem($key);
|
||||
return $this->renderSuccess(compact('values'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新系统设置
|
||||
* @param string $key
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function update(string $key): Json
|
||||
{
|
||||
// 保存商城设置
|
||||
$model = new SettingModel;
|
||||
if ($model->edit($key, $this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\model\store\Setting as SettingModel;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\User;
|
||||
use app\store\model\Shop as ShopModel;
|
||||
use app\common\exception\BaseException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 店铺控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Shop extends Controller
|
||||
{
|
||||
/**
|
||||
* 店铺列表
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index(): Json
|
||||
{
|
||||
$model = new ShopModel;
|
||||
$list = $model->getList($this->request->param(), $this->store['user']);
|
||||
$user = $this->store['user'];
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function getAdmin(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$admin = User::getAll($user);
|
||||
return $this->renderSuccess(compact('admin','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有店铺
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function all(): Json
|
||||
{
|
||||
$list = ShopModel::getAll($this->store['user']);
|
||||
$expiration_time = SettingModel::getItem('trade')['expiration_time'];
|
||||
return $this->renderSuccess(compact('list','expiration_time'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加店铺
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new ShopModel;
|
||||
// 新增记录
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 店铺详情
|
||||
* @param int $shopId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $shopId): Json
|
||||
{
|
||||
$shopInfo = ShopModel::detail($shopId);
|
||||
return $this->renderSuccess(compact('shopInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑店铺
|
||||
* @param int $shopId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $shopId): Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = ShopModel::detail($shopId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除店铺
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delete(): Json
|
||||
{
|
||||
$arr = $this->postData();
|
||||
$model = new ShopModel();
|
||||
if (!$model->update(['is_delete' => 1],[['shop_id','in',$arr]])) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
/*// 管理员详情
|
||||
$model = ShopModel::detail($shop_id);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改店铺列表状态
|
||||
* @return Json
|
||||
*/
|
||||
public function changeState(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$status = $post['state']?1:2;
|
||||
// 商品详情
|
||||
foreach ((array)$post['shopIds'] as $shop_id) {
|
||||
$model = ShopModel::detail($shop_id);
|
||||
$warn = $model->changeStatus($status);
|
||||
if ($warn !== true) {
|
||||
return $this->renderError($warn);
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改收款金额
|
||||
* @param int $shopId
|
||||
* @return Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function updateMoney($shopId): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$model = ShopModel::detail($shopId);
|
||||
if ($model->updateMoney($postData)) {
|
||||
return $this->renderSuccess('修改成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '修改失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\Spec as SpecModel;
|
||||
use app\store\model\SpecValue as SpecValueModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 规格组模型
|
||||
* Class Spec
|
||||
* @package app\store\model
|
||||
*/
|
||||
class Spec extends SpecModel
|
||||
{
|
||||
/**
|
||||
* 验证规格值是否合法
|
||||
* @param array $specList
|
||||
* @throws BaseException
|
||||
*/
|
||||
public static function checkSpecData(array $specList)
|
||||
{
|
||||
foreach ($specList as $item) {
|
||||
$values = helper::getArrayColumn($item['valueList'], 'spec_value');
|
||||
if (count($item['valueList']) != count(array_unique($values))) {
|
||||
throwError('很抱歉,不能存在重复的规格值 请检查您的输入');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规格组写入数据库并生成id
|
||||
* 此时的$specList是用户端传来的
|
||||
* @param array $specList
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function getNewSpecList(array $specList): array
|
||||
{
|
||||
// 规格组名称合集
|
||||
$names = helper::getArrayColumn($specList, 'spec_name');
|
||||
// 获取到已存在的规格组
|
||||
$alreadyData = static::getListByNames($names);
|
||||
// 遍历整理新的规格集
|
||||
foreach ($specList as $key => &$item) {
|
||||
$alreadyItem = helper::getArrayItemByColumn($alreadyData, 'spec_name', $item['spec_name']);
|
||||
if (!empty($alreadyItem)) {
|
||||
// 规格名已存在的记录spec_id
|
||||
$item['spec_id'] = $alreadyItem['spec_id'];
|
||||
} else {
|
||||
// 规格名不存在的新增记录
|
||||
$result = static::add($item);
|
||||
$item['spec_id'] = $result['spec_id'];
|
||||
}
|
||||
// 规格值写入数据库并生成id
|
||||
$item['valueList'] = SpecValueModel::getNewValueList((int)$item['spec_id'], $item['valueList']);
|
||||
}
|
||||
return $specList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增规格组记录
|
||||
* @param array $item
|
||||
* @return static|\think\Model
|
||||
*/
|
||||
private static function add(array $item)
|
||||
{
|
||||
// 拿到所有的规格组名称集
|
||||
// 获取到已存在的
|
||||
return self::create([
|
||||
'spec_name' => $item['spec_name'],
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规格组名称集获取列表
|
||||
* @param array $names
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private static function getListByNames(array $names): \think\Collection
|
||||
{
|
||||
return (new static)->where('spec_name', 'in', $names)->select();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\library\helper;
|
||||
use app\common\model\SpecValue as SpecValueModel;
|
||||
|
||||
/**
|
||||
* 规格/属性(值)模型
|
||||
* Class SpecValue
|
||||
* @package app\store\model
|
||||
*/
|
||||
class SpecValue extends SpecValueModel
|
||||
{
|
||||
/**
|
||||
* 规格值写入数据库并生成id
|
||||
* @param int $specId
|
||||
* @param array $valueList
|
||||
* @return array
|
||||
*/
|
||||
public static function getNewValueList(int $specId, array $valueList)
|
||||
{
|
||||
// 规格组名称合集
|
||||
$values = helper::getArrayColumn($valueList, 'spec_value');
|
||||
// 获取到已存在的规格值
|
||||
$alreadyData = static::getListByValues($specId, $values);
|
||||
// 遍历整理新的规格集
|
||||
foreach ($valueList as $key => &$item) {
|
||||
$alreadyItem = helper::getArrayItemByColumn($alreadyData, 'spec_value', $item['spec_value']);
|
||||
if (!empty($alreadyItem)) {
|
||||
// 规格值已存在的记录spec_value_id
|
||||
$item['spec_value_id'] = $alreadyItem['spec_value_id'];
|
||||
} else {
|
||||
// 规格值不存在的新增记录
|
||||
$result = static::add($specId, $item);
|
||||
$item['spec_value_id'] = $result['spec_value_id'];
|
||||
}
|
||||
}
|
||||
return $valueList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增规格组记录
|
||||
* @param int $specId
|
||||
* @param array $item
|
||||
* @return Spec|\think\Model
|
||||
*/
|
||||
private static function add(int $specId, array $item)
|
||||
{
|
||||
return self::create([
|
||||
'spec_value' => $item['spec_value'],
|
||||
'spec_id' => $specId,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据规格组名称集获取列表
|
||||
* @param int $specId
|
||||
* @param array $values
|
||||
* @return \think\Collection
|
||||
*/
|
||||
private static function getListByValues(int $specId, array $values)
|
||||
{
|
||||
return (new static)->where('spec_id', '=', $specId)
|
||||
->where('spec_value', 'in', $values)
|
||||
->select();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Store as StoreModel;
|
||||
|
||||
/**
|
||||
* 商家中心控制器
|
||||
* Class Store
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Store extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取当前登录的商城信息
|
||||
* @return array
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
// 商城详情
|
||||
$model = StoreModel::detail($this->getStoreId());
|
||||
return $this->renderSuccess(['storeInfo' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商城信息
|
||||
* @return array
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
// 商城详情
|
||||
$model = StoreModel::detail($this->getStoreId());
|
||||
// 更新记录
|
||||
if (!$model->edit($this->postForm())) {
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\store\model\Setting as SettingModel;
|
||||
use app\store\model\UploadFile as UploadFileModel;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
use app\common\enum\file\FileType as FileTypeEnum;
|
||||
use app\common\library\storage\Driver as StorageDriver;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 文件库管理
|
||||
* Class Upload
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Upload extends Controller
|
||||
{
|
||||
// 当前商城的上传设置
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
// 存储配置信息
|
||||
$this->config = SettingModel::getItem(SettingEnum::STORAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片上传接口
|
||||
* @param int $groupId 分组ID
|
||||
* @return Json
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function image(int $groupId = 0): Json
|
||||
{
|
||||
// 实例化存储驱动
|
||||
$storage = new StorageDriver($this->config);
|
||||
// 设置上传文件的信息
|
||||
$storage->setUploadFile('iFile')
|
||||
->setRootDirName((string)$this->storeId)
|
||||
->setValidationScene('image');
|
||||
// 执行文件上传
|
||||
if (!$storage->upload()) {
|
||||
return $this->renderError('图片上传失败:' . $storage->getError());
|
||||
}
|
||||
// 文件信息
|
||||
$fileInfo = $storage->getSaveFileInfo();
|
||||
// 添加文件库记录
|
||||
$model = new UploadFileModel;
|
||||
$model->add($fileInfo, FileTypeEnum::IMAGE, $groupId);
|
||||
// 图片上传成功
|
||||
return $this->renderSuccess(['fileInfo' => $model->toArray()], '图片上传成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 视频上传接口
|
||||
* @param int $groupId 分组ID
|
||||
* @return Json
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function video(int $groupId = 0): Json
|
||||
{
|
||||
// 实例化存储驱动
|
||||
$storage = new StorageDriver($this->config);
|
||||
// 设置上传文件的信息
|
||||
$storage->setUploadFile('iFile')
|
||||
->setRootDirName((string)$this->storeId)
|
||||
->setValidationScene('video');
|
||||
// 执行文件上传
|
||||
if (!$storage->upload()) {
|
||||
return $this->renderError('视频上传失败:' . $storage->getError());
|
||||
}
|
||||
// 文件信息
|
||||
$fileInfo = $storage->getSaveFileInfo();
|
||||
// 添加文件库记录
|
||||
$model = new UploadFileModel;
|
||||
$model->add($fileInfo, FileTypeEnum::VIDEO, $groupId);
|
||||
// 图片上传成功
|
||||
return $this->renderSuccess(['fileInfo' => $model->toArray()], '视频上传成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\Setting as SettingModel;
|
||||
use app\common\model\UploadFile as UploadFileModel;
|
||||
use app\common\library\storage\Driver as StorageDriver;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
use app\common\enum\file\Storage as StorageEnum;
|
||||
|
||||
/**
|
||||
* 文件库模型
|
||||
* Class UploadFile
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UploadFile extends UploadFileModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return \think\Paginator
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getList(array $param = []): \think\Paginator
|
||||
{
|
||||
// 商品列表获取条件
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'fileType' => -1, // 文件类型(-1全部 10图片 20附件 30视频)
|
||||
'groupId' => -1, // 分组ID(-1全部 0未分组)
|
||||
'fileName' => '', // 文件名称
|
||||
'storage' => '', // 存储方式(StorageEnum)
|
||||
'channel' => -1, // 上传来源(-1全部 10商户后台 20用户端)
|
||||
'isRecycle' => false // 是否在回收站
|
||||
]);
|
||||
// 查询对象
|
||||
$query = $this->getNewQuery();
|
||||
// 文件分组
|
||||
$params['groupId'] > -1 && $query->where('group_id', '=', (int)$params['groupId']);
|
||||
// 文件类型
|
||||
$params['fileType'] > -1 && $query->where('file_type', '=', (int)$params['fileType']);
|
||||
// 存储方式
|
||||
!empty($params['storage']) && $query->where('storage', '=', $params['storage']);
|
||||
// 上传来源
|
||||
$params['channel'] > -1 && $query->where('channel', '=', (int)$params['channel']);
|
||||
// 文件名称
|
||||
!empty($params['fileName']) && $query->where('file_name', 'like', "%{$params['fileName']}%");
|
||||
// 是否在回收站
|
||||
$query->where('is_recycle', '=', (int)$params['isRecycle']);
|
||||
// 查询列表数据
|
||||
return $query->where('channel', '=', 10)
|
||||
->where('is_delete', '=', 0)
|
||||
->order(['file_id' => 'desc'])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移入|移出回收站
|
||||
* @param bool $isRecycle
|
||||
* @return bool|false
|
||||
*/
|
||||
public function setRecycle(bool $isRecycle = true): bool
|
||||
{
|
||||
return $this->save(['is_recycle' => (int)$isRecycle]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件(批量)
|
||||
* @param array $fileIds 文件ID集
|
||||
* @return bool
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setDelete(array $fileIds): bool
|
||||
{
|
||||
// 验证文件数量
|
||||
if (count($fileIds) > 15) {
|
||||
$this->error = '一次性最多删除15个文件';
|
||||
return false;
|
||||
}
|
||||
// 存储配置信息
|
||||
$config = SettingModel::getItem(SettingEnum::STORAGE);
|
||||
foreach ($fileIds as $fileId) {
|
||||
// 获取文件详情
|
||||
$fileInfo = static::detail($fileId);
|
||||
// 实例化存储驱动
|
||||
$storage = new StorageDriver($config, $fileInfo['storage']);
|
||||
// 删除文件
|
||||
if (!$storage->delete($fileInfo['file_path'])) {
|
||||
$this->error = '文件删除失败:' . $storage->getError();
|
||||
return false;
|
||||
}
|
||||
// 标记为已删除
|
||||
$fileInfo->save(['is_delete' => 1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量移动文件分组
|
||||
* @param int $groupId
|
||||
* @param array $fileIds
|
||||
* @return bool
|
||||
*/
|
||||
public function moveGroup(int $groupId, array $fileIds): bool
|
||||
{
|
||||
return static::updateBase(['group_id' => $groupId], [['file_id', 'in', $fileIds]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文件库记录
|
||||
* @param array $data
|
||||
* @param int $fileType
|
||||
* @param int $groupId
|
||||
* @return bool|false
|
||||
*/
|
||||
public function add(array $data, int $fileType, int $groupId = 0): bool
|
||||
{
|
||||
return $this->save([
|
||||
'group_id' => $groupId > 0 ? (int)$groupId : 0,
|
||||
'channel' => 10,
|
||||
'storage' => $data['storage'],
|
||||
'domain' => $data['domain'],
|
||||
'file_name' => $data['file_name'],
|
||||
'file_path' => $data['file_path'],
|
||||
'file_size' => $data['file_size'],
|
||||
'file_ext' => $data['file_ext'],
|
||||
'file_type' => $fileType,
|
||||
'store_id' => self::$storeId
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
public function edit(array $data): bool
|
||||
{
|
||||
return $this->allowField(['file_name', 'group_id'])->save($data) !== false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\store\model\UploadFile as UploadFileModel;
|
||||
use app\common\model\UploadGroup as UploadGroupModel;
|
||||
|
||||
/**
|
||||
* 文件库分组模型
|
||||
* Class UploadGroup
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UploadGroup extends UploadGroupModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$list = $this->getAll();
|
||||
return $this->getTreeData($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有分组
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getAll()
|
||||
{
|
||||
return $this->order(['sort', 'create_time'])->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取树状列表
|
||||
* @param $list
|
||||
* @param int $parentId
|
||||
* @return array
|
||||
*/
|
||||
private function getTreeData(&$list, int $parentId = 0)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($list as $key => $item) {
|
||||
if ($item['parent_id'] == $parentId) {
|
||||
$children = $this->getTreeData($list, $item['group_id']);
|
||||
!empty($children) && $item['children'] = $children;
|
||||
$data[] = $item;
|
||||
unset($list[$key]);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加新记录
|
||||
* @param array $data
|
||||
* @return false|int
|
||||
*/
|
||||
public function add(array $data)
|
||||
{
|
||||
return $this->save(array_merge([
|
||||
'store_id' => self::$storeId,
|
||||
'sort' => 100
|
||||
], $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(array $data)
|
||||
{
|
||||
// 判断上级分组是否为当前子级
|
||||
if ($data['parent_id'] > 0) {
|
||||
// 获取所有上级id集
|
||||
$parentIds = $this->getTopGroupIds($data['parent_id']);
|
||||
if (in_array($this['group_id'], $parentIds)) {
|
||||
$this->error = '上级分组不允许设置为当前子分组';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return $this->save($data) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有上级id集
|
||||
* @param int $groupId
|
||||
* @param null|array $list
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function getTopGroupIds(int $groupId, $list = null)
|
||||
{
|
||||
static $parentIds = [];
|
||||
is_null($list) && $list = $this->getAll();
|
||||
foreach ($list as $item) {
|
||||
if ($item['group_id'] == $groupId && $item['parent_id'] > 0) {
|
||||
$parentIds[] = $item['parent_id'];
|
||||
$this->getTopGroupIds($item['parent_id'], $list);
|
||||
}
|
||||
}
|
||||
return $parentIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品分组
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
// 判断是否存在下级分组
|
||||
if (static::detail(['parent_id' => $this['group_id']])) {
|
||||
$this->error = '当前分组下存在子分组,不允许删除';
|
||||
return false;
|
||||
}
|
||||
// 更新该分组下的所有文件
|
||||
UploadFileModel::updateBase(['group_id' => 0], ['group_id' => $this['group_id']]);
|
||||
// 删除分组记录
|
||||
return $this->delete();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
|
||||
use app\common\service\Order as OrderService;
|
||||
use app\common\service\SybOil;
|
||||
use app\store\model\Merchant as MerchantModel;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\company\BalanceLog as CompanyBalanceLogModel;
|
||||
use app\store\model\User as UserModel;
|
||||
use app\store\model\user\BalanceLog as BalanceLogModel;
|
||||
use app\store\model\Order as OrderModel;
|
||||
use app\store\model\Goods as GoodsModel;
|
||||
use think\response\Json;
|
||||
use think\Exception;
|
||||
|
||||
use app\common\enum\merchant\balanceLog\Scene as SceneEnum;
|
||||
use app\common\lock\RedisLock;
|
||||
use think\facade\Db;
|
||||
|
||||
use app\console\service\Order as OrderServiceNew;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
* Class User
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class User extends Controller
|
||||
{
|
||||
/**
|
||||
* 用户列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
/*
|
||||
$service = new OrderServiceNew;
|
||||
$service->deliveryEvent($this->storeId);
|
||||
print_r('111');*/
|
||||
// 用户列表
|
||||
$model = new UserModel;
|
||||
$list = $model->getList($this->request->param(), $this->store['user']);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
* @return array|mixed
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$model = new UserModel;
|
||||
$data = $this->postForm();
|
||||
if (empty($data['company_id'])) {
|
||||
return $this->renderError('请填写分油公司');
|
||||
}
|
||||
if (empty($data['merchant_id'])) {
|
||||
return $this->renderError('请填写商户');
|
||||
}
|
||||
if (empty($data['userType'])) {
|
||||
return $this->renderError('请填写用户角色');
|
||||
}
|
||||
if (empty($data['userName'])) {
|
||||
return $this->renderError('请填写用户姓名');
|
||||
}
|
||||
if (empty($data['mobile'])) {
|
||||
return $this->renderError('请填写用户手机号');
|
||||
}
|
||||
if (empty($data['userIdCard'])) {
|
||||
return $this->renderError('请填写用户身份证号');
|
||||
}
|
||||
|
||||
$company = CompanyModel::detail($data['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $this->userOptAdd(['mobile'=>$data['mobile'],'userName'=>$data['userName'],'userIdCard'=>$data['userIdCard'],'userType'=>$data['userType']], $company);
|
||||
if($res['code'] == '00' && isset($res['data']['userNo'])){
|
||||
$data['userNo'] = $res['data']['userNo'];
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
// 新增记录
|
||||
if ($model->add($data,$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户详情
|
||||
* @param int $userId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $userId): Json
|
||||
{
|
||||
$userInfo = UserModel::detail($userId);
|
||||
return $this->renderSuccess(compact('userInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑用户
|
||||
* @param int $userId
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function edit(int $userId): Json
|
||||
{
|
||||
$model = UserModel::detail($userId);
|
||||
$data = $this->postForm();
|
||||
// 更新记录
|
||||
if ($model->edit($data)) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param int $userId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $userId)
|
||||
{
|
||||
// 用户详情
|
||||
$model = UserModel::detail($userId);
|
||||
if ($model->setDelete()) {
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
|
||||
public function processUserOrders() {
|
||||
$redisLock = new RedisLock('user_order_lock');
|
||||
$maxAttempts = 10; // 最大尝试次数
|
||||
$attempt = 0;
|
||||
$sleepTime = 500000; // 每次尝试失败后的等待时间(微秒),500000微秒 = 0.5秒
|
||||
|
||||
while ($attempt < $maxAttempts) {
|
||||
$lockAcquired = $redisLock->acquireLock();
|
||||
if ($lockAcquired) {
|
||||
break;
|
||||
}
|
||||
|
||||
$attempt++;
|
||||
usleep($sleepTime); // 等待一段时间再尝试
|
||||
}
|
||||
|
||||
if (!$lockAcquired) {
|
||||
throw new Exception("网络繁忙请稍后");
|
||||
}
|
||||
|
||||
//$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
// 查找一个未被调用的用户
|
||||
$account = Db::name('account')
|
||||
->alias('a')
|
||||
->join('company c', 'a.company_id = c.company_id')
|
||||
->where('a.last_called_at', '=', 0)
|
||||
->where('c.status', '=', 10)
|
||||
->field('a.*')
|
||||
->limit(1)
|
||||
->find();
|
||||
if (!$account) {
|
||||
throw new Exception("没有可用的用户");
|
||||
}
|
||||
// 更新用户的 `last_called_at`
|
||||
Db::name('account')
|
||||
->where('account_id', $account['account_id'])
|
||||
->update(['last_called_at' => time()]);
|
||||
|
||||
$redisLock->releaseLock();
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户分油
|
||||
* @param int $userId
|
||||
* @param string $target
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function oil(int $userId, string $target)
|
||||
{
|
||||
$data = $this->postForm();
|
||||
$user = UserModel::detail($userId);
|
||||
$data['amount'] = $data['amount']??0;
|
||||
$data['goodsNo'] = $data['goodsNo']??'';
|
||||
// 用户详情
|
||||
$model = new OrderModel();
|
||||
if (empty($data['oilCardType'])) {
|
||||
return $this->renderError('请填写卡券类型');
|
||||
}
|
||||
if ($data['oilCardType'] == 'card' && empty($data['amount'])) {
|
||||
return $this->renderError('请填写分油金额');
|
||||
}
|
||||
if ($data['oilCardType'] != 'card' && empty($data['goods_id'])) {
|
||||
return $this->renderError('请选择油券');
|
||||
}
|
||||
if($data['goods_id']) {
|
||||
$goods = GoodsModel::detail($data['goods_id']);
|
||||
$data['goodsNo'] = $goods['goods_no'];
|
||||
$data['amount'] = $goods['goods_price_max']; // 金额
|
||||
}
|
||||
// 查询用户余额
|
||||
if($data['amount'] > $user['balance']){
|
||||
return $this->renderError('用户余额不足');
|
||||
}
|
||||
$saleOrderNo = OrderService::createOrderNo();
|
||||
try {
|
||||
// 查找一个未被调用的用户
|
||||
$account = $this->processUserOrders();
|
||||
} catch (Exception $e) {
|
||||
return $this->renderError($e->getMessage());
|
||||
}
|
||||
$company = CompanyModel::detail($account['company_id']);
|
||||
// 查询公司余额
|
||||
if($data['amount'] > $company['balance']){
|
||||
return $this->renderError('公司余额不足');
|
||||
}
|
||||
$SybOil = new SybOil();
|
||||
// 对接平台接口
|
||||
$res = $SybOil->oilOilCardShare(['goodsNo'=>$data['goodsNo'],'amount'=>$data['amount'],'userNo'=>$account['userNo'],'mobile'=>$account['mobile'],'saleOrderNo'=>$saleOrderNo,'oilCardType'=>$data['oilCardType']], $company);
|
||||
//$res = json_decode('{"code":"00","message":"请求成功","errCode":null,"errMessage":null,"data":{"oilCardNo":null,"amount":100,"balance":null,"shareNo":"CDV2407271355570001"}}',true);
|
||||
if($res['code'] == '00'){
|
||||
$data['saleOrderNo'] = $saleOrderNo;
|
||||
$data['oilCardNo'] = $data['oilCardType'] == 'zsy_ticket' ? $res['data']['shareNo'] : $res['data']['oilCardNo'];
|
||||
$data['amount'] = $res['data']['amount'];
|
||||
$data['shareNo'] = $res['data']['shareNo'] ?? '';
|
||||
$data['company_id'] = $account['company_id'];
|
||||
$data['account_id'] = $account['account_id'];
|
||||
$data['userNo'] = $account['userNo'];
|
||||
$data['mobile'] = $account['mobile'];
|
||||
}else{
|
||||
return $this->renderError('平台分油失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
$data['user_id'] = $user['user_id'];
|
||||
$data['store_id'] = $user['store_id'];
|
||||
$data['payType'] = 10;
|
||||
if ($model->addOil($data)) {
|
||||
// 更新用户余额
|
||||
UserModel::setDecBalance((int)$user['user_id'], (float)$data['amount']);
|
||||
BalanceLogModel::add(SceneEnum::CONSUME, [
|
||||
'user_id' => (int)$user['user_id'],
|
||||
'money' => -(float)$data['amount'],
|
||||
], ['saleOrderNo' => $saleOrderNo]);
|
||||
// 累积用户总消费金额
|
||||
UserModel::setIncPayMoney($user['user_id'], (float)$data['amount']);
|
||||
|
||||
// 更新公司余额
|
||||
CompanyModel::setDecBalance((int)$user['company_id'], (float)$data['amount']);
|
||||
CompanyBalanceLogModel::add(SceneEnum::CONSUME, [
|
||||
'company_id' => (int)$user['company_id'],
|
||||
'money' => -(float)$data['amount'],
|
||||
], ['saleOrderNo' => $saleOrderNo]);
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户充值
|
||||
* @param int $userId
|
||||
* @param string $target
|
||||
* @return array
|
||||
*/
|
||||
public function recharge(int $userId, string $target)
|
||||
{
|
||||
// 用户详情
|
||||
$model = UserModel::detail($userId);
|
||||
if ($model->recharge($target, $this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员等级
|
||||
* @param int $userId
|
||||
* @return array
|
||||
*/
|
||||
public function grade(int $userId)
|
||||
{
|
||||
// 用户详情
|
||||
$model = UserModel::detail($userId);
|
||||
if ($model->updateGrade($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有商户
|
||||
* @return mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function merchant(): Json
|
||||
{
|
||||
$user = $this->store['user'];
|
||||
$list = MerchantModel::getAll($user);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserAddress as UserAddressModel;
|
||||
|
||||
/**
|
||||
* 用户收货地址模型
|
||||
* Class UserAddress
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserAddress extends UserAddressModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserCoupon as UserCouponModel;
|
||||
|
||||
/**
|
||||
* 用户优惠券模型
|
||||
* Class UserCoupon
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserCoupon extends UserCouponModel
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @param array $param
|
||||
* @return mixed
|
||||
*/
|
||||
public function getList(array $param = [])
|
||||
{
|
||||
// 设置查询条件
|
||||
$filter = $this->getFilter($param);
|
||||
// 获取列表数据
|
||||
return $this->with(['user.avatar'])
|
||||
->alias('m')
|
||||
->field('m.*')
|
||||
->join('user', 'user.user_id = m.user_id')
|
||||
->where($filter)
|
||||
->order(['m.create_time' => 'desc', $this->getPk()])
|
||||
->paginate(15);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
private function getFilter(array $param): array
|
||||
{
|
||||
// 设置默认的检索数据
|
||||
$params = $this->setQueryDefaultValue($param, [
|
||||
'userId' => 0, // 会员ID
|
||||
'couponName' => '', // 优惠券名称
|
||||
'nickName' => '', // 会员昵称
|
||||
'betweenTime' => [], // 起止时间
|
||||
]);
|
||||
// 检索查询条件
|
||||
$filter = [];
|
||||
// 用户ID
|
||||
$params['userId'] > 0 && $filter[] = ['m.user_id', '=', $params['userId']];
|
||||
// 会员昵称
|
||||
!empty($params['couponName']) && $filter[] = ['m.name', 'like', "%{$params['couponName']}%"];
|
||||
// 会员昵称
|
||||
!empty($params['nickName']) && $filter[] = ['user.nick_name', 'like', "%{$params['nickName']}%"];
|
||||
// 起止时间
|
||||
if (!empty($params['betweenTime'])) {
|
||||
$times = between_time($params['betweenTime']);
|
||||
$filter[] = ['m.create_time', '>=', $times['start_time']];
|
||||
$filter[] = ['m.create_time', '<', $times['end_time'] + 86400];
|
||||
}
|
||||
return $filter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\model;
|
||||
|
||||
use app\common\model\UserOauth as UserOauthModel;
|
||||
|
||||
/**
|
||||
* 模型类:第三方用户信息
|
||||
* Class UserOauth
|
||||
* @package app\store\model
|
||||
*/
|
||||
class UserOauth extends UserOauthModel
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller;
|
||||
use think\facade\Db;
|
||||
use think\worker\Server;
|
||||
use Workerman\Lib\Timer;
|
||||
define('HEARTBEAT_TIME', 20);// 心跳间隔55秒
|
||||
class Worker extends Server
|
||||
{
|
||||
protected $socket = 'websocket://0.0.0.0:2345';
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->onMessage();
|
||||
// 或者这样调用
|
||||
$this->worker->onWorkerStart = function($worker)
|
||||
{
|
||||
echo "Worker starting...\n";
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 收到信息
|
||||
* @param $connection
|
||||
* @param $data
|
||||
*/
|
||||
public function onMessage()
|
||||
{
|
||||
$this->worker->onMessage = function($connection, $data)
|
||||
{
|
||||
dump('参数:'.$data.'时间:'.date('Y-m-d H:i:s',time()));
|
||||
$connection->send($data);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\card;
|
||||
|
||||
use think\response\Json;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\card\CardPrint as CardPrintModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 实体卡打印下载控制器
|
||||
* Class CardPrint
|
||||
* @package app\store\controller\order
|
||||
*/
|
||||
class CardPrint extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单导出记录
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new CardPrintModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改打印记录下载状态
|
||||
* @return Json
|
||||
*/
|
||||
public function changeState(): Json
|
||||
{
|
||||
$post = $this->postData();
|
||||
$is_download = $post['state']?1:0;
|
||||
// 商品详情
|
||||
foreach ((array)$post['printIds'] as $print_id) {
|
||||
$model = CardPrintModel::detail($print_id);
|
||||
if (!$model->changeStatus($is_download)) {
|
||||
return $this->renderError('修改状态失败');
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess($post);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\client\h5;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\h5\Setting as SettingModel;
|
||||
|
||||
/**
|
||||
* H5端基本设置
|
||||
* Class Setting
|
||||
* @package app\store\controller\apps\wxapp
|
||||
*/
|
||||
class Setting extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取H5端设置 (指定)
|
||||
* @param string $key
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function detail(string $key): \think\response\Json
|
||||
{
|
||||
$detail = SettingModel::getItem($key);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设置项
|
||||
* @param string $key
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update(string $key): \think\response\Json
|
||||
{
|
||||
$model = new SettingModel;
|
||||
if ($model->edit($key, $this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\client\wxapp;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\wxapp\Setting as SettingModel;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 微信小程序设置
|
||||
* Class Setting
|
||||
* @package app\store\controller\apps\wxapp
|
||||
*/
|
||||
class Setting extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取微信小程序设置 (指定)
|
||||
* @param string $key
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function detail(string $key): Json
|
||||
{
|
||||
$detail = SettingModel::getItem($key);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新设置项
|
||||
* @param string $key
|
||||
* @return Json
|
||||
*/
|
||||
public function update(string $key): Json
|
||||
{
|
||||
$model = new SettingModel;
|
||||
if ($model->edit($key, $this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\company;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\company\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Balance
|
||||
* @package app\store\controller\company
|
||||
*/
|
||||
class Balance extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
$model = new BalanceLogModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\content;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Article as ArticleModel;
|
||||
|
||||
/**
|
||||
* 文章管理控制器
|
||||
* Class article
|
||||
* @package app\store\controller\content
|
||||
*/
|
||||
class Article extends Controller
|
||||
{
|
||||
/**
|
||||
* 文章列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new ArticleModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
* @param int $articleId
|
||||
* @return array|bool|string
|
||||
*/
|
||||
public function detail(int $articleId)
|
||||
{
|
||||
$detail = ArticleModel::detail($articleId);
|
||||
// 获取image (这里不能用with因为编辑页需要image对象)
|
||||
!empty($detail) && $detail['image'];
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文章
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new ArticleModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章
|
||||
* @param int $articleId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $articleId)
|
||||
{
|
||||
// 文章详情
|
||||
$model = ArticleModel::detail($articleId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章
|
||||
* @param $articleId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $articleId)
|
||||
{
|
||||
// 文章详情
|
||||
$model = ArticleModel::detail($articleId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\content;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Help as HelpModel;
|
||||
|
||||
/**
|
||||
* 帮助中心
|
||||
* Class help
|
||||
* @package app\store\controller\wxapp
|
||||
*/
|
||||
class Help extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new HelpModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加帮助
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new HelpModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新帮助
|
||||
* @param $helpId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $helpId)
|
||||
{
|
||||
// 帮助详情
|
||||
$model = HelpModel::detail($helpId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除帮助
|
||||
* @param int $helpId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $helpId)
|
||||
{
|
||||
// 帮助详情
|
||||
$model = HelpModel::detail($helpId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\content\article;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\article\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* Class Category
|
||||
* @package app\store\controller\content
|
||||
*/
|
||||
class Category extends Controller
|
||||
{
|
||||
/**
|
||||
* 文章分类列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new CategoryModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文章分类
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new CategoryModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文章分类
|
||||
* @param int $categoryId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $categoryId)
|
||||
{
|
||||
// 分类详情
|
||||
$model = CategoryModel::detail($categoryId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文章分类
|
||||
* @param int $categoryId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $categoryId)
|
||||
{
|
||||
$model = CategoryModel::detail($categoryId);
|
||||
if (!$model->remove($categoryId)) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\files;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\UploadGroup as GroupModel;
|
||||
|
||||
/**
|
||||
* 文件分组
|
||||
* Class Group
|
||||
* @package app\store\controller\content
|
||||
*/
|
||||
class Group extends Controller
|
||||
{
|
||||
/**
|
||||
* 文件分组列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new GroupModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文件分组
|
||||
* @return array|string
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new GroupModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑文件分组
|
||||
* @param int $groupId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(int $groupId)
|
||||
{
|
||||
// 分组详情
|
||||
$model = GroupModel::detail($groupId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件分组
|
||||
* @param int $groupId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $groupId)
|
||||
{
|
||||
$model = GroupModel::detail($groupId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\goods;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Comment as CommentModel;
|
||||
|
||||
/**
|
||||
* 商品评价管理
|
||||
* Class Comment
|
||||
* @package app\store\controller\goods
|
||||
*/
|
||||
class Comment extends Controller
|
||||
{
|
||||
/**
|
||||
* 评价列表
|
||||
* @return array
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new CommentModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 评价详情
|
||||
* @param int $commentId
|
||||
* @return array|bool|string
|
||||
*/
|
||||
public function detail(int $commentId)
|
||||
{
|
||||
// 评价详情
|
||||
$model = new CommentModel;
|
||||
$detail = $model->getDetail($commentId);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑评价
|
||||
* @param int $commentId
|
||||
* @return array
|
||||
*/
|
||||
public function edit(int $commentId)
|
||||
{
|
||||
// 评价详情
|
||||
$model = CommentModel::detail($commentId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除评价
|
||||
* @param int $commentId
|
||||
* @return array|bool
|
||||
*/
|
||||
public function delete(int $commentId)
|
||||
{
|
||||
// 评价详情
|
||||
$model = CommentModel::detail($commentId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\goods;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\goods\Service as ServiceModel;
|
||||
|
||||
/**
|
||||
* 商品服务与承诺管理
|
||||
* Class Service
|
||||
* @package app\store\controller\goods
|
||||
*/
|
||||
class Service extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new ServiceModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new ServiceModel;
|
||||
$list = $model->getAll($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加记录
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new ServiceModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新记录
|
||||
* @param $serviceId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $serviceId)
|
||||
{
|
||||
// 记录详情
|
||||
$model = ServiceModel::detail($serviceId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @param int $serviceId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $serviceId)
|
||||
{
|
||||
// 记录详情
|
||||
$model = ServiceModel::detail($serviceId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\goods;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Spec as SpecModel;
|
||||
use app\store\model\SpecValue as SpecValueModel;
|
||||
|
||||
/**
|
||||
* 商品规格控制器
|
||||
* Class Spec
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Spec extends Controller
|
||||
{
|
||||
/* @var SpecModel $SpecModel */
|
||||
private $SpecModel;
|
||||
|
||||
/* @var SpecValueModel $SpecModel */
|
||||
private $SpecValueModel;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->SpecModel = new SpecModel;
|
||||
$this->SpecValueModel = new SpecValueModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加规则组
|
||||
* @param $spec_name
|
||||
* @param $spec_value
|
||||
* @return array
|
||||
*/
|
||||
public function addSpec($spec_name, $spec_value)
|
||||
{
|
||||
// 判断规格组是否存在
|
||||
if (!$specId = $this->SpecModel->getSpecIdByName($spec_name)) {
|
||||
// 新增规格组and规则值
|
||||
if ($this->SpecModel->add($spec_name)
|
||||
&& $this->SpecValueModel->add($this->SpecModel['spec_id'], $spec_value))
|
||||
return $this->renderSuccess('', '', [
|
||||
'spec_id' => (int)$this->SpecModel['spec_id'],
|
||||
'spec_value_id' => (int)$this->SpecValueModel['spec_value_id'],
|
||||
]);
|
||||
return $this->renderError();
|
||||
}
|
||||
// 判断规格值是否存在
|
||||
if ($specValueId = $this->SpecValueModel->getSpecValueIdByName($specId, $spec_value)) {
|
||||
return $this->renderSuccess('', '', [
|
||||
'spec_id' => (int)$specId,
|
||||
'spec_value_id' => (int)$specValueId,
|
||||
]);
|
||||
}
|
||||
// 添加规则值
|
||||
if ($this->SpecValueModel->add($specId, $spec_value))
|
||||
return $this->renderSuccess('', '', [
|
||||
'spec_id' => (int)$specId,
|
||||
'spec_value_id' => (int)$this->SpecValueModel['spec_value_id'],
|
||||
]);
|
||||
return $this->renderError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加规格值
|
||||
* @param $spec_id
|
||||
* @param $spec_value
|
||||
* @return array
|
||||
*/
|
||||
public function addSpecValue($spec_id, $spec_value)
|
||||
{
|
||||
// 判断规格值是否存在
|
||||
if ($specValueId = $this->SpecValueModel->getSpecValueIdByName($spec_id, $spec_value)) {
|
||||
return $this->renderSuccess('', '', [
|
||||
'spec_value_id' => (int)$specValueId,
|
||||
]);
|
||||
}
|
||||
// 添加规则值
|
||||
if ($this->SpecValueModel->add($spec_id, $spec_value))
|
||||
return $this->renderSuccess('', '', [
|
||||
'spec_value_id' => (int)$this->SpecValueModel['spec_value_id'],
|
||||
]);
|
||||
return $this->renderError();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\market;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Coupon as CouponModel;
|
||||
use app\store\model\UserCoupon as UserCouponModel;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 优惠券管理
|
||||
* Class Coupon
|
||||
* @package app\store\controller\market
|
||||
*/
|
||||
class Coupon extends Controller
|
||||
{
|
||||
/**
|
||||
* 列表记录
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new CouponModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new CouponModel;
|
||||
$list = $model->getAll($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情记录
|
||||
* @param int $couponId
|
||||
* @return Json
|
||||
*/
|
||||
public function detail(int $couponId): Json
|
||||
{
|
||||
$detail = CouponModel::detail($couponId);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加优惠券
|
||||
* @return Json
|
||||
*/
|
||||
public function add(): Json
|
||||
{
|
||||
// 新增记录
|
||||
$model = new CouponModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新优惠券
|
||||
* @param int $couponId
|
||||
* @return Json
|
||||
*/
|
||||
public function edit(int $couponId): Json
|
||||
{
|
||||
// 优惠券详情
|
||||
$model = CouponModel::detail($couponId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除优惠券
|
||||
* @param int $couponId
|
||||
* @return Json
|
||||
*/
|
||||
public function delete(int $couponId): Json
|
||||
{
|
||||
// 优惠券详情
|
||||
$model = CouponModel::detail($couponId);
|
||||
// 更新记录
|
||||
if ($model->setDelete()) {
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取记录
|
||||
* @return Json
|
||||
*/
|
||||
public function receive(): Json
|
||||
{
|
||||
// 获取列表记录
|
||||
$model = new UserCouponModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\market;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\user\PointsLog as PointsLogModel;
|
||||
|
||||
/**
|
||||
* 积分管理
|
||||
* Class Points
|
||||
* @package app\store\controller\market
|
||||
*/
|
||||
class Points extends Controller
|
||||
{
|
||||
/**
|
||||
* 积分明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
// 积分明细列表
|
||||
$model = new PointsLogModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\market\recharge;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\recharge\Plan as PlanModel;
|
||||
|
||||
/**
|
||||
* 充值套餐管理
|
||||
* Class Coupon
|
||||
* @package app\store\controller\market
|
||||
*/
|
||||
class Plan extends Controller
|
||||
{
|
||||
// 用户充值订单模型
|
||||
/* @var PlanModel $model */
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new PlanModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值套餐列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$list = $this->model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加充值套餐
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
if ($this->model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($this->model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新充值套餐
|
||||
* @param $planId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $planId)
|
||||
{
|
||||
// 充值套餐详情
|
||||
$model = PlanModel::detail($planId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除充值套餐
|
||||
* @param $planId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function delete(int $planId)
|
||||
{
|
||||
// 套餐详情
|
||||
$model = PlanModel::detail($planId);
|
||||
// 删除记录
|
||||
if ($model->setDelete()) {
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\merchant;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\merchant\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Balance
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Balance extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
$model = new BalanceLogModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\merchant;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\merchant\MerchantOrder as MerchantOrderModel;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Order
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
/**
|
||||
* 订单明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new MerchantOrderModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\order;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 订单操作控制器
|
||||
* Class Operate
|
||||
* @package app\store\controller\order
|
||||
*/
|
||||
class Event extends Controller
|
||||
{
|
||||
/**
|
||||
* 确认发货
|
||||
* @param int $orderId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delivery(int $orderId)
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::detail($orderId);
|
||||
if ($model->delivery($this->postForm())) {
|
||||
return $this->renderSuccess('发货成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '发货失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单价格
|
||||
* @param int $orderId
|
||||
* @return array
|
||||
*/
|
||||
public function updatePrice(int $orderId)
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::detail($orderId);
|
||||
if ($model->updatePrice($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核:用户取消订单
|
||||
* @param $orderId
|
||||
* @return array|bool
|
||||
*/
|
||||
public function confirmCancel($orderId)
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::detail($orderId);
|
||||
if ($model->confirmCancel($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除订单记录
|
||||
* @param int $orderId
|
||||
* @return array|\think\response\Json
|
||||
*/
|
||||
public function delete(int $orderId)
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::detail($orderId);
|
||||
// 确认核销
|
||||
if ($model->setDelete()) {
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\order;
|
||||
|
||||
use think\response\Json;
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\order\Export as ExportModel;
|
||||
use app\store\service\order\Export as ExportService;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 订单导出记录控制器
|
||||
* Class Export
|
||||
* @package app\store\controller\order
|
||||
*/
|
||||
class Export extends Controller
|
||||
{
|
||||
/**
|
||||
* 执行订单导出excel
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function exportOrder(): Json
|
||||
{
|
||||
$model = new ExportService;
|
||||
if (!$model->exportOrder($this->request->param())) {
|
||||
$this->renderError($model->getError() ?: '导出失败');
|
||||
}
|
||||
return $this->renderSuccess('导出Excel文件成功,请在导出记录中下载');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单导出记录
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new ExportModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\order;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\OrderRefund as OrderRefundModel;
|
||||
|
||||
/**
|
||||
* 售后管理
|
||||
* Class Refund
|
||||
* @package app\store\controller\order
|
||||
*/
|
||||
class Refund extends Controller
|
||||
{
|
||||
/**
|
||||
* 售后单列表
|
||||
* @return array
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new OrderRefundModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 售后单详情
|
||||
* @param int $orderRefundId
|
||||
* @return array
|
||||
*/
|
||||
public function detail(int $orderRefundId)
|
||||
{
|
||||
// 售后单详情
|
||||
$model = new OrderRefundModel;
|
||||
if (!$detail = $model->getDetail($orderRefundId)) {
|
||||
return $this->renderError('未找到该售后单记录');
|
||||
}
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家审核
|
||||
* @param int $orderRefundId
|
||||
* @return array|bool
|
||||
*/
|
||||
public function audit(int $orderRefundId)
|
||||
{
|
||||
// 售后单详情
|
||||
$model = OrderRefundModel::detail($orderRefundId);
|
||||
// 确认审核
|
||||
if ($model->audit($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货并退款
|
||||
* @param int $orderRefundId
|
||||
* @return array|bool
|
||||
*/
|
||||
public function receipt(int $orderRefundId)
|
||||
{
|
||||
// 售后单详情
|
||||
$model = OrderRefundModel::detail($orderRefundId);
|
||||
// 确认收货并退款
|
||||
if ($model->receipt($this->postForm())) {
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\partners;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\partners\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Balance
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Balance extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
$model = new BalanceLogModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\partners;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\partners\Order as OrderModel;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use app\common\service\QueueService;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Order
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
/**
|
||||
* 订单明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCode(): Json
|
||||
{
|
||||
$postData = $this->postForm();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
|
||||
$order = OrderModel::detail($postData['order_id']);
|
||||
if($order['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
$company = CompanyModel::detail(['orgNo' => $this->getCompany($order['goods_no'])]);
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$order['oilCardNo']], $company);
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$order['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$order['goods_price'],
|
||||
'order_id'=>$order['order_id'],
|
||||
'user_id'=>0,
|
||||
'store_id'=>$order['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'qrCode'=>$res['data']['useQrCodeUrl']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError($res['errMessage'] ?? $res['message']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $goodsNo
|
||||
* @return string
|
||||
*/
|
||||
public function getCompany($goodsNo): string
|
||||
{
|
||||
switch ($goodsNo) {
|
||||
case 'djgdface100':
|
||||
case 'djgdface200':
|
||||
case 'djgdface300':
|
||||
return 'umQZhIHKofyA';
|
||||
case 'jmgxyyface100':
|
||||
case 'jmgxyyface200':
|
||||
case 'jmgxyyface300':
|
||||
|
||||
case 'jmgzface100':
|
||||
case 'jmgzface200':
|
||||
case 'jmgzface300':
|
||||
|
||||
case 'jmfjface100':
|
||||
case 'jmfjface200':
|
||||
case 'jmfjface300':
|
||||
return 'HpWqXIgYvTBg';
|
||||
case 'face003':
|
||||
return 'NKJBgaaRNdiL'; // 测试参数
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动分油
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function share(): Json
|
||||
{
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
|
||||
$order = OrderModel::detail($postData['order_id']);
|
||||
if($order['oil_status'] != 0){
|
||||
return $this->renderError('已分油');
|
||||
}else {
|
||||
if($order['oilCardType']) {
|
||||
$data['amount'] = $order['total_price']; // 金额
|
||||
$company = CompanyModel::detail(['orgNo' => $this->getCompany($order['goods_no'])]);
|
||||
if (!$company) {
|
||||
return $this->renderError('已分油');
|
||||
}
|
||||
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->oilOilCardShare([
|
||||
'goodsNo'=>$order['goods_no'],
|
||||
'amount'=>$data['amount'],
|
||||
'userNo'=>0,
|
||||
'mobile'=>$order['mobile'],
|
||||
'saleOrderNo'=>$order['oilCardNo'],
|
||||
'oilCardType'=>$order['oilCardType']
|
||||
], $company);
|
||||
if ($res['code'] != 1) {
|
||||
return $this->renderError($res['errMessage'] ?? $res['message']);
|
||||
}
|
||||
$IdingjuOil->saveLogStore("分油接口结果".json_encode($res,320));
|
||||
// $item['company_id'] = $company['company_id'];
|
||||
$item['shareNo'] = $res['data']['trade_no'] ?? '';
|
||||
$item['qrCode'] = $res['data']['useUrl'] ?? '';
|
||||
$item['oil_status_zsy'] = $res['data']['state'] ?? 0;
|
||||
$item['oil_time'] = time();
|
||||
$item['oil_status'] = $item['oil_status_zsy'] == 2 ? 1 : 0; // 已发券 为1
|
||||
$r = $order->save($item);
|
||||
$IdingjuOil->saveLogStore("保存分油结果".json_encode($r,320));
|
||||
return $this->renderSuccess('分油成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分油回调
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function oilCallback(): Json
|
||||
{
|
||||
/*
|
||||
$model = new OrderModel;
|
||||
$list = $model->getAll([
|
||||
['partners_id', '=', 4],
|
||||
['oil_status', '=', 1],
|
||||
['oil_callback', '=', 0],
|
||||
])->toArray();
|
||||
$queueService = new QueueService();
|
||||
foreach ($list as $order){
|
||||
// 存入队列处理
|
||||
$queueService->push('notify_queue', json_encode([
|
||||
'order_id' => $order['order_id'],
|
||||
'type' => 'add',
|
||||
'optType' => 'share_oil',
|
||||
'retry_count' => 0,
|
||||
], 320));
|
||||
}
|
||||
return $this->renderSuccess('回调成功');*/
|
||||
|
||||
$postData = $this->request->param();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
|
||||
$order = OrderModel::detail($postData['order_id']);
|
||||
if($order['oil_status'] == 0){
|
||||
return $this->renderError('未分油');
|
||||
}else {
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('notify_queue', json_encode([
|
||||
'order_id' => $order['order_id'],
|
||||
'type' => 'add',
|
||||
'optType' => 'share_oil',
|
||||
'retry_count' => 0,
|
||||
], 320));
|
||||
return $this->renderSuccess('回调成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用回调
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function useCallback(): Json
|
||||
{
|
||||
/*
|
||||
$model = new OrderModel;
|
||||
$list = $model->getAll([
|
||||
['partners_id', '=', 4],
|
||||
['use_status', '=', 1],
|
||||
['use_callback', '=', 0],
|
||||
])->toArray();
|
||||
$queueService = new QueueService();
|
||||
foreach ($list as $order){
|
||||
// 存入队列处理
|
||||
$queueService->push('notify_queue', json_encode([
|
||||
'order_id' => $order['order_id'],
|
||||
'optType' => 'add_oil',
|
||||
'retry_count' => 0,
|
||||
], 320));
|
||||
}
|
||||
return $this->renderSuccess('回调成功');*/
|
||||
|
||||
$postData = $this->request->param();
|
||||
$postData['order_id'] = $this->request->param('orderId');
|
||||
|
||||
$order = OrderModel::detail($postData['order_id']);
|
||||
if($order['use_status'] == 0){
|
||||
return $this->renderError('未使用');
|
||||
}else {
|
||||
// 通知对接公司
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('notify_queue', json_encode([
|
||||
'order_id' => $order['order_id'],
|
||||
'optType' => 'add_oil',
|
||||
'retry_count' => 0,
|
||||
], 320));
|
||||
return $this->renderSuccess('回调成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\setting;
|
||||
|
||||
use think\response\Json;
|
||||
use app\store\service\setting\Clear as ClearService;
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
* Class Index
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Cache extends Controller
|
||||
{
|
||||
/**
|
||||
* 数据缓存项目(只显示key和name)
|
||||
* @return Json
|
||||
*/
|
||||
public function items(): Json
|
||||
{
|
||||
$ClearService = new ClearService;
|
||||
$items = $ClearService->items();
|
||||
return $this->renderSuccess(compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
* @return Json
|
||||
*/
|
||||
public function clear(): Json
|
||||
{
|
||||
$ClearService = new ClearService;
|
||||
$ClearService->rmCache($this->postForm()['keys']);
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\setting;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Delivery as DeliveryModel;
|
||||
|
||||
/**
|
||||
* 配送设置
|
||||
* Class Delivery
|
||||
* @package app\store\controller\setting
|
||||
*/
|
||||
class Delivery extends Controller
|
||||
{
|
||||
/**
|
||||
* 配送模板列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new DeliveryModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new DeliveryModel;
|
||||
$list = $model->getAll();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取详情记录
|
||||
* @param int $deliveryId
|
||||
* @return array
|
||||
*/
|
||||
public function detail(int $deliveryId)
|
||||
{
|
||||
$detail = DeliveryModel::detail($deliveryId, ['rule']);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加配送模板
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new DeliveryModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑配送模板
|
||||
* @param int $deliveryId
|
||||
* @return array
|
||||
*/
|
||||
public function edit(int $deliveryId)
|
||||
{
|
||||
// 模板详情
|
||||
$model = DeliveryModel::detail($deliveryId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板
|
||||
* @param int $deliveryId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $deliveryId)
|
||||
{
|
||||
// 模板详情
|
||||
$model = DeliveryModel::detail($deliveryId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\setting;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\Express as ExpressModel;
|
||||
|
||||
/**
|
||||
* 物流公司
|
||||
* Class Express
|
||||
* @package app\store\controller\setting
|
||||
*/
|
||||
class Express extends Controller
|
||||
{
|
||||
/**
|
||||
* 物流公司列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new ExpressModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new ExpressModel;
|
||||
$list = $model->getAll($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除物流公司
|
||||
* @param int $expressId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $expressId)
|
||||
{
|
||||
$model = ExpressModel::detail($expressId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加物流公司
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new ExpressModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑物流公司
|
||||
* @param $expressId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $expressId)
|
||||
{
|
||||
// 模板详情
|
||||
$model = ExpressModel::detail($expressId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\statistics;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\service\statistics\Data as StatisticsDataService;
|
||||
|
||||
/**
|
||||
* 数据概况
|
||||
* Class Data
|
||||
* @package app\store\controller\statistics
|
||||
*/
|
||||
class Data extends Controller
|
||||
{
|
||||
// 数据概况服务类
|
||||
/* @var $service StatisticsDataService */
|
||||
private $service;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
// 实例化数据概况服务类
|
||||
$this->service = new StatisticsDataService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据统计主页
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function data()
|
||||
{
|
||||
// 获取数据
|
||||
$data = [
|
||||
// 数据概况
|
||||
'overview' => [], //$this->service->getSurveyData()
|
||||
// 近七日交易走势
|
||||
'tradeTrend' => $this->service->getTransactionTrend(),
|
||||
// 商品销售榜
|
||||
'goodsRanking' => [], // $this->service->getGoodsRanking()
|
||||
// 用户消费榜
|
||||
'userExpendRanking' => [], // $this->service->geUserExpendRanking()
|
||||
];
|
||||
return $this->renderSuccess(compact('data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据概况API
|
||||
* @param null $startDate
|
||||
* @param null $endDate
|
||||
* @return array
|
||||
*/
|
||||
public function survey($startDate = null, $endDate = null)
|
||||
{
|
||||
// 获取数据概况
|
||||
$data = $this->service->getSurveyData($startDate, $endDate);
|
||||
return $this->renderSuccess($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\store;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\Address as AddressModel;
|
||||
|
||||
/**
|
||||
* 商家地址管理
|
||||
* Class Delivery
|
||||
* @package app\store\controller\setting
|
||||
*/
|
||||
class Address extends Controller
|
||||
{
|
||||
/**
|
||||
* 列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new AddressModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new AddressModel;
|
||||
$list = $model->getAll($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加记录
|
||||
* @return array|string
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new AddressModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑记录
|
||||
* @param int $addressId
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function edit(int $addressId)
|
||||
{
|
||||
// 详情记录
|
||||
$model = AddressModel::detail($addressId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除记录
|
||||
* @param int $addressId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $addressId)
|
||||
{
|
||||
// 详情记录
|
||||
$model = AddressModel::detail($addressId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\store;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\Menu as MenuModel;
|
||||
|
||||
/**
|
||||
* 商家后台菜单管理
|
||||
* Class Menu
|
||||
* @package app\store\controller\store
|
||||
*/
|
||||
class Menu extends Controller
|
||||
{
|
||||
/**
|
||||
* 菜单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new MenuModel;
|
||||
$list = $model->getList();
|
||||
//二级账户创建角色,不能给管理员模块权限,意味着三级账户不能新建管理员
|
||||
/*if($this->store['user']['level'] == 2){
|
||||
unset($list[1]);
|
||||
$list = array_values($list);
|
||||
}*/
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\store;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\Role as RoleModel;
|
||||
use app\store\model\store\User;
|
||||
|
||||
/**
|
||||
* 商家用户角色控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Role extends Controller
|
||||
{
|
||||
/**
|
||||
* 角色列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new RoleModel;
|
||||
$filter = [];
|
||||
$user = $this->store['user'];
|
||||
if($user['is_super'] == 0){
|
||||
$filter[] = ['store_user_id', 'in', User::getScope($user)];
|
||||
}
|
||||
$list = $model->getList($filter);
|
||||
return $this->renderSuccess(compact('list','user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加角色
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new RoleModel;
|
||||
$data = $this->postForm();
|
||||
$data['store_user_id'] = $this->store['user']['store_user_id'];
|
||||
/*if($this->store['user']['is_super'] == 0){
|
||||
$data['store_user_id'] = $this->store['user']['store_user_id'];
|
||||
}*/
|
||||
if ($model->add($data)) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色
|
||||
* @param $roleId
|
||||
* @return array|bool|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function edit(int $roleId)
|
||||
{
|
||||
// 角色详情
|
||||
$model = RoleModel::detail($roleId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除角色
|
||||
* @param $roleId
|
||||
* @return array|bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function delete(int $roleId)
|
||||
{
|
||||
// 角色详情
|
||||
$model = RoleModel::detail($roleId);
|
||||
if (!$model->remove()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\store;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\store\User as StoreUserModel;
|
||||
use app\store\service\store\User as StoreUserService;
|
||||
use app\store\service\store\Role as StoreRoleService;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
|
||||
/**
|
||||
* 商家用户控制器
|
||||
* Class StoreUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class User extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取当前登录的用户信息
|
||||
* @return array
|
||||
* @param String $client_id
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function info(string $client_id = '')
|
||||
{
|
||||
/*if($client_id) {
|
||||
Gateway::bindUid($client_id, (int)StoreUserService::getLoginUserId());
|
||||
'client_id' => $client_id,
|
||||
'uidList' => Gateway::getAllUidList(),
|
||||
'clientIdList' => Gateway::getAllClientIdList(),
|
||||
'state' => Gateway::isUidOnline((int)StoreUserService::getLoginUserId()),
|
||||
}*/
|
||||
return $this->renderSuccess([
|
||||
// 用户信息
|
||||
'userInfo' => StoreUserModel::detail(StoreUserService::getLoginUserId()),
|
||||
// 菜单权限
|
||||
'roles' => StoreRoleService::getLoginPermissions(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new StoreUserModel;
|
||||
$list = $model->getList($this->request->param(),$this->store['user']);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加管理员
|
||||
* @return array
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new StoreUserModel;
|
||||
if ($model->add($this->postForm(),$this->store['user'])) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新管理员
|
||||
* @param int $userId
|
||||
* @return array
|
||||
*/
|
||||
public function edit(int $userId)
|
||||
{
|
||||
// 管理员详情
|
||||
$model = StoreUserModel::detail($userId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm(),$this->store['user'])) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除管理员
|
||||
* @param int $userId
|
||||
* @return array|bool
|
||||
*/
|
||||
public function delete(int $userId)
|
||||
{
|
||||
// 管理员详情
|
||||
$model = StoreUserModel::detail($userId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前管理员信息
|
||||
* @return array|bool|string
|
||||
*/
|
||||
public function renew()
|
||||
{
|
||||
// 管理员详情
|
||||
$model = StoreUserModel::detail(StoreUserService::getLoginUserId());
|
||||
// 更新当前管理员信息
|
||||
if ($model->renew($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* * @param $status
|
||||
* @return array|mixed
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function state($status)
|
||||
{
|
||||
$text = $status == 1?"已上线":"已下线";
|
||||
// 管理员详情
|
||||
$model = StoreUserModel::detail($this->store['user']['store_user_id']);
|
||||
$warn = $model->setStatus($status);
|
||||
if ($warn !== true) {
|
||||
return $this->renderError($warn);
|
||||
}
|
||||
return $this->renderSuccess($text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通基础数据
|
||||
* Class SybBase
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybBase extends Controller
|
||||
{
|
||||
/** 油站查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function baseGasStationList($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.base.gasStation.list',
|
||||
];
|
||||
$body = [
|
||||
'province' => $data['province']??'',
|
||||
'city' => $data['city']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/base/gasStationList', $body, $header);
|
||||
$this->saveLogStore("油站查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 文件上传接口
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function baseFileUpload($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.base.file.upload',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'file' => request()->file('file'),
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/base/uploadFile', $body, $header);
|
||||
$this->saveLogStore("文件上传接口".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通油卡操作
|
||||
* Class SybOil
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybOil extends Controller
|
||||
{
|
||||
/** 油卡查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardSelect($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.select',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'userNo' => $data['userNo']??'',
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'pageLimit' => $data['pageLimit']??'10',
|
||||
'pageNum' => $data['pageNum']??'1',
|
||||
'oilCardType' => $data['oilCardType']??'card', //不填时默认为“E卡通平台自营卡”
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/select', $body, $header);
|
||||
$this->saveLogStore("油卡查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 用户分油
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardShare($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.share',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'goodsNo' => $data['goodsNo']??'',
|
||||
'amount' => $data['oilCardType']=='card' ? round($data['amount'],2) : '',
|
||||
'userNo' => $data['userNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/share', $body, $header);
|
||||
$this->saveLogStore("用户分油".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 分油撤销接口
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardCancelShare($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.cancelShare',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'type' => $data['type']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/cancelShare', $body, $header);
|
||||
$this->saveLogStore("分油撤销接口".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 用户分油记录查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardShareList($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.shareList',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'userNo' => $data['userNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'beginDate' => $data['beginDate']??'',
|
||||
'endDate' => $data['endDate']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/opt/oilCard/shareList', $body, $header);
|
||||
$this->saveLogStore("用户分油记录查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通加油记录查询
|
||||
* Class SybOrder
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybOrder extends Controller
|
||||
{
|
||||
/** 加油记录查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function orderListSale($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.order.list.sale',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'beginDate' => $data['beginDate']??'',
|
||||
'endDate' => $data['endDate']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/opt/list/sale', $body, $header);
|
||||
$this->saveLogStore("加油记录查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通支付财务
|
||||
* Class SybOil
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybPay extends Controller
|
||||
{
|
||||
/** 付款二维码申请
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payQrCodeRequest($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.qrCode.request',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/getPayQrCode', $body, $header);
|
||||
$this->saveLogStore("付款二维码申请".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 主扫订单创建
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payActiveScan($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.active.scan',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'qrInfo' => $data['qrInfo']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/activeScan', $body, $header);
|
||||
$this->saveLogStore("主扫订单创建".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 主扫订单信息确认
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payActiveVerify($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.active.verify',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'activeOrderId' => $data['activeOrderId']??'',
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'deviceId' => $data['deviceId']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/activeVerify', $body, $header);
|
||||
$this->saveLogStore("主扫订单信息确认".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 账户余额查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payAmountBalance($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.account.balance',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/account/balance', $body, $header);
|
||||
$this->saveLogStore("账户余额查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 申请发票
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payInvoiceRequest($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.invoice.request',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'oilNo' => $data['oilNo']??'',
|
||||
'invoiceAddress' => $data['invoiceAddress']??'',
|
||||
'invoiceHeader' => $data['invoiceHeader']??'',
|
||||
'invoicePhone' => $data['invoicePhone']??'',
|
||||
'invoiceOpenBank' => $data['invoiceOpenBank']??'',
|
||||
'taxIdentifyNo' => $data['taxIdentifyNo']??'',
|
||||
'invoiceCardNo' => $data['invoiceCardNo']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/invoice/request', $body, $header);
|
||||
$this->saveLogStore("申请发票".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 开票状态查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payInvoiceStatus($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.invoice.status',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'invoiceNo' => $data['invoiceNo']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/invoice/status', $body, $header);
|
||||
$this->saveLogStore("开票状态查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通用户账户
|
||||
* Class SybUser
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybUser extends Controller
|
||||
{
|
||||
/** 添加用户
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function userOptAdd($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.user.opt.add',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'userName' => $data['userName']??'',
|
||||
'userIdCard' => $data['userIdCard']??'',
|
||||
'userType' => $data['userType']??'user',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/user/opt/add', $body, $header);
|
||||
$this->saveLogStore("添加用户".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\syb;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
|
||||
/**
|
||||
* 优惠券
|
||||
* Class SybVoucher
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class SybVoucher extends Controller
|
||||
{
|
||||
/** 优惠券下单
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherCreateOrder($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.createOrder',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'model' => $data['model']??'',
|
||||
'voucherAmount' => $data['voucherAmount']??'',
|
||||
'fullAmount' => $data['fullAmount']??'',
|
||||
'storeNum' => $data['storeNum']??'',
|
||||
'validTime' => $data['validTime']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/createOrder', $body, $header);
|
||||
$this->saveLogStore("优惠券下单".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 优惠券订单查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherOrderListPage($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.order.listPage',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'orderNo' => $data['orderNo']??'',
|
||||
'model' => $data['model']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/order/listPage', $body, $header);
|
||||
$this->saveLogStore("优惠券订单查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 卡券查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherItemListPage($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.item.listPage',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'orderNo' => $data['orderNo']??'',
|
||||
'model' => $data['model']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/item/listPage', $body, $header);
|
||||
$this->saveLogStore("卡券查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\user;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\user\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 余额明细
|
||||
* Class Balance
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Balance extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额明细
|
||||
* @return mixed
|
||||
*/
|
||||
public function log()
|
||||
{
|
||||
$model = new BalanceLogModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\user;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\user\Grade as GradeModel;
|
||||
|
||||
/**
|
||||
* 会员等级
|
||||
* Class Grade
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Grade extends Controller
|
||||
{
|
||||
/**
|
||||
* 列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new GradeModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 全部记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$model = new GradeModel;
|
||||
$list = $model->getAll($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加等级
|
||||
* @return array|bool|mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
// 新增记录
|
||||
$model = new GradeModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess('添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑会员等级
|
||||
* @param int $gradeId
|
||||
* @return array|bool|mixed
|
||||
*/
|
||||
public function edit(int $gradeId)
|
||||
{
|
||||
// 会员等级详情
|
||||
$model = GradeModel::detail($gradeId);
|
||||
// 更新记录
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess('更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员等级
|
||||
* @param int $gradeId
|
||||
* @return array
|
||||
*/
|
||||
public function delete(int $gradeId)
|
||||
{
|
||||
// 会员等级详情
|
||||
$model = GradeModel::detail($gradeId);
|
||||
if (!$model->setDelete()) {
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
return $this->renderSuccess('删除成功');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\store\controller\user;
|
||||
|
||||
use app\store\controller\Controller;
|
||||
use app\store\model\recharge\Order as OrderModel;
|
||||
|
||||
/**
|
||||
* 余额记录
|
||||
* Class Recharge
|
||||
* @package app\store\controller\user
|
||||
*/
|
||||
class Recharge extends Controller
|
||||
{
|
||||
/**
|
||||
* 充值记录
|
||||
* @return mixed
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user