Merge branch 'feature/main20240421'

wechat
lqmac 11 months ago
commit dafbf30f85
  1. 132
      app/admin/controller/Channel.php
  2. 113
      app/admin/controller/Store.php
  3. 105
      app/admin/model/Channel.php
  4. 3
      app/admin/model/Store.php
  5. 7
      app/api/controller/Category.php
  6. 4
      app/api/controller/Checkout.php
  7. 61
      app/api/controller/GoodsNew.php
  8. 4
      app/api/controller/Merchant.php
  9. 15
      app/api/controller/Square.php
  10. 6
      app/api/controller/Store.php
  11. 18
      app/api/model/Goods.php
  12. 2
      app/api/model/Order.php
  13. 15
      app/api/model/Square.php
  14. 25
      app/api/service/cashier/Payment.php
  15. 1
      app/api/service/order/Checkout.php
  16. 16
      app/api/service/order/PaySuccess.php
  17. 206
      app/command/ProfitSharing.php
  18. 131
      app/command/ProfitSharingResult.php
  19. 2
      app/command/SyncGoodsToEs.php
  20. 30
      app/common/library/elasticsearch/Client.php
  21. 8
      app/common/library/payment/gateway/Driver.php
  22. 35
      app/common/library/payment/gateway/driver/Wechat.php
  23. 168
      app/common/library/payment/gateway/driver/wechat/V3.php
  24. 48
      app/common/model/Channel.php
  25. 1
      app/common/model/GoodsCategoryRel.php
  26. 35
      app/common/model/Merchant.php
  27. 71
      app/common/model/MerchantPay.php
  28. 10
      app/common/model/Payment.php
  29. 11
      app/common/model/PaymentTemplate.php
  30. 6
      app/common/model/Store.php
  31. 2
      app/common/model/UploadFile.php
  32. 368
      app/common/service/GoodsEs.php
  33. 3
      app/store/controller/Goods.php
  34. 6
      app/store/controller/Merchant.php
  35. 1
      app/store/controller/setting/Payment.php
  36. 6
      app/store/controller/setting/payment/Template.php
  37. 13
      app/store/controller/store/User.php
  38. 9
      app/store/model/Goods.php
  39. 65
      app/store/model/MerchantPay.php
  40. 6
      app/store/model/Payment.php
  41. 11
      app/store/model/PaymentTemplate.php
  42. 3
      app/store/model/UploadFile.php
  43. 2
      app/store/model/store/Role.php
  44. 4
      app/store/model/store/RoleMenu.php
  45. 47
      app/store/model/store/User.php
  46. 4
      app/store/model/store/UserRole.php
  47. 2
      config/console.php
  48. 2
      config/database.php
  49. 41
      public/install/data/install_struct.sql

@ -0,0 +1,132 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\controller;
use think\response\Json;
use app\admin\controller\Controller;
use app\admin\model\Channel as ChannelModel;
use app\common\model\UploadFile;
/**
* 商家后台菜单控制器
* Class Menu
* @package app\store\controller
*/
class Channel extends Controller
{
/**
* 菜单列表
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index(): Json
{
$model = new ChannelModel;
$list = $model->getList()->toArray();
foreach ($list['data'] as $kr => &$r) {
$r['licenseImg'] = [];
if ($r['license_img_id']) {
$img_ids = explode(",", $r['license_img_id']);
$files = UploadFile::getFileList($img_ids, 0);
$r['licenseImg'] = $files ?: null;
}
}
return $this->renderSuccess(compact('list'));
}
/**
* 菜单详情
* @param int $menuId
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function info(int $id): Json
{
// 菜单详情
$model = ChannelModel::detail($id);
return $this->renderSuccess(['info' => $model]);
}
/**
* 新增菜单
* @return Json
*/
public function add(): Json
{
// 新增记录
$model = new ChannelModel;
if ($model->add($this->postForm())) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 编辑菜单
* @param $menuId
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function edit(int $id): Json
{
// 菜单详情
$model = ChannelModel::detail($id);
// 更新记录
if ($model->edit($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 设置菜单绑定的Api
* @param int $menuId
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function setApis(int $menuId): Json
{
// 菜单详情
$model = MenuModel::detail($menuId);
// 更新记录
if ($model->setApis($this->postForm())) {
return $this->renderSuccess('操作成功');
}
return $this->renderError($model->getError() ?: '操作失败');
}
/**
* 删除菜单
* @param int $menuId
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function delete(int $menuId): Json
{
// 菜单详情
$model = MenuModel::detail($menuId);
if (!$model->remove()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
}

@ -17,6 +17,11 @@ use app\admin\model\Store as StoreModel;
use app\admin\model\store\SyncTask;
use app\admin\service\store\User as StoreUserService;
use app\common\model\Channel;
use app\common\model\Merchant;
use app\store\model\store\User as StoreUserModel;
use app\store\model\store\Role as role;
use think\facade\Db;
/**
* 商城管理
* Class Store
@ -214,6 +219,104 @@ class Store extends Controller
public function auth(int $storeId): Json
{
$platformList = $this->request->param('platformList');
//多商户新增一个商户用户
$model = StoreModel::detail($storeId);
$storeUserModel = new StoreUserModel;
if ($model->store_version == 1) {
if ($platformList) {
foreach ($platformList as $value) {
$channel = Channel::where('code', $value)->where('status',1)->find();
if ($channel->isEmpty()) {
return $this->renderError('当前渠道不存在');
}
$user_name = $channel->code.$storeId;
//当前账号是否创建
$merchant = Merchant::where('channel_id', $channel->id)->where('store_id', $storeId)->where('is_delete', 0)->find();
if ($merchant) {
continue;
}
//创建账号
//查出当前店铺的商户角色的id
$whererole = [
'store_id' => $storeId,
'role_name' => "商户"
];
$role = role::detail($whererole);
if (!$role) {
return $this->renderError('当前多商户商城商户角色不存在');
}
$params = [
"real_name" => $channel->name,
"user_name" => $user_name,
"roles" => [$role->role_id],
"password" => "123456",
"password_confirm" => "123456",
"sort" => 100,
'storeId' => $storeId,
];
// var_dump($params);
// exit();
$storeUserModel->addNew($params);
//复制商户
$merchantData = [
"shop_name" => $channel->shop_name,
"shop_label" => $channel->shop_label,
"channel_id" => $channel->id,
"channel" => $channel->code,
"store_id" => $storeId,
"user_name" => $user_name,
"score" => 5,
"sale" => 100,
"sort" => 100,
"license_img_id" => "",
"logo_image_id" => 0,
"create_time" => time(),
];
// var_dump($merchantData);
// exit();
if ($channel->logo_image_id) {
//复制图片
$upload_file = Db::name('upload_file')->where('file_id', $channel->logo_image_id)->find();
if ($upload_file) {
$upload_file['store_id'] = $storeId;
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$logo_image_id = Db::name('upload_file')->insertGetId($upload_file);
$merchantData['logo_image_id'] = $logo_image_id;
}
}
if ($channel->license_img_id) {
$arr = explode(",", $channel->license_img_id);
$license_img_ids = [];
foreach ($arr as $key => $val) {
//复制图片
$upload_file = Db::name('upload_file')->where('file_id', $val)->find();
if ($upload_file) {
$upload_file['store_id'] = $storeId;
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$license_img_id = Db::name('upload_file')->insertGetId($upload_file);
$license_img_ids[] = $license_img_id;
}
}
$merchantData['license_img_id'] = implode(",", $license_img_ids);
}
Merchant::create($merchantData);
}
}
}
// var_dump($model->store_version);
// exit();
$currItems = SyncTask::where('store_id', $storeId)->select()->toArray();
if ($currItems) {
$delIds = [];
@ -234,10 +337,17 @@ class Store extends Controller
if (in_array($platform, $curr_channels)) {
continue;
}
$merchantId = 0;
if ($model->store_version == 1) {
$merchant = Merchant::where('channel', $platform)->where('store_id', $storeId)->find();
$merchantId = $merchant->merchant_id;
}
$inData[] = [
'store_id' => $storeId,
'channel' => $platform,
'create_time' => time(),
'merchant_id' => $merchantId,
];
}
if ($inData) {
@ -249,8 +359,7 @@ class Store extends Controller
return $this->renderSuccess('操作成功');
}

@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\admin\model;
use app\common\model\Channel as ChannelModel;
/**
* 商家后台菜单模型
* Class Menu
* @package app\admin\model\store
*/
class Channel extends ChannelModel
{
/**
* 新增记录
* @param array $data
* @return bool
*/
public function add(array $data): bool
{
return $this->save($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): bool
{
return $this->save($data);
}
/**
* 设置菜单的API权限
* @param array $data
* @return bool
*/
public function setApis(array $data): bool
{
if (empty($data['apiIds'])) {
$this->error = 'API权限不能为空';
return false;
}
// 根据菜单id批量更新API关联记录
return (new MenuApiModel)->updateByMenuId($this['menu_id'], $data['apiIds']);
}
/**
* 删除菜单
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \Exception
*/
public function remove(): bool
{
// 判断是否存在下级菜单
if (self::detail(['parent_id' => $this['menu_id']])) {
$this->error = '当前菜单下存在子菜单或操作,请先删除';
return false;
}
return $this->delete();
}
/**
* 获取所有上级id集
* @param int $menuId
* @param null $menuList
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getTopMenuIds(int $menuId, $menuList = null): array
{
static $ids = [];
is_null($menuList) && $menuList = $this->getAll();
foreach ($menuList as $item) {
if ($item['menu_id'] == $menuId && $item['parent_id'] > 0) {
$ids[] = $item['parent_id'];
$this->getTopMenuIds($item['parent_id'], $menuList);
}
}
return $ids;
}
}

@ -97,7 +97,8 @@ class Store extends StoreModel
10046,10243,10244,10246,10245,10050,10051,
10052,10205,10054,10189,10055,10223,10139,10252,10056,10058,
10059,10057,10201,10238,10241,10239,10240,10242,10202,10203,
10206,10207,10208,10209,10213,10210,10211,10115
10206,10207,10208,10209,10213,10210,10211,10115,10247,10248,
10249
],
'store_id' => $storeId
];

@ -55,6 +55,7 @@ class Category extends Controller
public function listmerchant(): Json
{
$list = [];
$merchantId = (int)$this->request->param('merchantId', 0);
$model = new CategoryModel;
$hasGoods = GoodsCategoryRel::getcategory($this->storeId,$merchantId);
@ -64,10 +65,14 @@ class Category extends Controller
foreach ($hasGoods as $v) {
$arr[] = $v['category_id'];
}
} else {
return $this->renderSuccess(compact('list'));
}
if (!empty($arr)) {
$arr1 = ['cataIds' => $arr];
} else {
return $this->renderSuccess(compact('list'));
}
$list = $model->getListPublic($this->request->param(), $arr1);

@ -109,6 +109,10 @@ class Checkout extends Controller
}
// 创建订单 增加订单
$orderInfo['merchantId'] = $merchantId;
if ($merchantId) {
$model = \app\store\model\Merchant::detail($merchantId, $this->storeId);
$orderInfo['commission_ratio'] = $model['commission_ratio'];
}
//print_r($orderInfo);die;
if (!$Checkout->createOrder($orderInfo)) {
return $this->renderError($Checkout->getError() ?: '订单创建失败', ['isCreated' => false]);

@ -4,6 +4,7 @@ namespace app\api\controller;
use app\common\service\GoodsEs;
use think\App;
class GoodsNew extends Controller
{
@ -13,4 +14,64 @@ class GoodsNew extends Controller
$data = $goodsService->list([]);
dd($data);
}
public function search()
{
$keyword = $this->request->param('keyword');
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
if (!$keyword) {
$this->renderError('请输入搜索关键字');
}
$params = ['goods_name' => $keyword];
$goodsService = new GoodsEs();
$list = $goodsService->list($params, $page, $limit);
$data['list'] = $list;
$data['total'] = $goodsService->count();
return $this->renderSuccess($data);
}
/**
* 添加商品
*/
public function add()
{
$goods_id = 1;
$goods_data = \app\common\model\Goods::where('goods_id', '=', $goods_id)
->order('goods_id desc')
->find()
->toArray();
$goodsService = new GoodsEs();
$data = $goodsService->createData($goods_id, $goods_data);
$this->renderSuccess($data);
}
/**
* 更新商品
*/
public function update()
{
$goods_id = 1;
$update = [
'goods_name' => '测试商品',
'selling_point' => '测试商品',
'goods_price_min' => 100,
'goods_price_max' => 100,
];
$goodsService = new GoodsEs();
$data = $goodsService->updateData($goods_id, $update);
$this->renderSuccess($data);
}
/**
* 删除
*/
public function delete()
{
$goods_id = 1;
$goodsService = new GoodsEs();
$data = $goodsService->delete($goods_id);
$this->renderSuccess($data);
}
}

@ -133,7 +133,9 @@ class Merchant extends Controller
$pageSize = empty($pageSize) ? 15 : $pageSize;
$sort = $this->request->param('sort');
$sort = empty($sort) ? "merchant_id" : $sort;
$list = $model->getList($this->request->param(), intval($pageSize), $sort)->toArray();
$params = $this->request->param();
$params['is_select_mechant'] = 1;
$list = $model->getList($params, intval($pageSize), $sort)->toArray();
foreach ($list['data'] as $kr => $r) {
$res[$kr]['licenseImg'] = [];

@ -58,6 +58,21 @@ class Square extends Controller
return $this->renderError('添加失败');
}
/**
* 删除门店
* @param int $shopId
* @return Json
*/
public function delete(int $squareId): Json
{
// 门店详情
$model = squareModel::detail($squareId, $this->storeId);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
/**
* 列表

@ -125,7 +125,11 @@ class Store extends Controller
$file = UploadFile::where('file_id', '=', $info['logo_image_id'])->find();
$info['logo_image'] = $file->preview_url;
}
$info['login_img'] = "";
if ($info['login_img_id']) {
$file = UploadFile::where('file_id', '=', $info['login_img_id'])->find();
$info['login_img'] = $file->preview_url;
}
return $this->renderSuccess($info);
}

@ -463,6 +463,24 @@ class Goods extends GoodsModel
if (isset($goodsInfo->skuList1)) {
unset($goodsInfo->skuList1);
}
$goodsInfo['merchant'] = null;
//商户信息
if ($goodsInfo['merchant_id']) {
$merchant = \app\common\model\Merchant::detail($goodsInfo['merchant_id'], $goodsInfo->store_id);
if ($merchant) {
if ($merchant['license_img_id']) {
$img_ids = explode(",", $merchant['license_img_id']);
$files = UploadFileModel::getFileList($img_ids, $goodsInfo->store_id);
$merchant['licenseImg'] = $files ?: null;
}
if ($merchant['logo_image_id']) {
$files = UploadFileModel::getFileList([$merchant['logo_image_id']], $goodsInfo->store_id);
$merchant['logoImage'] = $files ?: null;
}
}
$goodsInfo['merchant'] = $merchant;
}
//加入足迹
$userId = UserService::getCurrentLoginUserId(false) ?? '';
if ($userId) {

@ -469,6 +469,8 @@ class Order extends OrderModel
'pay_status' => $orderInfo['pay_status'],
'order_status' => $orderInfo['order_status'],
'create_time' => $orderInfo['create_time'],
'store_id' => $orderInfo['store_id'],
'merchant_id' => $orderInfo['merchant_id'],
'showExpiration' => $orderCloseTime > 0,
'expirationTime' => format_time($expirationTime),
];

@ -31,6 +31,21 @@ class Square extends \app\common\model\Square
return $this->save($data) !== false;
}
/**
* 详情信息
* @param int $storeId
* @return static|array|null
*/
public static function detail(int $squareId, $store_id = 0)
{
$store_id = $store_id ? $store_id : self::$storeId;
$where = [
'square_id' => $squareId,
'store_id' => $store_id
];
return static::get($where, []);
}
/**
* 新增记录
* @param array $data

@ -95,10 +95,15 @@ class Payment extends BaseService
$userInfo = UserService::getCurrentLoginUser(true);
// 根据指定客户端获取可用的支付方式
$PaymentModel = new PaymentModel;
$methods = $PaymentModel->getMethodsByClient($this->client);
// 获取结算订单信息
$OrderModel = new OrderModel;
$orderInfo = $OrderModel->getUnpaidOrderDetail($this->orderId);
//当前商户是系统自动创建的商户,自动读取商城主的支付配置
$model = \app\store\model\Merchant::detail($orderInfo['merchant_id']);
$merchantId = ($model && $model->channel_id > 0) ? 0 : $orderInfo['merchant_id'];
$methods = $PaymentModel->getMethodsByClient($this->client, true, $orderInfo['store_id'], $merchantId);
return [
'order' => $orderInfo,
'personal' => $userInfo,
@ -121,8 +126,16 @@ class Payment extends BaseService
$this->orderInfo = OrderModel::getDetail($this->orderId);
// 订单支付事件
$this->orderPayEvent();
//判断当前订单是否需要设置为分账订单
if ($this->orderInfo->commission_ratio > 0) {
$precent = $this->orderInfo->commission_ratio / 1000;
$precentPrice = round($precent * $this->orderInfo->pay_price, 2);
if ($precentPrice > 0) {
$extra['profit_sharing'] = TRUE;
}
}
// 构建第三方支付请求的参数
$payment = $this->unifiedorder($extra,$this->orderInfo['merchantId']);
$payment = $this->unifiedorder($extra,$this->orderInfo->merchant_id);
// 记录第三方交易信息
$this->recordPaymentTrade($payment);
// 返回结果
@ -144,8 +157,11 @@ class Payment extends BaseService
if (!in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {
return false;
}
//新增获取商户的支付配置问题
$trade = PaymentTradeModel::where('out_trade_no', $outTradeNo)->find();
$orderInfo = OrderModel::where('trade_id', $trade['trade_id'] ?? 0)->field('merchant_id')->find();
// 获取支付方式的配置信息
$options = $this->getPaymentConfig();
$options = $this->getPaymentConfig($orderInfo['merchant_id'] ?? 0);
// 构建支付模块
$Payment = PaymentFacade::store($this->method)->setOptions($options, $this->client);
// 执行第三方支付查询API
@ -254,6 +270,9 @@ class Payment extends BaseService
private function getPaymentConfig(int $merchantId = null)
{
$PaymentModel = new PaymentModel;
//当前商户是系统自动创建的商户,自动读取商城主的支付配置
$model = \app\store\model\Merchant::detail($merchantId);
$merchantId = ($model && $model->channel_id > 0) ? 0 : $merchantId;
$templateInfo = $PaymentModel->getPaymentInfo($this->method, $this->client, $this->getStoreId(), $merchantId);
return $templateInfo['template']['config'][$this->method];
}

@ -876,6 +876,7 @@ class Checkout extends BaseService
'platform' => getPlatform(),
'store_id' => $this->storeId,
'merchant_id' => $order['merchantId'] ?? 0,
'commission_ratio' => $order['commission_ratio'] ?? 0,
'expect_receive_time' => $this->param['expect_receive_time'],//期待收货时间
'is_street_take' => $this->param['is_street_take'],//是否街边1-在 0-不在
'to_store_time' => $this->param['to_store_time'],//预计到店时间

@ -15,6 +15,8 @@ namespace app\api\service\order;
use think\facade\Event;
use app\api\model\User as UserModel;
use app\api\model\Order as OrderModel;
use app\common\model\Merchant as merchantModel;
use app\common\model\MerchantPay as merchantPayModel;
use app\api\model\PaymentTrade as PaymentTradeModel;
use app\api\model\user\BalanceLog as BalanceLogModel;
use app\api\service\order\source\Factory as OrderSourceFactory;
@ -292,6 +294,7 @@ class PaySuccess extends BaseService
$this->updateOrderStatus();
// 累积用户总消费金额
UserModel::setIncPayMoney($orderInfo['user_id'], (float)$orderInfo['pay_price']);
// 记录订单支付信息
$this->updatePayInfo();
});
@ -349,6 +352,19 @@ class PaySuccess extends BaseService
'user_id' => (int)$orderInfo['user_id'],
'money' => -$orderInfo['pay_price'],
], ['order_no' => $orderInfo['order_no']]);
// //增加商户支付详情
// $model = \app\store\model\Merchant::detail($orderInfo['merchant_id']);
// $precent = 1;
// if ($model['commission_ratio']) {
// $precent = (1 - $model['commission_ratio'] / 1000);
// }
// $precentPrice = round($precent * $orderInfo['pay_price'], 2);
// (new merchantPayModel())->addDetail($orderInfo, $precentPrice);
// //累计商户余额支付金额
// merchantModel::setIncTotal($orderInfo['merchant_id'], $precentPrice);
}
// 将第三方交易记录更新为已支付状态
if (in_array($this->method, [PaymentMethodEnum::WECHAT, PaymentMethodEnum::ALIPAY])) {

@ -0,0 +1,206 @@
<?php
declare (strict_types=1);
namespace app\command;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use think\facade\Db;
use app\common\model\Order;
use app\common\model\Store;
use app\common\enum\payment\Method as PaymentMethodEnum;
use app\common\model\MerchantPay as merchantPayModel;
use app\common\model\Merchant as merchantModel;
use EasyWeChat\Factory;
use app\common\model\PaymentTemplate;
use app\common\model\Payment;
use app\common\model\PaymentTrade;
use app\common\model\wxapp\Setting;
use app\common\enum\Client as ClientEnum;
use app\common\library\payment\Facade as PaymentFacade;
use app\common\library\Log;
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
class ProfitSharing extends Command
{
protected function configure()
{
// 指令配置
$this->setName('ProfitSharing')->setDescription('自动分账');
$this->addArgument("store_id");
$this->addArgument("div");
$this->addArgument("mod");
}
protected function execute(Input $input, Output $output)
{
$store_id = $input->getArgument("store_id");
$div = $input->getArgument("div");
$mod = $input->getArgument("mod");
$limit = 100;
while (TRUE) {
echo $store_id.PHP_EOL;
$sql = "SELECT store_id FROM `yoshop_store` WHERE store_id > " . $store_id . " AND store_id % ". $div . " = ". $mod ." AND store_version = 1 AND is_delete = 0 AND is_recycle = 0 AND status = 1 order by store_id asc LIMIT ".$limit;
$stores = Db::query($sql);
if (!$stores) {
echo "没有多商户商城了".PHP_EOL;
return false;
}
//var_dump($stores);
foreach ($stores as $store) {
$where = [];
//查询已完成的订单,并且未分账的订单
$where[] = ['order_status','=', 30];
$where[] = ['pay_status','=', 20];
$where[] = ['is_refund','=', 10];
$where[] = ['is_delete','=', 0];
$where[] = ['profitsharing_status','=', 0];
$where[] = ['store_id','=', $store['store_id']];
$where[] = ['merchant_id','>', 0];
$where[] = ['commission_ratio','>', 0];
$orders = Order::where($where)
->field('order_id,total_price,order_price,pay_price,pay_method,cost_price,merchant_id,store_id,order_status,pay_status,delivery_status,receipt_status,delivery_type,delivery_time,create_time,trade_id,commission_ratio')
->select();
// var_dump($orders->toArray());
// exit();
if ($orders->isEmpty()) {
echo $store['store_id']."没有已完成的订单要分账".PHP_EOL;
continue;
}
//微信支付订单抽佣给平台、余额支付抽佣给平台,把订单金额记录到商户账上
foreach ($orders as $order) {
try {
//余额支付
if ($order->pay_method == PaymentMethodEnum::BALANCE) {
//增加商户支付详情
$model = \app\store\model\Merchant::detail($order->merchant_id, $order->store_id);
$precent = 1;
if ($model['commission_ratio'] > 0) {
$precent = (1 - $model['commission_ratio'] / 1000);
}
$precentPrice = round($precent * $order->pay_price, 2);
(new merchantPayModel())->addDetail($order, $precentPrice);
//累计商户余额支付金额
merchantModel::setIncTotal($order->merchant_id, $precentPrice);
//更新
$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 2, 'profitsharing_time' => time()]);
echo "余额支付分账成功".PHP_EOL;
var_dump($ret);
} elseif($order->pay_method == PaymentMethodEnum::WECHAT){//微信支付
//商户微信支付配置
$payment = Payment::where('store_id', $order->store_id)->where('merchant_id', $order->merchant_id)->where('method',PaymentMethodEnum::WECHAT)->where('is_enable', 1)->find();
if (!$payment) {
echo $store['store_id']."微信支付方式没有配置".PHP_EOL;
continue;
}
$payment_template = PaymentTemplate::where('template_id', $payment->template_id)->where('is_delete', 0)->find();
if (!$payment_template) {
echo $store['store_id']." ".$payment->template_id."微信支付模版没有配置".PHP_EOL;
continue;
}
$wechat_config = $payment_template['config'] ?? [];
if (!$wechat_config) {
echo $store['store_id'].$payment->template_id."微信支付模版没有配置11".PHP_EOL;
continue;
}
$wechat_config = $wechat_config['wechat']['normal'] ?? [];
//小程序配置
$mini = Setting::where('store_id', $order->store_id)->find();
if (!$mini) {
echo $store['store_id']."小程序配置没有".PHP_EOL;
continue;
}
$mini_config = $mini['values'] ?? [];
if (!$mini_config) {
echo $store['store_id'].$payment->template_id."微信支付模版没有配置11".PHP_EOL;
continue;
}
//支付信息初始化
$PaymentModel = new Payment;
$templateInfo = $PaymentModel->getPaymentInfo(PaymentMethodEnum::WECHAT, ClientEnum::MP_WEIXIN, $order->store_id, $order->merchant_id);
$options = $templateInfo['template']['config'][PaymentMethodEnum::WECHAT];
$payment = PaymentFacade::store(PaymentMethodEnum::WECHAT)->setOptions($options, ClientEnum::MP_WEIXIN);
//平台微信支付配置信息
$platform_payment = Payment::where('store_id', $order->store_id)->where('merchant_id', 0)->where('method',PaymentMethodEnum::WECHAT)->where('is_enable', 1)->find();
if (!$platform_payment) {
echo $store['store_id']."微信支付方式没有配置".PHP_EOL;
continue;
}
$platform_payment_template = PaymentTemplate::where('template_id', $platform_payment->template_id)->where('is_delete', 0)->find();
if (!$platform_payment_template) {
echo $store['store_id'].$platform_payment->template_id."微信支付模版没有配置".PHP_EOL;
continue;
}
$platform_wechat_config = $platform_payment_template['config'] ?? [];
if (!$platform_wechat_config) {
echo $store['store_id'].$platform_payment->template_id."微信支付模版没有配置11".PHP_EOL;
continue;
}
$platform_wechat_config = $platform_wechat_config['wechat']['normal'] ?? [];
var_dump($order->trade_id);
$payment_trade = PaymentTrade::where('trade_id', $order->trade_id)->field('trade_no')->find();
if (!$payment_trade) {
echo $store['store_id'].$platform_payment->template_id."没有交易流水号".PHP_EOL;
continue;
}
if ($order->commission_ratio <= 0) {
echo $order->merchant_id."当前商户无需抽佣".PHP_EOL;
continue;
}
$precent = $order->commission_ratio / 1000;
$precentPrice = round($precent * $order->pay_price * 100, 2);
var_dump($precentPrice);
//$precentPrice = 100;
if ($precentPrice <= 0) {
echo $order->order_id.":当前订单抽佣金额小于等于0".$precentPrice.PHP_EOL;
continue;
}
//var_dump($payment);
//$ret = $payment->addReceiver("MERCHANT_ID", $platform_wechat_config['mchId'], "武汉市汉阳区静好电子商务商行(个体工商户)", "HEADQUARTER");
$ret = $payment->addReceiver("MERCHANT_ID", $platform_wechat_config['mchId'], $platform_payment_template['name'], "HEADQUARTER");
//exit();
$transaction_id = $payment_trade->trade_no;
$out_trade_no = "ps".date("YmdHis").mt_rand(1000,9999);
$receivers = [
[
"type" => "MERCHANT_ID",
"account" => $platform_wechat_config['mchId'],
"amount" => $precentPrice,
"description" => "分到平台"
]
];
var_dump($receivers);
$sharing = $payment->profitsharing($transaction_id, $out_trade_no, $receivers);
var_dump($sharing);
//更新
$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 1, 'profitsharing_time' => time(),'out_order_no' => $out_trade_no]);
echo "微信支付分账中".PHP_EOL;
var_dump($ret);
}
} catch (\Exception $e) {
Log::append('微信支付分账失败', [$order->order_id.":".$e->getMessage()]);
echo $order->order_id.":".$e->getMessage();
//$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 3, 'profitsharing_time' => time(),'out_order_no' => $out_trade_no]);
continue;
}
}
}
$store_id = end($stores)['store_id'];
}
}
}

@ -0,0 +1,131 @@
<?php
declare (strict_types=1);
namespace app\command;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use think\facade\Db;
use app\common\model\Order;
use app\common\model\Store;
use app\common\enum\payment\Method as PaymentMethodEnum;
use app\common\model\MerchantPay as merchantPayModel;
use app\common\model\Merchant as merchantModel;
use EasyWeChat\Factory;
use app\common\model\PaymentTemplate;
use app\common\model\Payment;
use app\common\model\PaymentTrade;
use app\common\model\wxapp\Setting;
use app\common\enum\Client as ClientEnum;
use app\common\library\payment\Facade as PaymentFacade;
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
class ProfitSharingResult extends Command
{
protected function configure()
{
// 指令配置
$this->setName('ProfitSharingResult')->setDescription('自动分账');
$this->addArgument("order_id");
}
protected function execute(Input $input, Output $output)
{
$order_id = $input->getArgument("order_id");
if ($order_id) {
$where[] = ['order_id','=', $order_id];
} else {
//查询已完成的订单,并且未分账的订单
$where[] = ['order_status','=', 30];
$where[] = ['pay_status','=', 20];
$where[] = ['is_refund','=', 10];
$where[] = ['is_delete','=', 0];
$where[] = ['profitsharing_status','=', 1];
$where[] = ['merchant_id','>', 0];
$where[] = ['pay_method','=', PaymentMethodEnum::WECHAT];
}
$orders = Order::where($where)
->field('order_id,total_price,order_price,pay_price,pay_method,cost_price,merchant_id,store_id,order_status,pay_status,delivery_status,receipt_status,delivery_type,delivery_time,create_time,out_order_no,trade_id,commission_ratio')
->select();
// var_dump($orders->toArray());
// exit();
if ($orders->isEmpty()) {
echo "没有已完成的订单要分账".PHP_EOL;
return false;
}
//微信支付订单抽佣给平台、余额支付抽佣给平台,把订单金额记录到商户账上
foreach ($orders as $order) {
try {
//商户微信支付配置
$payment = Payment::where('store_id', $order->store_id)->where('merchant_id', $order->merchant_id)->where('method',PaymentMethodEnum::WECHAT)->where('is_enable', 1)->find();
if (!$payment) {
echo $order['store_id']."微信支付方式没有配置".PHP_EOL;
continue;
}
$payment_template = PaymentTemplate::where('template_id', $payment->template_id)->where('is_delete', 0)->find();
if (!$payment_template) {
echo $order['store_id'].$payment->template_id."微信支付模版没有配置".PHP_EOL;
continue;
}
$wechat_config = $payment_template['config'] ?? [];
if (!$wechat_config) {
echo $order['store_id'].$payment->template_id."微信支付模版没有配置11".PHP_EOL;
continue;
}
$wechat_config = $wechat_config['wechat']['normal'] ?? [];
//小程序配置
$mini = Setting::where('store_id', $order->store_id)->find();
if (!$mini) {
echo $order['store_id']."小程序配置没有".PHP_EOL;
continue;
}
$mini_config = $mini['values'] ?? [];
if (!$mini_config) {
echo $order['store_id'].$payment->template_id."微信支付模版没有配置11".PHP_EOL;
continue;
}
//分账
//支付信息初始化
$PaymentModel = new Payment;
$templateInfo = $PaymentModel->getPaymentInfo(PaymentMethodEnum::WECHAT, ClientEnum::MP_WEIXIN, $order->store_id, $order->merchant_id);
$options = $templateInfo['template']['config'][PaymentMethodEnum::WECHAT];
$payment = PaymentFacade::store(PaymentMethodEnum::WECHAT)->setOptions($options, ClientEnum::MP_WEIXIN);
// var_dump($payment);
// exit();
$payment_trade = PaymentTrade::where('trade_id', $order->trade_id)->field('trade_no')->find();
if (!$payment_trade) {
echo $order['store_id']."没有交易流水号".PHP_EOL;
continue;
}
$transaction_id = $payment_trade->trade_no;
$sharing = $payment->profitsharingQuery($order->out_order_no, $transaction_id);
var_dump($sharing);
if ($sharing['state'] == "FINISHED") {
//更新
$ret = Order::where('order_id',$order->order_id)->update(['profitsharing_status' => 2, 'profitsharing_time' => time()]);
echo "微信支付分账结果".PHP_EOL;
var_dump($ret);
}
} catch (\Exception $e) {
echo $e->getMessage();
continue;
}
}
}
}

@ -21,7 +21,7 @@ class SyncGoodsToEs extends Command
protected function execute(Input $input, Output $output)
{
$goodsService = new GoodsEs();
$goods = $goodsService->list([]);
$goods = $goodsService->list();
var_dump($goods);
}

@ -256,11 +256,13 @@ class Client
}
if (!empty($this->queryParams['order'])) {
$queryParams['body']['sort'] = [
key($this->queryParams['order']) => [
'order' => current($this->queryParams['order'])
]
];
foreach ($this->queryParams['order'] as $key => $row) {
$queryParams['body']['sort'][] = [
key($row) => [
'order' => current($row)
]
];
}
}
$queryParams['body']['query']['bool']['filter'] = $filter;
@ -349,7 +351,7 @@ class Client
* @param string $index_name
* @param string $type_name
*/
public function addDoc($id, $doc, string $type_name = '_doc'): array
public function addDoc($id, $doc, string $type_name = '_doc')
{
$params = [
'index' => $this->index,
@ -386,8 +388,8 @@ class Client
protected function settings()
{
return [
'number_of_shards' => 5,
'number_of_replicas' => 1
'number_of_shards' => 1,
'number_of_replicas' => 0
];
}
@ -484,9 +486,9 @@ class Client
$check = $this->indices()->exists($params);
if ($check) {
throw new Exception('index: ' . $this->index . ' already exists');
}
// if ($check) {
// throw new Exception('index: ' . $this->index . ' already exists');
// }
$params = [
'index' => $this->index,
@ -655,12 +657,12 @@ class Client
}
/**
* 更新索引
* @return array @todo
*/
public function updateIndex()
public function updateIndex($mappings)
{
@ -672,7 +674,7 @@ class Client
'body' => [
'properties' => $this->mappings()
'properties' => $mappings
]

@ -63,6 +63,13 @@ abstract class Driver
* @return bool
* @throws BaseException
*/
abstract public function addReceiver(string $type, string $account, string $name, string $relation_type = "HEADQUARTER", string $custom_relation = ""): bool;
abstract public function profitsharing(string $transaction_id, string $out_order_no, array $receivers): bool;
abstract public function profitsharingQuery(string $out_order_no, string $transaction_id): ?array;
abstract public function unify(string $outTradeNo, string $totalFee, array $extra = []): bool;
/**
@ -73,6 +80,7 @@ abstract class Driver
*/
abstract public function tradeQuery(string $outTradeNo): ?array;
/**
* 获取异步回调的请求参数
* @return array

@ -49,7 +49,40 @@ class Wechat extends Driver
}
return $this->app;
}
/* 统一下单API
* @param string $outTradeNo 交易订单号
* @param string $totalFee 实际付款金额
* @param array $extra 附加的数据 (需要携带openid)
* @return bool
* @throws BaseException
*/
public function addReceiver(string $type, string $account, string $name, string $relation_type = "HEADQUARTER", string $custom_relation = ""): bool
{
if (!$this->getApp()->setOptions($this->options, $this->client)->addReceiver($type, $account, $name, $relation_type, $custom_relation)) {
$this->setError($this->getApp()->getError());
return false;
}
return true;
}
/**
* 统一下单API
* @param string $outTradeNo 交易订单号
* @param string $totalFee 实际付款金额
* @param array $extra 附加的数据 (需要携带openid)
* @return bool
* @throws BaseException
*/
public function profitsharing(string $transaction_id, string $out_order_no, array $receivers): bool
{
if (!$this->getApp()->setOptions($this->options, $this->client)->profitsharing($transaction_id, $out_order_no, $receivers)) {
$this->setError($this->getApp()->getError());
return false;
}
return true;
}
public function profitsharingQuery(string $out_order_no, string $transaction_id): ?array{
return $this->getApp()->profitsharingQuery($out_order_no, $transaction_id);
}
/**
* 统一下单API
* @param string $outTradeNo 交易订单号

@ -63,7 +63,129 @@ class V3
$this->config = $this->getConfig($options);
return $this;
}
/**
* 微信分账-添加分账人
* [addReceiver description]
* @param string $type [description]
* @param string $account [description]
* @param string $name [description]
* @param string $relation_type [description]
* @param string $custom_relation [description]
*/
public function addReceiver(string $type, string $account, string $name, string $relation_type = "HEADQUARTER", string $custom_relation = ""): bool{
//是否解冻剩余未分资金,暂时请求分账即解冻,后续可看需求调整
$unfreeze_unsplit = true;
// 下单的参数
$params = [
'type' => $type,
'account' => $account,
'name' => $this->getEncrypt($name),
'relation_type' => $relation_type,
//'custom_relation' => $custom_relation,
];
// 普通商户参数和服务商支付参数
if ($this->isProvider()) {
$params['sp_appid'] = $this->config['app_id'];
$params['sp_mchid'] = $this->config['mch_id'];
$params['sub_appid'] = $this->config['sub_appid'];
$params['sub_mchid'] = $this->config['sub_mchid'];
} else {
$params['appid'] = $this->config['app_id'];
//$params['mchid'] = $this->config['mch_id'];
}
try {
// 统一下单API
// Doc: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
$resp = $this->getApp()
->chain($this->getAddReceiverUrl())
->post(['json' => $params,'headers' => ['Accept' => 'application/json','Wechatpay-Serial' => $this->platformCertificateSerial]]);
// 记录api返回的数据
$unifyResult = helper::jsonDecode((string)$resp->getBody());
//var_dump($unifyResult);exit;
return true;
} catch (\Throwable $e) {
// 异常处理
$message = $this->getThrowMessage($e);
$this->throwError('profitsharing', "微信支付分账添加分账人:{$message}");
}
return false;
}
/**
* 微信发起分账
* [profitsharing description]
* @param string $transaction_id [description]
* @param string $out_order_no [description]
* @param array $receivers [description]
* @return [type] [description]
*/
public function profitsharing(string $transaction_id, string $out_order_no, array $receivers): bool{
// 下单的参数
$params = [
'out_order_no' => $out_order_no,
'transaction_id' => $transaction_id,
'receivers' => $receivers,
'unfreeze_unsplit' => true,
];
// 普通商户参数和服务商支付参数
if ($this->isProvider()) {
$params['sp_appid'] = $this->config['app_id'];
$params['sp_mchid'] = $this->config['mch_id'];
$params['sub_appid'] = $this->config['sub_appid'];
$params['sub_mchid'] = $this->config['sub_mchid'];
} else {
$params['appid'] = $this->config['app_id'];
$params['mchid'] = $this->config['mch_id'];
}
try {
// 统一下单API
// Doc: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
$resp = $this->getApp()
->chain($this->getProfitUrl())
->post(['json' => $params]);
// 记录api返回的数据
$unifyResult = helper::jsonDecode((string)$resp->getBody());
var_dump($unifyResult);
//exit;
return true;
} catch (\Throwable $e) {
// 异常处理
$message = $this->getThrowMessage($e);
$this->throwError('profitsharing', "微信支付分账失败:{$message}");
}
return false;
}
/**
* 分账查询
* [profitsharingQuery description]
* @param string $out_order_no [description]
* @param string $transaction_id [description]
* @return [type] [description]
*/
public function profitsharingQuery(string $out_order_no, string $transaction_id): ?array
{
// 下单的参数
$params = ['transaction_id' => $transaction_id];
$url = $this->getProfitUrl()."/".$out_order_no."?transaction_id=".$transaction_id;
try {
$resp = $this->getApp()
->chain($url)
->get();
// 记录api返回的数据
$result = helper::jsonDecode((string)$resp->getBody());
var_dump($result);
// 判断订单支付成功
return $result;
} catch (\Throwable $e) {
// 异常处理
$message = $this->getThrowMessage($e);
$this->throwError('tradeQuery', "微信支付交易查询失败:{$message}");
}
return null;
}
/**
* 统一下单API
* @param string $outTradeNo 交易订单号
@ -80,8 +202,11 @@ class V3
'description' => '线上商城商品',
'notify_url' => $this->notifyUrl(), // 支付结果异步通知地址
'amount' => ['total' => (int)helper::bcmul($totalFee, 100), 'currency' => 'CNY'],
'scene_info' => ['payer_client_ip' => \request()->ip()]
'scene_info' => ['payer_client_ip' => \request()->ip()],
'settle_info' => ['profit_sharing' => $extra['profit_sharing'] ?? false],//是否指定分账
];
// var_dump($params);
// exit();
// 普通商户参数和服务商支付参数
if ($this->isProvider()) {
$params['sp_appid'] = $this->config['app_id'];
@ -433,7 +558,9 @@ class V3
// 从「微信支付平台证书」中获取「证书序列号」
$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateFilePath);
//设置类属性
$this->platformCertificateSerial = $platformCertificateSerial;
// 构造一个 APIv3 客户端实例
return Builder::factory([
// 微信支付商户号
@ -507,6 +634,25 @@ class V3
];
}
}
/**
* 平台私密信息加密算法
* [getEncrypt description]
* @param [type] $str [description]
* @return [type] [description]
*/
private function getEncrypt($str) {
//$str是待加密字符串
$public_key_path = $this->config['platform_cert_path'];
$public_key = file_get_contents($public_key_path);
$encrypted = '';
if (openssl_public_encrypt($str, $encrypted, $public_key, OPENSSL_PKCS1_OAEP_PADDING)) {
//base64编码
$sign = base64_encode($encrypted);
} else {
throw new Exception('encrypt failed');
}
return $sign;
}
/**
* 异步回调地址
@ -636,4 +782,22 @@ class V3
{
return 'v3/transfer/batches';
}
/**
* 分账API的Url
* @return string
*/
private function getProfitUrl(): string
{
return 'v3/profitsharing/orders';
}
/**
* 分账API的Url
* @return string
*/
private function getAddReceiverUrl(): string
{
return 'v3/profitsharing/receivers/add';
}
}

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\HasOne;
/**
* 文章模型
@ -32,4 +33,51 @@ class Channel extends BaseModel
// self::$storeId = 0;
// app()->request->setStoreId(0);
}
/**
* 关联logo图片
* @return HasOne
*/
public function logoImage(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'logo_image_id');
}
/**
* 关联logo图片
* @return HasOne
*/
public function licenseImage(): HasMany
{
return $this->HasMany('UploadFile', 'file_id', 'license_img_id');
}
/**
* 菜单信息
* @param int|array $where
* @return static|array|null
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function detail($where)
{
$query = static::withoutGlobalScope();
is_array($where) ? $query->where($where) : $query->where('id', '=', $where);
return $query->find();
}
/**
* 获取列表数据
* @param bool $isRecycle
* @return \think\Paginator
* @throws \think\db\exception\DbException
*/
public function getList(array $param = [], int $pageSize = 15): \think\Paginator
{
return $this->with(['logoImage'])
->where('status', '=', 1)
->order(['weigh' => 'asc', 'create_time' => 'desc'])
->paginate($pageSize);
}
}

@ -53,6 +53,7 @@ class GoodsCategoryRel extends BaseModel
public static function getcategory(int $storeId = null,int $merchantId = null) {
$where = [
'b.store_id' => $storeId,
'a.is_delete' => 0
];
if (!empty($merchantId)) {
$where['a.merchant_id'] = $merchantId;

@ -69,15 +69,31 @@ class Merchant extends BaseModel
* @param int $storeId
* @return static|array|null
*/
public static function detail(int $merchantId)
public static function detail(int $merchantId, $store_id = 0)
{
$store_id = $store_id ? $store_id : self::$storeId;
$where = [
'merchant_id' => $merchantId,
'store_id' => self::$storeId
'store_id' => $store_id
];
return static::get($where, []);
}
/**
* 详情信息
* @param int $storeId
* @return static|array|null
*/
public static function detailbystore(int $merchantId, int $storeId = 0)
{
$where = [
'merchant_id' => $merchantId,
'store_id' => $storeId
];
return static::get($where, []);
}
/**
* 获取列表数据
* @param bool $isRecycle 是否在回收站
@ -111,7 +127,7 @@ class Merchant extends BaseModel
// 搜索关键词
!empty($params['search']) && $filter[] = ['shop_name|shop_label', 'like', "%{$params['search']}%"];
// 门店状态
//is_numeric($params['status']) && $filter[] = ['status', '=', (int)$params['status']];
isset($params['is_select_mechant']) && $filter[] = ['is_select_mechant', '=', (int)$params['is_select_mechant']];
return $filter;
}
@ -123,4 +139,17 @@ class Merchant extends BaseModel
{
return $this->save(['is_delete' => 1]);
}
/**
* 累积用户可用余额
* @param int $userId
* @param float $money
* @return mixed
*/
public static function setIncTotal(int $merchantId, $money)
{
(new static)->setInc($merchantId, 'total_amount', $money);
(new static)->setInc($merchantId, 'available_amount', $money);
return true;
}
}

@ -0,0 +1,71 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\common\model;
use cores\BaseModel;
use think\model\relation\HasOne;
/**
* Class Store
* @package app\common\model
*/
class MerchantPay extends BaseModel
{
// 定义表名
protected $name = 'merchant_pay';
// 定义主键
protected $pk = 'merchant_pay_id';
/**
* 累积用户可用余额
* @param int $userId
* @param float $money
* @return mixed
*/
public function addDetail($orderInfo, $precentPrice)
{
if (!empty($orderInfo['merchant_id'])) {
$data = [
'order_id' => $orderInfo['order_id'],
//'store_id' => $orderInfo['store_id'],
'merchant_id' => $orderInfo['merchant_id'],
'total_amount' => $precentPrice,
];
return $this->save($this->createData($data));
}
return true;
}
/**
* 创建数据
* @param array $data
* @return array
*/
private function createData(array $data): array
{
$data['store_id'] = self::$storeId;
return $data;
}
/**
* 软删除
* @return bool
*/
public function setDelete(): bool
{
return $this->save(['is_delete' => 1]);
}
}

@ -88,11 +88,12 @@ class Payment extends BaseModel
if (empty($merchantId)) {
$merchantId = 0;
}
if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) {
//if (!$data = Cache::get("payment_{$storeId}_{$merchantId}")) {
if (true) {
// 获取所有支付方式
$data = $model->dataByStorage($storeId, $defaultData, $merchantId);
// 写入缓存中
Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data);
//Cache::tag('cache')->set("payment_{$storeId}_{$merchantId}", $data);
}
// 重组缓存数据 (多维)
return static::reorganize2($defaultData, $data);
@ -124,6 +125,7 @@ class Payment extends BaseModel
foreach ($data as &$item) {
$item['methods'] = array_values($item['methods']);
}
//unset($item);
return $data;
}
@ -140,9 +142,9 @@ class Payment extends BaseModel
{
// 获取数据库中所有的支付方式
$where = [];
if (isset($merchantId) && $merchantId) {
//if (isset($merchantId) && $merchantId) {
$where['merchant_id'] = $merchantId;
}
//}
$list = $this->where($where)->where('store_id', '=', $storeId)->select();
if ($list->isEmpty()) {
return [];

@ -110,9 +110,16 @@ class PaymentTemplate extends BaseModel
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getAll()
public function getAll($merchantId = 0)
{
return $this->where('is_delete', '=', 0)
$where = [
['is_delete', '=', 0],
];
// if (isset($merchantId) && $merchantId) {
// $where[] = ['merchant_id', '=', $merchantId];
// }
$where[] = ['merchant_id', '=', $merchantId];
return $this->where($where)
->order(['sort' => 'asc', $this->getPk()])
->select();
}

@ -92,6 +92,12 @@ class Store extends BaseModel
} else {
$list['rankingImg'] = null;
}
if ($list['login_img_id']) {
$files = UploadFile::getFileList([$list['login_img_id']]);
$list['loginImg'] = $files ? $files[0] : null;
} else {
$list['loginImg'] = null;
}
}
return $list ?? null;
} catch (\Exception $e) {

@ -106,7 +106,7 @@ class UploadFile extends BaseModel
public static function getFileList(array $fileIds, int $storeId = null)
{
return (new static)->where('file_id', 'in', $fileIds)
->where('store_id', '=', $storeId ?: self::$storeId)
//->where('store_id', '=', $storeId ?: self::$storeId)
->where('is_delete', '=', 0)
->select();
}

@ -8,68 +8,46 @@ class GoodsEs
{
private Client $esService;
private $index_name = 'goods_list';
private string $index_name = 'goods_list';
public function __construct()
{
$this->esService = Client::setEs('goods_list');
$this->esService = Client::setEs($this->index_name);
}
/**
* 查询商品列表
* @param $params
* @return
*/
public function list($params)
public function list($params = [],$page = 1, $limit = 10)
{
$page = 1;
$limit = 10;
// $body = [
// 'query' => [
// 'match_all' => []
// ],
// 'from' => ($page - 1) * $limit,
// 'size' => $limit,
// 'sort' => [
// 'id' => [
// 'order' => 'desc'
// ]
// ]
// ];
$data = $this->esService
return $this->esService
// ->setDebug()
->equal(['intro' => ''])
->from(1)
->size(10)
->order(['id' => 'desc'])
->like($params)
->from($page)
->size($limit)
->order(['goods_id' => 'desc'])
->query();
dd($data);
}
public function count($params = [],$page = 1, $limit = 10)
{
return $this->esService
// ->setDebug()
->like($params)
->from($page)
->size($limit)
->query(true);
}
/**
* 更新商品
*/
public function update($goods_id)
public function updateData($goods_id, $data)
{
$goods_id = 1;
$doc = [
'id' => $goods_id,
'video_title' => '少爷的甜蜜良药',
'director' => '吴宇森',
'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
'episode_count' => '12',
'wechat_vid' => 'wx_vid_1',
'duration' => '01:02:03',
'service_types' => '2,3',
];
return $this->esService->update($goods_id, $doc);
return $this->esService->update($goods_id, $data);
}
/**
@ -77,32 +55,57 @@ class GoodsEs
*/
public function detail($goods_id)
{
$goods_id = 1;
$res = $this->esService->getDoc($goods_id);
var_dump($res);
return $this->esService->getDoc($goods_id);
}
/**
* 创建商品
*/
public function createData($goods_id, $goods_list)
{
$goods_list['create_time'] = $goods_list['create_time'] ? strtotime($goods_list['create_time']) * 1000 : time() * 1000;
$goods_list['update_time'] = $goods_list['update_time'] ? strtotime($goods_list['update_time']) * 1000 : time() * 1000;
$goods_list['delivery_type'] = implode(',', $goods_list['delivery_type']);
return $this->esService->addDoc($goods_id, $goods_list)->asArray();
}
/**
* 批量创建商品
* @return
*/
public function create($goods_id)
public function batchCreateData()
{
$goods_id = 1;
$doc = [
'id' => $goods_id,
'video_title' => '少爷的甜蜜良药',
'director' => '吴宇森',
'intro' => '吴宇森导演的《少爷的甜蜜良药》是吴宇森导演的经典作品,讲述了一个boyfriend和girlfriend的故事,boyfriend因为工作原因,被拒了girlfriend的offer,然后boyfriend和girlfriend一起去一个地方,然后boyfriend和girlfriend',
'cover' => 'https://oss-duanju-file.luochen.com/cover/202404/62249c6a-5f57-45cf-90ac-be6de5890ce0.jpg?x-oss-process=image/resize,m_fixed,h_400,w_360',
'episode_count' => '12',
'wechat_vid' => 'wx_vid_1',
'duration' => '01:02:03',
'service_types' => '2,3',
];
$res = $this->esService->addDoc($goods_id, $doc);
var_dump($res);
for ($page = 1; $page<=134; $page++)
{
$this->addData($page);
sleep(1);
}
}
public function addData($page)
{
$goods_list = \app\common\model\Goods::where('goods_id', '>', 368257)
// ->order('goods_id desc')
->page($page)
->limit(2000)
->select()
->toArray();
//
$i = 0;
foreach ($goods_list as $value)
{
$value['create_time'] = strtotime($value['create_time']) * 1000;
$value['update_time'] = strtotime($value['update_time']) * 1000;
$value['delivery_type'] = implode(',', $value['delivery_type']);
$res = $this->esService->addDoc($value['goods_id'], $value)->asArray();
if($res['result'] == 'created')
{
$i++;
}
}
echo('同步成功'.$i.'条数据').PHP_EOL;
}
/**
@ -110,8 +113,15 @@ class GoodsEs
*/
public function delete($goods_id)
{
$res = $this->esService->deleteDoc($goods_id);
var_dump($res);
return $this->esService->deleteDoc($goods_id);
}
/**
* 删除索引
*/
public function deleteIndex()
{
return $this->esService->deleteIndexNew();
}
@ -126,41 +136,255 @@ class GoodsEs
$mapping = [
'properties' => [
'goods_id' => [
'type' => 'integer'
'type' => 'keyword'
],
'goods_type' => [
'type' => 'keyword'
],
'director' => [
'goods_name' => [
'type' => 'text',
"analyzer" => "ik_smart"
],
'intro' => [
'goods_no' => [
'type' => 'keyword',
],
'video_id' => [
'type' => 'integer'
],
'brand_id' => [
'type' => 'integer'
],
'video_cover_id' => [
'type' => 'integer'
],
'selling_point' => [
'type' => 'text',
"analyzer" => "ik_smart"
],
'cover' => [
'spec_type' => [
'type' => 'integer'
],
'cost_price_min' => [
'type' => 'float'
],
'goods_price_min' => [
'type' => 'float'
],
'goods_price_max' => [
'type' => 'float'
],
'line_price_min' => [
'type' => 'float'
],
'line_price_max' => [
'type' => 'float'
],
'stock_total' => [
'type' => 'integer'
],
'deduct_stock_type' => [
'type' => 'integer'
],
'is_restrict' => [
'type' => 'integer'
],
'restrict_total' => [
'type' => 'integer'
],
'restrict_single' => [
'type' => 'integer'
],
'content' => [
'type' => 'text',
],
'sales_initial' => [
'type' => 'integer'
],
'delivery_id' => [
'type' => 'integer'
],
'is_points_gift' => [
'type' => 'integer'
],
'is_points_discount' => [
'type' => 'integer'
],
'is_alone_points_discount' => [
'type' => 'integer'
],
'points_discount_config' => [
'type' => 'text'
],
'is_enable_grade' => [
'type' => 'integer'
],
'is_alone_grade' => [
'type' => 'integer'
],
'alone_grade_equity' => [
'type' => 'text'
],
'is_ind_dealer' => [
'type' => 'integer'
],
'dealer_money_type' => [
'type' => 'integer'
],
'first_money' => [
'type' => 'float'
],
'second_money' => [
'type' => 'float'
],
'third_money' => [
'type' => 'float'
],
'is_ind_delivery_type' => [
'type' => 'integer'
],
'delivery_type' => [
'type' => 'keyword'
],
'status' => [
'type' => 'integer'
],
'sort' => [
'type' => 'integer'
],
'store_id' => [
'type' => 'keyword'
],
'merchant_id' => [
'type' => 'keyword'
],
'create_time' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'update_time' => [
'type' => 'date',
'format' => 'yyyy-MM-dd HH:mm:ss'
],
'is_brand' => [
'type' => 'integer'
],
'is_new' => [
'type' => 'integer'
],
'paihang' => [
'type' => 'integer'
],
'remaizhishu' => [
'type' => 'integer'
],
'spu_id' => [
'type' => 'integer'
],
'channel' => [
'type' => 'keyword'
],
'unicode' => [
'type' => 'keyword'
],
'is_in_store' => [
'type' => 'integer'
],
'profit' => [
'type' => 'float'
],
'profit_rate' => [
'type' => 'float'
],
'cmmdty_model'=> [
'type' => 'keyword'
],
'remark' => [
'type' => 'text'
],
'sale_areas' => [
'type' => 'text'
],
'sale_areas_id' => [
'type' => 'keyword'
],
'episode_count' => [
'data_type' => [
'type' => 'integer'
],
'is_pool' => [
'type' => 'integer'
],
'is_self' => [
'type' => 'integer'
],
'link' => [
'type' => 'keyword'
],
'wechat_vid' => [
'origin_goods_id' => [
'type' => 'integer'
],
'link_other' => [
'type' => 'text'
],
'goods_no_other' => [
'type' => 'keyword'
],
'duration' => [
'region' => [
'type' => 'text'
],
'region_text' => [
'type' => 'text'
],
'specific_value' => [
'type' => 'keyword'
],
'service_types' => [
'cate_status' => [
'type' => 'integer'
],
'is_check' => [
'type' => 'integer'
],
'goods_source' => [
'type' => 'keyword'
],
'delivery_time' => [
'type' => 'integer'
],
'distribute_price' => [
'type' => 'float'
],
'shop_price' => [
'type' => 'float'
],
'is_has_banner' => [
'type' => 'integer'
],
'is_has_detail' => [
'type' => 'integer'
],
'is_jingpin' => [
'type' => 'integer'
],
'sale_time' => [
'type' => 'integer'
],
'markup_rate' => [
'type' => 'integer'
]
]
];
$res = $this->esService->createIndexNew($mapping);
var_dump($res);
return $this->esService->createIndexNew($mapping);
}
/**
* 设置分词字段
*/
public function analyze()
{
return $this->esService->analyze('goods_name');
}
}

@ -185,7 +185,8 @@ class Goods extends Controller
if (!$list) {
return $this->renderError("没有需要加入商品池的自营商品");
}
$goodsIds = array_column($list, "goods_id");
$goodsIds = array_column($list->toArray(), "goods_id");
$state = $state ? 1 : 2;
if (!$model->setIsPool($goodsIds, $state)) {
return $this->renderError($model->getError() ?: '操作失败');
}

@ -75,7 +75,7 @@ class Merchant extends Controller
public function info(): Json
{
// 商城详情
$model = MerchantModel::detail($this->storeId);
$model = MerchantModel::detailbystore($this->storeId);
return $this->renderSuccess(['storeInfo' => $model]);
}
@ -86,7 +86,7 @@ class Merchant extends Controller
public function edit(): Json
{
// 商城详情
$model = MerchantModel::detail($this->postForm()['merchant_id']);
$model = MerchantModel::detailbystore($this->postForm()['merchant_id'], $this->storeId);
// 更新记录
if (!$model->edit($this->postForm())) {
return $this->renderError($model->getError() ?: '更新失败');
@ -118,7 +118,7 @@ class Merchant extends Controller
public function delete(int $merchantId): Json
{
// 门店详情
$model = MerchantModel::detail($merchantId);
$model = MerchantModel::detailbystore($merchantId, $this->storeId);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}

@ -34,7 +34,6 @@ class Payment extends Controller
{
$model = new PaymentModel;
$postform = $this->postForm();
//$postform['merchant_id'] = $this->merchantId;
if ($model->updateOptions($postform, $this->merchantId)) {
return $this->renderSuccess('更新成功');
}

@ -31,9 +31,9 @@ class Template extends Controller
*/
public function list(): Json
{
$merchantId = $this->request->param("merchantId");
//$merchantId = $this->request->param("merchantId");
$model = new PaymentTemplateModel;
$list = $model->getList($merchantId);
$list = $model->getList($this->merchantId);
return $this->renderSuccess(compact('list'));
}
@ -45,7 +45,7 @@ class Template extends Controller
public function all(): Json
{
$model = new PaymentTemplateModel;
$list = $model->getAll();
$list = $model->getAll($this->merchantId);
return $this->renderSuccess(compact('list'));
}

@ -37,13 +37,22 @@ class User extends Controller
{
// 当前登录用户的ID
$storeUserId = StoreUserService::getLoginUserId();
$roles = StoreRoleService::getLoginPermissions();
$modules = StoreModuleModel::getModules();
if ($roles['isSuper'] == 1) {
$modules = array_flip($modules);
// var_dump($modules1);
// exit();
unset($modules['apps-collector']);
$modules = array_keys($modules);
}
return $this->renderSuccess([
// 用户信息
'userInfo' => StoreUserModel::detail($storeUserId),
// 菜单权限
'roles' => StoreRoleService::getLoginPermissions(),
'roles' => $roles,
// 开启的功能模块
'modules' => StoreModuleModel::getModules(),
'modules' => $modules,
]);
}

@ -321,8 +321,12 @@ class Goods extends GoodsModel
}
$data['alone_grade_equity'] = $aloneGradeEquity;
$data['categoryIds'] = $this->dealCategory($data['categoryIds']);
$categoryIds = $data['categoryIds'];
if ($categoryIds && isset($categoryIds[0]['value'])) {
$categoryIds = array_column($categoryIds, 'value');
}
$data['categoryIds'] = $this->dealCategory($categoryIds);
return $data;
}
@ -330,6 +334,7 @@ class Goods extends GoodsModel
public function dealCategory($category){
$arr = [];
// var_dump($category);
// exit();
foreach ($category as $key => $value) {
//一级
$cate = CategoryRelModel::where('category_id', $value)->find();

@ -0,0 +1,65 @@
<?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\MerchantPay as StoreModel;
/**
* 商家记录表模型
* Class Store
* @package app\store\model
*/
class MerchantPay extends StoreModel
{
/**
* 更新记录
* @param array $data
* @return bool
*/
public function edit(array $data): bool
{
// 是否删除图片
!isset($data['logo_image_id']) && $data['logo_image_id'] = 0;
return $this->save($data) !== false;
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function add(array $data): bool
{
return $this->save($this->createData($data));
}
/**
* 创建数据
* @param array $data
* @return array
*/
private function createData(array $data): array
{
$data['store_id'] = self::$storeId;
return $data;
}
/**
* 软删除
* @return bool
*/
public function setDelete(): bool
{
return $this->save(['is_delete' => 1]);
}
}

@ -32,11 +32,11 @@ class Payment extends PaymentModel
// 生成写入的数据
$dataList = $this->buildData($form, $merchantId);
// 删除所有的支付方式记录
static::deleteAll([]);
static::deleteAll(['merchant_id' => $merchantId]);
// 批量写入商品图片记录
static::increased($dataList);
$res = static::increased($dataList);
// 删除系统设置缓存
Cache::delete('payment_' . self::$storeId);
Cache::delete('payment_' . self::$storeId."_".$merchantId);
return true;
}

@ -34,10 +34,13 @@ class PaymentTemplate extends PaymentTemplateModel
*/
public function getList($merchantId = 0): \think\Paginator
{
$where = [];
if (isset($merchantId) && $merchantId) {
$where = ['merchant_id', '=', $merchantId];
}
$where = [
['is_delete', '=', 0],
];
// if (isset($merchantId) && $merchantId) {
// $where[] = ['merchant_id', '=', $merchantId];
// }
$where[] = ['merchant_id', '=', $merchantId];
return $this->where($where)->where('is_delete', '=', 0)
->order(['sort' => 'asc', $this->getPk()])
->paginate(15);

@ -56,8 +56,7 @@ class UploadFile extends UploadFileModel
// 是否在回收站
$query->where('is_recycle', '=', (int)$params['isRecycle']);
// 查询列表数据
return $query->where('channel', '=', 10)
->where('is_delete', '=', 0)
return $query->where('is_delete', '=', 0)
->order(['file_id' => 'desc'])
->paginate(15);
}

@ -108,7 +108,7 @@ class Role extends RoleModel
$this->save($data);
// 新增角色菜单关系记录
RoleMenuModel::increased((int)$this['role_id'], $data['menus']);
RoleMenuModel::increased((int)$this['role_id'], $data['menus'], $data['store_id']);
});
return true;
}

@ -27,14 +27,14 @@ class RoleMenu extends RoleMenuModel
* @param array $menuIds
* @return array|false
*/
public static function increased(int $roleId, array $menuIds)
public static function increased(int $roleId, array $menuIds, int $storeId = 0)
{
$data = [];
foreach ($menuIds as $menuId) {
$data[] = [
'role_id' => $roleId,
'menu_id' => $menuId,
'store_id' => self::$storeId,
'store_id' => $storeId ? $storeId : self::$storeId,
];
}
return (new static)->addAll($data);

@ -15,6 +15,7 @@ namespace app\store\model\store;
use app\common\library\helper;
use app\common\model\store\User as StoreUserModel;
use app\admin\service\store\User as StoreUserService;
use think\facade\Db;
/**
* 商家用户模型
@ -124,7 +125,49 @@ class User extends StoreUserModel
}
return $list;
}
/**
* 新增记录
* @param array $data
* @return bool
*/
public function addNew(array $data): bool
{
$data['user_name'] = strtolower($data['user_name']);
if (self::checkExist($data['user_name'])) {
$this->error = '用户名已存在';
return false;
}
if ($data['password'] !== $data['password_confirm']) {
$this->error = '确认密码不正确';
return false;
}
if (empty($data['roles'])) {
$this->error = '请选择所属角色';
return false;
}
// 整理数据
$data['password'] = encryption_hash($data['password']);
$data['store_id'] = $data['storeId'] ?? self::$storeId;
$data['is_super'] = 0;
// 事务处理
$this->transaction(function () use ($data) {
$roles = $data['roles'];
$storeId = $data['storeId'];
unset($data['roles']);
unset($data['storeId']);
unset($data['password_confirm']);
$data['create_time'] = time();
// 新增管理员记录
$store_user_id = Db::name('store_user')->insertGetId($data);
// $ret = $this->save($data);
// var_dump($ret);
// exit();
// 新增角色关系记录
UserRole::increased((int)$store_user_id, $roles, $storeId);
});
return true;
}
/**
* 新增记录
* @param array $data
@ -147,7 +190,7 @@ class User extends StoreUserModel
}
// 整理数据
$data['password'] = encryption_hash($data['password']);
$data['store_id'] = self::$storeId;
$data['store_id'] = $data['storeId'] ?? self::$storeId;
$data['is_super'] = 0;
// 事务处理
@ -155,7 +198,7 @@ class User extends StoreUserModel
// 新增管理员记录
$this->save($data);
// 新增角色关系记录
UserRole::increased((int)$this['store_user_id'], $data['roles']);
UserRole::increased((int)$this['store_user_id'], $data['roles'], $data['storeId'] ?? 0);
});
return true;
}

@ -27,14 +27,14 @@ class UserRole extends UserRoleModel
* @param array $roleIds
* @return array|false
*/
public static function increased(int $storeUserId, array $roleIds)
public static function increased(int $storeUserId, array $roleIds, int $storeId = 0)
{
$data = [];
foreach ($roleIds as $roleId) {
$data[] = [
'store_user_id' => $storeUserId,
'role_id' => $roleId,
'store_id' => self::$storeId,
'store_id' => $storeId ? $storeId : self::$storeId,
];
}
return (new static)->addAll($data);

@ -13,5 +13,7 @@ return [
'UpdateCollectGoodsPrice' => 'app\command\UpdateCollectGoodsPrice',
'SyncStoreBasicData' => 'app\command\SyncStoreBasicData',
'syncGoodsToEs' => 'app\command\SyncGoodsToEs',
'ProfitSharing' => 'app\command\ProfitSharing',
'ProfitSharingResult' => 'app\command\ProfitSharingResult',
],
];

@ -49,7 +49,7 @@ return [
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database.charset', 'utf8'),
'charset' => env('database.charset', 'utf8mb4'),
// 数据库表前缀
'prefix' => env('database.prefix', 'yoshop_'),

@ -756,7 +756,7 @@ CREATE TABLE `yoshop_order` (
`user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
`is_delete` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除',
`store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
`merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户'
`merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户ID、商店ID 隔离商城里面的商户',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`order_id`),
@ -1728,25 +1728,44 @@ ALTER TABLE `yoshop_store_menu`
MODIFY COLUMN `type` tinyint UNSIGNED NOT NULL DEFAULT 10 COMMENT '菜单类型(10页面 20操作)' AFTER `menu_id`,
ADD COLUMN `is_page` tinyint(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否为页面(1是 0否)' AFTER `path`;
DROP TABLE IF EXISTS `yoshop_merchant`;
DROP TABLE IF EXISTS `yoshop_merchant`;
CREATE TABLE `yoshop_merchant` (
`merchant_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`shop_name` varchar(100) NOT NULL DEFAULT '' COMMENT '名称',
`shop_label` varchar(100) NOT NULL DEFAULT '' COMMENT '标签',
`logo_image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店logo图片ID',
`license_img_id` varchar(200) NOT NULL DEFAULT '' COMMENT '营业执照图片ID',
`user_name` varchar(100) NOT NULL DEFAULT '' COMMENT '买家用户名',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '门店排序(数字越小越靠前)',
`score` varchar(100) NOT NULL DEFAULT '' COMMENT '得分',
`sale` varchar(100) NOT NULL DEFAULT '' COMMENT '销量',
`merchant_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`shop_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
`shop_label` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '标签',
`logo_image_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '门店logo图片ID',
`license_img_id` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '营业执照图片ID',
`user_name` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '买家用户名',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '门店排序(数字越小越靠前)',
`is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除',
`store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`score` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '得分',
`sale` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '销量',
`is_select_mechant` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '是否精选商户',
`total_amount` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '累计金额',
`available_amount` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '可用金额',
`commission_ratio` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '抽佣比例',
PRIMARY KEY (`merchant_id`),
KEY `store_id` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户表';
DROP TABLE IF EXISTS `yoshop_merchant_pay`;
CREATE TABLE `yoshop_merchant_pay` (
`merchant_pay_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`store_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
`merchant_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商户id',
`order_id` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单id',
`is_delete` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '是否删除',
`create_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`update_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
`total_amount` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '金额',
`is_add` tinyint(3) UNSIGNED NOT NULL DEFAULT 1 COMMENT '是否为收入金额',
PRIMARY KEY (`merchant_pay_id`),
KEY `store_id` (`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='商户收入表';
DROP TABLE IF EXISTS `yoshop_style`;
CREATE TABLE `yoshop_style` (
`style_id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',

Loading…
Cancel
Save