Merge branch 'fxshop' into pifa

pifa
zyh 6 months ago
commit 13e36d232f
  1. 105
      app/admin/controller/Wxwholesaler.php
  2. 6
      app/api/controller/Invite.php
  3. 3
      app/api/controller/Notify.php
  4. 52
      app/api/controller/Region copy.php
  5. 2
      app/api/controller/Store.php
  6. 26
      app/api/controller/Wholesaler.php
  7. 3
      app/api/controller/dealer/Apply.php
  8. 1
      app/api/model/dealer/Apply.php
  9. 32
      app/api/model/dealer/Order.php
  10. 1
      app/api/model/wholesaler/Apply.php
  11. 2
      app/api/service/identity/Payment.php
  12. 329
      app/command/SyncCategoryAdmin.php
  13. 8
      app/command/SyncStoreBasicData.php
  14. 565
      app/command/SyncStoreBasicDataAdmin.php
  15. 61
      app/common/enum/user/UserTypeEnum.php
  16. 62
      app/common/library/wxserver/Wholesaler.php
  17. 18
      app/common/model/dealer/Order.php
  18. 14
      app/common/model/dealer/Referee.php
  19. 14
      app/common/model/dealer/User.php
  20. 2
      app/store/model/RetailDescribe.php
  21. 8
      app/store/model/dealer/Apply.php
  22. 11
      app/store/model/dealer/User.php
  23. 2
      app/timer/model/dealer/Order.php
  24. 4
      app/timer/service/dealer/Order.php
  25. 38
      config/database.php
  26. 2
      config/queue.php

@ -6,6 +6,7 @@ namespace app\admin\controller;
use app\common\library\wxserver\Wholesaler; use app\common\library\wxserver\Wholesaler;
use app\common\library\wxserver\Server; use app\common\library\wxserver\Server;
use app\job\controller\Wxholesaler as WxserverJob; use app\job\controller\Wxholesaler as WxserverJob;
use cores\exception\BaseException;
use PHPQRCode\QRcode; use PHPQRCode\QRcode;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\facade\Db; use think\facade\Db;
@ -189,13 +190,17 @@ class Wxwholesaler extends Controller
return $this->renderError('操作失败'); return $this->renderError('操作失败');
} }
/** 单个操作发布体验版
* @throws BaseException
*/
public function commitOne(): Json public function commitOne(): Json
{ {
$appid = $this->request->get('appid'); $appid = $this->request->get('appid');
$template_id = $this->request->get('template_id');
$obj = new Wholesaler(); $obj = new Wholesaler();
$msg = $obj->privacyInfo($appid); $msg = $obj->privacyInfo($appid);
if ($msg == 'ok') { if ($msg == 'ok') {
$msg = $obj->submitAudit($appid); $msg = $obj->commit($appid, $template_id);
if ($msg == 'ok') { if ($msg == 'ok') {
return $this->renderSuccess('success'); return $this->renderSuccess('success');
} }
@ -213,9 +218,11 @@ class Wxwholesaler extends Controller
$appid = $this->request->get('appid'); $appid = $this->request->get('appid');
if ($appid) { if ($appid) {
$obj = new Wholesaler(); $obj = new Wholesaler();
if ($obj->getVersioninfo($appid)) { $res = $obj->getVersioninfo($appid);
if ($res['code']) {
return $this->renderSuccess('success'); return $this->renderSuccess('success');
} }
return $this->renderError($res['msg']);
} }
return $this->renderError('操作失败'); return $this->renderError('操作失败');
} }
@ -238,6 +245,22 @@ class Wxwholesaler extends Controller
return $this->renderError('操作失败'); return $this->renderError('操作失败');
} }
/**
* @notes:单个提交正式版审核
* @return Json
* @author: wanghousheng
*/
public function auditOne(): Json
{
$appid = $this->request->get('appid');
$obj = new Wholesaler();
$msg = $obj->submitAudit($appid);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
return $this->renderError($msg);
}
/** /**
* @notes:发布正式版前检查 * @notes:发布正式版前检查
* @return Json * @return Json
@ -256,4 +279,82 @@ class Wxwholesaler extends Controller
} }
return $this->renderError($msg); return $this->renderError($msg);
} }
/**
* @notes:设置域名
* @return Json
* @author: wanghousheng
*/
public function setDomain(): Json
{
$msg = 'appid不能为空';
$domain = $this->request->domain(true);
$appid = $this->request->get('appid', $domain);
if ($appid) {
$obj = new Wholesaler();
$msg = $obj->setDomain($appid, $domain);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置隐私
* @return Json
* @author: wanghousheng
*/
public function privacySetting(): Json
{
$msg = 'appid不能为空';
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Wholesaler();
$msg = $obj->getPrivacySetting($appid);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置业务域名
* @return Json
* @author: wanghousheng
*/
public function modifyJumpDomain(): Json
{
$msg = 'appid不能为空';
$domain = $this->request->domain(true);
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Wholesaler();
$msg = $obj->modifyJumpDomain($appid, $domain);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
/**
* @notes:设置订单页
* @return Json
* @author: wanghousheng
*/
public function setOrderPath(): Json
{
$msg = 'appid不能为空';
$appid = $this->request->get('appid');
if ($appid) {
$obj = new Wholesaler();
$msg = $obj->applySetOrderPathInfo([$appid]);
if ($msg == 'ok') {
return $this->renderSuccess('success');
}
}
return $this->renderError($msg);
}
} }

@ -103,7 +103,9 @@ class Invite extends Controller
$data['adoption_num'] = $adoption_num."/".$invite_num; $data['adoption_num'] = $adoption_num."/".$invite_num;
$data['invite_num'] = 0; $data['invite_num'] = 0;
$data['refuse_num'] = 0; $data['refuse_num'] = 0;
$data['invite_num'] = 0;
$model = new InviteLog(); $model = new InviteLog();
$storeId = $this->storeId;
$user_ids = $model->inviteeUserIds(); $user_ids = $model->inviteeUserIds();
$status = intval($this->request->post('status')); $status = intval($this->request->post('status'));
if (!$status) { if (!$status) {
@ -124,6 +126,10 @@ class Invite extends Controller
} }
$data['list'] = $list->items(); $data['list'] = $list->items();
$data['total'] = $list->total(); $data['total'] = $list->total();
//1.查询需要的邀请人数是多少
$setting = Setting::where(['key'=>'condition'])->field('values')->find();
$setting = json_decode($setting,true);
$invite_num = $setting['values']['invite_num'] ?? 10;
//审核通过 //审核通过
$adoption_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count(); $adoption_num = $applyModel->whereIn('user_id', $user_ids)->where(['status' => WholesalerEnum::ADOPT])->count();
$data['invite_num'] = $adoption_num; $data['invite_num'] = $adoption_num;

@ -12,8 +12,8 @@ declare (strict_types=1);
namespace app\api\controller; namespace app\api\controller;
use cores\BaseController;
use app\api\service\Notify as NotifyService; use app\api\service\Notify as NotifyService;
use cores\BaseController;
/** /**
* 支付成功异步通知接口 * 支付成功异步通知接口
@ -45,6 +45,7 @@ class Notify extends BaseController
try { try {
$NotifyService = new NotifyService; $NotifyService = new NotifyService;
return $NotifyService->wechatV3(); return $NotifyService->wechatV3();
} catch (\Throwable $e) { } catch (\Throwable $e) {
return '{"code": "FAIL","message": "失败"}'; return '{"code": "FAIL","message": "失败"}';
} }

@ -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\api\controller;
use app\api\model\Region as RegionModel;
use think\response\Json;
/**
* 地区管理
* Class Region
* @package app\api\controller
*/
class Region extends Controller
{
/**
* 获取所有地区
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function all(): Json
{
$list = RegionModel::getCacheAll();
return $this->renderSuccess(compact('list'));
}
/**
* 获取所有地区(树状)
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function tree(): Json
{
$model = new RegionModel();
$list = $model->getNewTreeList();
//$list = array_values($list);
return $this->renderSuccess(compact('list'));
}
}

@ -222,7 +222,7 @@ class Store extends Controller
$page = $this->request->param('page') ?? 1; $page = $this->request->param('page') ?? 1;
$servers = new successful(); $servers = new successful();
//$list = $servers->list($page); //$list = $servers->list($page);
$list = successful:: withoutGlobalScope()->where('status',10)->order('sort','asc')->paginate(10, false, $page); $list = successful::where('status',10)->order('sort','asc')->paginate(10, false, $page);
$list->each(function ($item, $key) { $list->each(function ($item, $key) {
$imageUrl = UploadFile::withoutGlobalScope()->where('file_id', $item['image_id'])->find(); $imageUrl = UploadFile::withoutGlobalScope()->where('file_id', $item['image_id'])->find();
if ($imageUrl) { if ($imageUrl) {

@ -4,6 +4,7 @@ namespace app\api\controller;
use app\api\model\wholesaler\Apply; use app\api\model\wholesaler\Apply;
use app\api\model\wholesaler\Set; use app\api\model\wholesaler\Set;
use app\common\enum\WholesalerEnum;
use cores\exception\BaseException; use cores\exception\BaseException;
use Exception; use Exception;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
@ -119,6 +120,13 @@ class Wholesaler extends Controller
} catch (Exception $e) { } catch (Exception $e) {
return $this->renderError($e->getMessage() ?: '短信验证码不正确'); return $this->renderError($e->getMessage() ?: '短信验证码不正确');
} }
$model = new Apply();
if ($model->where(['card_no' => $card_no])->value('id')) {
return $this->renderError('该身份证号已存在');
}
if ($model->where(['credit_code' => $credit_code])->value('id')) {
return $this->renderError('营业执照已存在');
}
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
$data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id'));
$data['total_price'] = $priceInfo['price']; $data['total_price'] = $priceInfo['price'];
@ -222,6 +230,22 @@ class Wholesaler extends Controller
if (!$avatar_id) { if (!$avatar_id) {
return $this->renderError('头像不能为空'); return $this->renderError('头像不能为空');
} }
$info = Apply::info();
if (empty($info->id) || empty($info->status)) {
return $this->renderError('信息不存在');
}
if ($info->status == WholesalerEnum::ADOPT) {
return $this->renderError('申请已通过');
}
$model = new Apply();
$exists_id = $model->where(['card_no' => $card_no])->value('id');
if ($exists_id && $info->id != $exists_id) {
return $this->renderError('该身份证号已存在');
}
$exists_id = $model->where(['credit_code' => $credit_code])->value('id');
if ($exists_id && $info->id != $exists_id) {
return $this->renderError('营业执照已存在');
}
try { try {
CaptchaApi::checkSms($mobile_code, $mobile); CaptchaApi::checkSms($mobile_code, $mobile);
} catch (Exception $e) { } catch (Exception $e) {
@ -229,6 +253,8 @@ class Wholesaler extends Controller
} }
$data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id'); $data = compact('company_name', 'credit_code', 'city_id', 'province_id', 'door_img_id', 'business', 'card_no', 'avatar_id');
$data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id')); $data = array_merge($data, compact('username', 'mobile', 'card_back_img_id', 'card_front_img_id', 'license_img_id'));
$data['status'] = WholesalerEnum::AUDITING;
$data['remake'] = null;
if ((new Apply())->edit($data)) { if ((new Apply())->edit($data)) {
return $this->renderSuccess('操作成功'); return $this->renderSuccess('操作成功');
} }

@ -16,6 +16,7 @@ use app\api\controller\Controller;
use app\api\model\dealer\Apply as DealerApplyModel; use app\api\model\dealer\Apply as DealerApplyModel;
use app\api\model\dealer\User as DealerUserModel; use app\api\model\dealer\User as DealerUserModel;
use app\api\service\User as UserService; use app\api\service\User as UserService;
use app\common\enum\dealer\apply\ApplyStatus as ApplyStatusEnum;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
@ -134,6 +135,8 @@ class Apply extends Controller
return $this->renderError('所在城市不能为空'); return $this->renderError('所在城市不能为空');
} }
$data = compact('business', 'city', 'real_name', 'mobile', 'shop_type', 'shop_name', 'business', 'city'); $data = compact('business', 'city', 'real_name', 'mobile', 'shop_type', 'shop_name', 'business', 'city');
$data['apply_status'] = ApplyStatusEnum::WAIT;
$data['reject_reason'] = null;
$model = new DealerApplyModel; $model = new DealerApplyModel;
if ($model->editApplyServiceProviders($data)) { if ($model->editApplyServiceProviders($data)) {
return $this->renderSuccess('更新成功'); return $this->renderSuccess('更新成功');

@ -151,6 +151,7 @@ class Apply extends ApplyModel
'shop_name' => $data['shop_name'], 'shop_name' => $data['shop_name'],
'business' => $data['business'], 'business' => $data['business'],
'city' => $data['city'], 'city' => $data['city'],
'apply_status' => !empty($data['apply_status']) ? $data['apply_status'] : ApplyStatusEnum::WAIT,
]; ];
if ($this->update($data, ['user_id' => $userId])) { if ($this->update($data, ['user_id' => $userId])) {
return true; return true;

@ -153,6 +153,32 @@ class Order extends DealerOrderModel
]); ]);
} }
/**
* 获取当前买家的所有上级分销商用户ID
* @param int $userId 用户ID
* @param int $level 推荐等级
* @param bool $selfBuy 分销商自购
* @return array
*/
// private function getDealerUserId(int $userId, int $level, bool $selfBuy): array
// {
// $dealerUser = [
// 'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0,
// 'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0,
// 'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0
// ];
// // 分销商自购
// if ($selfBuy && User::isDealerUser($userId)) {
// return [
// 'first_user_id' => $userId,
// 'second_user_id' => $dealerUser['first_user_id'],
// 'third_user_id' => $dealerUser['second_user_id'],
// ];
// }
// return $dealerUser;
// }
//
/** /**
* 获取当前买家的所有上级分销商用户ID * 获取当前买家的所有上级分销商用户ID
* @param int $userId 用户ID * @param int $userId 用户ID
@ -163,9 +189,9 @@ class Order extends DealerOrderModel
private function getDealerUserId(int $userId, int $level, bool $selfBuy): array private function getDealerUserId(int $userId, int $level, bool $selfBuy): array
{ {
$dealerUser = [ $dealerUser = [
'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0, 'first_user_id' => $level >= 1 ? Referee::getRefereeBuyUser($userId, 1, true) : 0,
'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0, 'second_user_id' => $level >= 2 ? Referee::getRefereeBuyUser($userId, 2, true) : 0,
'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0 'third_user_id' => $level == 3 ? Referee::getRefereeBuyUser($userId, 3, true) : 0
]; ];
// 分销商自购 // 分销商自购
if ($selfBuy && User::isDealerUser($userId)) { if ($selfBuy && User::isDealerUser($userId)) {

@ -13,7 +13,6 @@ class Apply extends \app\common\model\wholesaler\Apply
* @var array * @var array
*/ */
protected $hidden = [ protected $hidden = [
'create_time',
'update_time', 'update_time',
'store_id', 'store_id',
'id', 'id',

@ -286,7 +286,7 @@ class Payment extends BaseService
private function extraAsUnify(array $extra = []): array private function extraAsUnify(array $extra = []): array
{ {
// 微信支付时需要的附加数据 // 微信支付时需要的附加数据
if ($this->method === PaymentMethodEnum::WECHAT || $this->method === PaymentMethodEnum::HUIFU) { if ($this->method === PaymentMethodEnum::WECHAT || $this->method == PaymentMethodEnum::HUIFU) {
// 微信小程序端和微信公众号端需要openid // 微信小程序端和微信公众号端需要openid
if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) { if (in_array($this->client, [ClientEnum::WXOFFICIAL, ClientEnum::MP_WEIXIN])) {
$extra['openid'] = $this->getWechatOpenid(); $extra['openid'] = $this->getWechatOpenid();

@ -0,0 +1,329 @@
<?php
namespace app\command;
use app\common\service\GoodsCateEs;
use app\common\service\GoodsEs;
use think\console\Command;
use think\console\Output;
use think\console\Input;
use app\store\model\Category as CategoryModel;
use app\common\model\Store;
use think\facade\Db;
class SyncCategory extends Command
{
const DEFAULT_STORE_ID = 0;
protected function configure()
{
// 指令配置
$this->setName('SyncCategory')->setDescription('同步商品数据到ES');
$this->addArgument("store_id");
$this->addArgument("is_update_image");
}
protected function execute(Input $input, Output $output)
{
// $store_id = $input->getArgument("store_id");
$is_update_image = $input->getArgument("is_update_image");
// $where[] = ['is_sync_cate','=', 1];
// $where[] = ['is_delete','=', 0];
// $where[] = ['is_recycle','=', 0];
// $where[] = ['status','=', 1];
// if ($store_id) {
// $where[] = ['store_id','=', $store_id];
// } else {
// $where[] = ['store_id', '<>', self::DEFAULT_STORE_ID];
// }
// $stores = Store::where($where)->field('store_id,is_sync,is_recycle,status,is_delete')->select()->toArray();
// if (!$stores) {
// echo "没有要同步的商城了";
// return;
// }
// foreach ($stores as $store) {
$this->copyCategory(0, $is_update_image);
//}
}
public function copyCategory(int $new_store_id, $is_update_image = 0){
$store_id = 0;
$model = new CategoryModel;
$list = Db::connect("shopMysql")->name('yoshop_category')->where('store_id', 0)->order(['sort', 'create_time'])->select();
$list = $this->getTreeData($list);
//$list = $model->getList(['store_id' => self::DEFAULT_STORE_ID]);
// var_dump($list);
// exit();
if (!$list) {
return;
}
foreach ($list as $value) {
//$value = $value->toArray();
if ($value['status'] != 1) {
continue;
}
$category = CategoryModel::where('original_category_id', $value['category_id'])->where('store_id', $new_store_id)->find();
if ($category) {
//更新分类
//父类id
if ($value['parent_id']) {
$p_category = CategoryModel::where('original_category_id', $value['parent_id'])->where('store_id', $new_store_id)->find();
}
$upData = [
'name' => $value['name'],
'level' => $value['level'],
'sort' => $value['sort'],
'parent_id' => $p_category['category_id'] ?? 0,
];
if ($is_update_image) {
$upData['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0;
$upData['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0;
}
// var_dump($upData);
// exit();
$ret = CategoryModel::where('category_id', $category->category_id)->update($upData);
echo "更新成功".PHP_EOL;
var_dump($ret);
$firstid = $category->category_id;
} else {
//新增一个分类
$value['store_id'] = $new_store_id;
$value['create_time'] = time();
$value['update_time'] = time();
$value['image_id'] = $value['image_id'] ? $this->copyImage($value['image_id'], $new_store_id) : 0;
$value['rank_image_id'] = $value['rank_image_id'] ? $this->copyImage($value['rank_image_id'], $new_store_id) : 0;
$value['original_category_id'] = $value['category_id'];
$temp = $value;
unset($temp['children']);
unset($temp['rankimage']);
unset($temp['image']);
unset($temp['category_id']);
$firstid = Db::table('yoshop_category')->insertGetId($temp);
}
if (!isset($value['children']) || !$value['children']) {
continue;
}
foreach ($value['children'] as $value1) {
//$value1 = $value1->toArray();
if ($value1['status'] != 1) {
continue;
}
$category1 = CategoryModel::where('original_category_id', $value1['category_id'])->where('store_id', $new_store_id)->find();
//var_dump($category1->toArray());
if ($category1) {
//更新分类
//父类id
$p_category1 = CategoryModel::where('original_category_id', $value1['parent_id'])->where('store_id', $new_store_id)->find();
// var_dump($p_category1);
// exit();
$upData1 = [
'name' => $value1['name'],
'level' => $value1['level'],
'sort' => $value1['sort'],
'parent_id' => $p_category1['category_id'] ?? 0,
];
if ($is_update_image) {
$upData1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0;
$upData1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0;
}
$ret = CategoryModel::where('category_id', $category1->category_id)->update($upData1);
echo "更新成功".PHP_EOL;
var_dump($ret);
$secondid = $category1->category_id;
} else {
//新增一个分类
$value1['parent_id'] = $firstid;
$value1['store_id'] = $new_store_id;
$value1['create_time'] = time();
$value1['update_time'] = time();
$value1['image_id'] = $value1['image_id'] ? $this->copyImage($value1['image_id'], $new_store_id) : 0;
$value1['rank_image_id'] = $value1['rank_image_id'] ? $this->copyImage($value1['rank_image_id'], $new_store_id) : 0;
$value1['original_category_id'] = $value1['category_id'];
$temp1 = $value1;
unset($temp1['children']);
unset($temp1['image']);
unset($temp1['rankimage']);
unset($temp1['category_id']);
$secondid = Db::table('yoshop_category')->insertGetId($temp1);
}
if (!isset($value1['children']) || !$value1['children']) {
continue;
}
foreach ($value1['children'] as $value2) {
//$value2 = $value2->toArray();
if ($value2['status'] != 1) {
continue;
}
$category2 = CategoryModel::where('original_category_id', $value2['category_id'])->where('store_id', $new_store_id)->find();
if ($category2) {
//更新分类
//父类id
$p_category2 = CategoryModel::where('original_category_id', $value2['parent_id'])->where('store_id', $new_store_id)->find();
$upData2 = [
'name' => $value2['name'],
'level' => $value2['level'],
'sort' => $value2['sort'],
'parent_id' => $p_category2['category_id'] ?? 0,
];
if ($is_update_image) {
$upData2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0;
$upData2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0;
}
$ret = CategoryModel::where('category_id', $category2->category_id)->update($upData2);
echo "更新成功".PHP_EOL;
var_dump($ret);
$thirdid = $category2->category_id;
} else {
//新增一个分类
$value2['parent_id'] = $secondid;
$value2['store_id'] = $new_store_id;
$value2['create_time'] = time();
$value2['update_time'] = time();
$value2['image_id'] = $value2['image_id'] ? $this->copyImage($value2['image_id'], $new_store_id) : 0;
$value2['rank_image_id'] = $value2['rank_image_id'] ? $this->copyImage($value2['rank_image_id'], $new_store_id) : 0;
$value2['original_category_id'] = $value2['category_id'];
$temp2 = $value2;
unset($temp2['children']);
unset($temp2['image']);
unset($temp2['rankimage']);
unset($temp2['category_id']);
$thirdid = Db::table('yoshop_category')->insertGetId($temp2);
}
if (!isset($value2['children']) || !$value2['children']) {
continue;
}
foreach ($value2['children'] as $value3) {
//$value3 = $value3->toArray();
if ($value3['status'] != 1) {
continue;
}
$category3 = CategoryModel::where('original_category_id', $value3['category_id'])->where('store_id', $new_store_id)->find();
if ($category3) {
//更新分类
//父类id
$p_category3 = CategoryModel::where('original_category_id', $value3['parent_id'])->where('store_id', $new_store_id)->find();
$upData3 = [
'name' => $value3['name'],
'level' => $value3['level'],
'sort' => $value3['sort'],
'parent_id' => $p_category3['category_id'] ?? 0,
];
if ($is_update_image) {
$upData3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0;
$upData3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0;
}
$ret = CategoryModel::where('category_id', $category3->category_id)->update($upData3);
echo "更新成功".PHP_EOL;
var_dump($ret);
$fourthid = $category3->category_id;
} else {
$value3['parent_id'] = $thirdid;
$value3['store_id'] = $new_store_id;
$value3['create_time'] = time();
$value3['update_time'] = time();
$value3['image_id'] = $value3['image_id'] ? $this->copyImage($value3['image_id'], $new_store_id) : 0;
$value3['rank_image_id'] = $value3['rank_image_id'] ? $this->copyImage($value3['rank_image_id'], $new_store_id) : 0;
$value3['original_category_id'] = $value3['category_id'];
$temp3 = $value3;
unset($temp3['children']);
unset($temp3['image']);
unset($temp3['rankimage']);
unset($temp3['category_id']);
$fourthid = Db::table('yoshop_category')->insertGetId($temp3);
}
if (!isset($value3['children']) || !$value3['children']) {
continue;
}
foreach ($value3['children'] as $value4) {
//$value4 = $value4->toArray();
if ($value4['status'] != 1) {
continue;
}
$category4 = CategoryModel::where('original_category_id', $value4['category_id'])->where('store_id', $new_store_id)->find();
if ($category4) {
//更新分类
//父类id
$p_category4 = CategoryModel::where('original_category_id', $value4['parent_id'])->where('store_id', $new_store_id)->find();
$upData4 = [
'name' => $value4['name'],
'level' => $value4['level'],
'sort' => $value4['sort'],
'parent_id' => $p_category4['category_id'] ?? 0,
];
if ($is_update_image) {
$upData4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0;
$upData4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0;
}
$ret = CategoryModel::where('category_id', $category4->category_id)->update($upData4);
echo "更新成功".PHP_EOL;
var_dump($ret);
} else {
$value4['parent_id'] = $fourthid;
$value4['store_id'] = $new_store_id;
$value4['create_time'] = time();
$value4['update_time'] = time();
$value4['image_id'] = $value4['image_id'] ? $this->copyImage($value4['image_id'], $new_store_id) : 0;
$value4['rank_image_id'] = $value4['rank_image_id'] ? $this->copyImage($value4['rank_image_id'], $new_store_id) : 0;
$value4['original_category_id'] = $value4['category_id'];
$temp4 = $value4;
unset($temp4['children']);
unset($temp4['image']);
unset($temp4['rankimage']);
unset($temp4['category_id']);
Db::table('yoshop_category')->insertGetId($temp4);
}
}
}
}
}
}
}
public function copyImage($image_id, $store_id){
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $image_id)->find();
if (!$upload_file) {
return 0;
}
$upload_file['store_id'] = $store_id;
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$new_image_id = DB::table("yoshop_upload_file")->insertGetId($upload_file);
return $new_image_id;
}
/**
* 获取树状列表
* @param $list
* @param int $parentId
* @return array
*/
private function getTreeData($list, int $parentId = 0): array
{
$data = [];
foreach ($list as $key => $item) {
if ($item['parent_id'] == $parentId) {
$children = $this->getTreeData($list, $item['category_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($list[$key]);
}
}
return $data;
}
}

@ -26,7 +26,7 @@ use app\store\model\Setting;
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test // /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
class SyncStoreBasicData extends Command class SyncStoreBasicData extends Command
{ {
const DEFAULT_STORE_ID = 10048; const DEFAULT_STORE_ID = 10063;
protected function configure() protected function configure()
{ {
@ -86,9 +86,9 @@ class SyncStoreBasicData extends Command
if ($isSyncRecoveryData) { if ($isSyncRecoveryData) {
$this->syncRecoveryData($store); $this->syncRecoveryData($store);
} }
if ($isSyncServerData) { // if ($isSyncServerData) {
$this->syncServerData($store); // $this->syncServerData($store);
} // }
if ($isSyncBannerData) { if ($isSyncBannerData) {
$this->syncBannerData($store); $this->syncBannerData($store);
} }

@ -0,0 +1,565 @@
<?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\MaintenanceCategory;
use app\common\model\Maintenance;
use app\common\model\article\Category;
use app\common\model\Article;
use app\common\model\Store;
use app\common\model\Agreement;
use app\common\model\UploadFile;
use app\common\model\Banner;
use app\common\model\Express;
use app\store\model\server\RecoveryCategory;
use app\store\model\server\ServerRecovery;
use app\store\model\server\Server;
use app\store\model\ServerCategory;
use app\store\model\Setting;
// /www/server/php/74/bin/php /server/wwwroot/yanzong/think test
class SyncStoreBasicData extends Command
{
const DEFAULT_STORE_ID = 10048;
protected function configure()
{
// 指令配置
$this->setName('SyncStoreBasicData')->setDescription('同步商城基础数据');
$this->addArgument("store_id");
$this->addArgument("isSyncMaintenanceData");
$this->addArgument("isSyncHelpData");
$this->addArgument("isSyncRichTextData");
$this->addArgument("isSyncRecoveryData");
$this->addArgument("isSyncServerData");
$this->addArgument("isSyncBannerData");
$this->addArgument("isSyncStoreSettingData");
$this->addArgument("isSyncStoreExpressData");
}
protected function execute(Input $input, Output $output)
{
$store_id = $input->getArgument("store_id");
$isSyncMaintenanceData = $input->getArgument("isSyncMaintenanceData");
$isSyncHelpData = $input->getArgument("isSyncHelpData");
$isSyncRichTextData = $input->getArgument("isSyncRichTextData");
$isSyncRecoveryData = $input->getArgument("isSyncRecoveryData");
$isSyncServerData = $input->getArgument("isSyncServerData");
$isSyncBannerData = $input->getArgument("isSyncBannerData");
$isSyncStoreSettingData = $input->getArgument("isSyncStoreSettingData");
$isSyncStoreExpressData = $input->getArgument("isSyncStoreExpressData");
$where[] = ['is_sync','=', 0];
$where[] = ['is_delete','=', 0];
$where[] = ['is_recycle','=', 0];
$where[] = ['status','=', 1];
if ($store_id) {
$where[] = ['store_id','=', $store_id];
} else {
$where[] = ['store_id', '<>', self::DEFAULT_STORE_ID];
}
$stores = Store::where($where)->field('store_id,is_sync,is_recycle,status,is_delete')->select()->toArray();
// echo "<pre>";
// print_r($stores);
// exit();
if (!$stores) {
echo "没有要同步的商城了";
return;
}
foreach ($stores as $store) {
if ($isSyncMaintenanceData) {
$this->syncMaintenanceData($store);
}
if ($isSyncHelpData) {
$this->syncHelpData($store);
}
if ($isSyncRichTextData) {
$this->syncRichTextData($store);
}
if ($isSyncRecoveryData) {
$this->syncRecoveryData($store);
}
if ($isSyncServerData) {
$this->syncServerData($store);
}
if ($isSyncBannerData) {
$this->syncBannerData($store);
}
if ($isSyncStoreSettingData) {
$this->syncStoreSettingData($store);
}
if ($isSyncStoreExpressData) {
$this->syncStoreExpressData($store);
}
Store::where('store_id', $store['store_id'])->update(['is_sync' => 1]);
}
}
/**
* 同步物流公司
* [syncStoreExpressData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncStoreExpressData($store){
//维修分类数据同步
$expressList = Db::connect("shopMysql")->name('yoshop_express')->where('store_id',self::DEFAULT_STORE_ID)->select()->toArray();
if ($expressList) {
foreach ($expressList as &$express) {
$info = Express::where('store_id', $store['store_id'])->where('kuaidi100_code', $express['kuaidi100_code'])->where('kdniao_code', $express['kdniao_code'])->find();
if ($info) {
echo $express['express_id']."物流公司已存在".PHP_EOL;
$ret = Express::where('store_id', $store['store_id'])->where('express_id', $info['express_id'])->update([
'express_name' => $express['express_name'],
'kuaidi100_code' => $express['kuaidi100_code'],
'kdniao_code' => $express['kdniao_code'],
'original_id' => $express['express_id'],
]);
var_dump($ret);
continue;
}
$express['create_time'] = time();
$express['update_time'] = time();
$express['original_id'] = $express['express_id'];
$express['store_id'] = $store['store_id'];
unset($express['express_id']);
$ret = Express::create($express);
var_dump($ret->express_id);
}
unset($express);
}
}
/**
* 同步基本信息,七牛云、快递100、99api的配置
* [syncSettingData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncStoreSettingData($store){
//99api配置
// $collector = Setting::where('key','collector')->where('store_id', $store['store_id'])->find();
// if (!$collector) {
// $collectorData = [
// "key" => "collector",
// "describe" => "商品采集设置",
// "values" => json_decode('{"config":{"99api":{"apiKey":"9271DA7BF37C6F50BED49B7F0ADD49A2"}}}', true),
// "store_id" => $store['store_id'],
// "create_time" => time(),
// "update_time" => time(),
// ];
// $ret = Setting::create($collectorData);
// echo "99api配置新增成功";
// var_dump($ret->key);
// }
//配送设置
$delivery = Setting::where('key','delivery')->where('store_id', $store['store_id'])->find();
if (!$delivery) {
$deliveryData = [
"key" => "delivery",
"describe" => "配送设置",
"values" => json_decode('{"traces":{"enable":1,"default":"kd100","providerConfig":{"kd100":{"customer":"F6CAEF5CEA6B5BF219149B9B42BECAA1","key":"pjVBLUai1633"},"aliyun":{"appCode":""}}},"delivery_type":[10,20,30]}', true),
"store_id" => $store['store_id'],
"create_time" => time(),
"update_time" => time(),
];
$ret = Setting::create($deliveryData);
echo "配送设置新增成功";
var_dump($ret->key);
}
//上传设置
$storage = Setting::where('key','storage')->where('store_id', $store['store_id'])->find();
if (!$storage) {
$storageData = [
"key" => "storage",
"describe" => "上传设置",
"values" => json_decode('{"default":"qiniu","engine":{"qiniu":{"bucket":"saasyovo","access_key":"ehSHgkSkS9lGex8n0-vMf1-wkbgi56yv6fhEwsYS","secret_key":"jNXsuPmTnmfiRlNs-JoAmT833o0qusgXrXqeR3VK","domain":"https:\/\/qiniu.shop.royaum.com.cn"},"aliyun":{"bucket":"","access_key_id":"","access_key_secret":"","domain":"http:\/\/"},"qcloud":{"bucket":"","region":"","secret_id":"","secret_key":"","domain":"http:\/\/"}}}', true),
"store_id" => $store['store_id'],
"create_time" => time(),
"update_time" => time(),
];
$ret = Setting::create($storageData);
echo "上传设置新增成功";
var_dump($ret->key);
}
}
/**
* 同步富文本数据
* [syncHelpData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncRichTextData($store){
//维修分类数据同步
$agreementList = Db::connect("shopMysql")->name('yoshop_agreement')->where('store_id',self::DEFAULT_STORE_ID)->select()->toArray();
if ($agreementList) {
foreach ($agreementList as &$agreement) {
$info = Agreement::where('store_id', $store['store_id'])->where('original_id', $agreement['id'])->find();
if ($info) {
echo $agreement['id']."富文本已存在".PHP_EOL;
continue;
}
$agreement['create_time'] = time();
$agreement['update_time'] = time();
$agreement['original_id'] = $agreement['id'];
$agreement['store_id'] = $store['store_id'];
unset($agreement['id']);
$ret = Agreement::create($agreement);
var_dump($ret->id);
}
unset($agreement);
}
}
/**
* 同步帮助中心数据
* [syncHelpData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncHelpData($store){
//维修分类数据同步
$articleCategoryList = Db::connect("shopMysql")->name('yoshop_article_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($articleCategoryList) {
foreach ($articleCategoryList as &$articleCategory) {
$info = Category::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
if ($info) {
echo $articleCategory['category_id']."帮助分类已存在".PHP_EOL;
continue;
}
$articleCategory['create_time'] = time();
$articleCategory['update_time'] = time();
$articleCategory['original_id'] = $articleCategory['category_id'];
$articleCategory['store_id'] = $store['store_id'];
unset($articleCategory['category_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['img_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$articleCategory['img_id'] = $image_id ?? 0;
$ret = Category::create($articleCategory);
var_dump($ret->id);
}
unset($articleCategory);
}
//维修数据同步
$articleList = Db::connect("shopMysql")->name('yoshop_article')->where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->where('status', 1)->select()->toArray();
if ($articleList) {
foreach ($articleList as &$article) {
$info = Article::where('store_id', $store['store_id'])->where('original_id', $article['article_id'])->find();
if ($info) {
echo $article['article_id']."帮助已存在".PHP_EOL;
continue;
}
//查询分类id
$articleCategory = Category::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
if (!$articleCategory) {
continue;
}
$article['create_time'] = time();
$article['update_time'] = time();
$article['original_id'] = $article['article_id'];
$article['category_id'] = $articleCategory['category_id'];
$article['store_id'] = $store['store_id'];
unset($article['article_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$article['image_id'] = $image_id;
$ret = Article::create($article);
//写入图片id
var_dump($ret->id);
}
unset($article);
}
}
/**
* 同步维修数据
* [syncMaintenanceData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncMaintenanceData($store){
//维修分类数据同步
$maintenanceCategoryList = Db::connect("shopMysql")->name('yoshop_maintenance_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($maintenanceCategoryList) {
foreach ($maintenanceCategoryList as &$maintenanceCategory) {
$info = MaintenanceCategory::where('store_id', $store['store_id'])->where('original_id', $maintenanceCategory['id'])->find();
if ($info) {
echo $maintenanceCategory['id']."维修分类已存在".PHP_EOL;
continue;
}
$maintenanceCategory['create_time'] = time();
$maintenanceCategory['update_time'] = time();
$maintenanceCategory['original_id'] = $maintenanceCategory['id'];
$maintenanceCategory['store_id'] = $store['store_id'];
unset($maintenanceCategory['id']);
// echo "<pre>";
// print_r($maintenanceCategory);
// exit();
$ret = MaintenanceCategory::create($maintenanceCategory);
var_dump($ret->id);
}
unset($maintenanceCategory);
}
//维修数据同步
$maintenanceList = Db::connect("shopMysql")->name('yoshop_maintenance')->where('store_id',self::DEFAULT_STORE_ID)->where('is_delete', 0)->select()->toArray();
if ($maintenanceList) {
foreach ($maintenanceList as &$maintenance) {
$info = Maintenance::where('store_id', $store['store_id'])->where('original_id', $maintenance['id'])->find();
if ($info) {
echo $maintenance['id']."维修已存在".PHP_EOL;
continue;
}
// echo "<pre>";
// print_r($info);
// exit();
//查询分类id
$maintenanceCategory = MaintenanceCategory::where('original_id', $maintenance['category_id'])->where('store_id', $store['store_id'])->find();
if (!$maintenanceCategory) {
continue;
}
$maintenance['create_time'] = time();
$maintenance['update_time'] = time();
$maintenance['original_id'] = $maintenance['id'];
$maintenance['category_id'] = $maintenanceCategory['id'];
$maintenance['store_id'] = $store['store_id'];
unset($maintenance['id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $maintenance['img_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
// echo "<pre>";
// print_r($upload_file);
// exit();
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$maintenance['img_id'] = $image_id ?? 0;
$ret = Maintenance::create($maintenance);
//写入图片id
var_dump($ret->id);
}
unset($maintenance);
}
}
/**
* 同步回收数据
* [syncHelpData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncRecoveryData($store){
//维修分类数据同步
$articleCategoryList = Db::connect("shopMysql")->name('yoshop_server_recovery_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($articleCategoryList) {
foreach ($articleCategoryList as &$articleCategory) {
$info = RecoveryCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
if ($info) {
echo $articleCategory['category_id']."回收已存在".PHP_EOL;
continue;
}
$articleCategory['create_time'] = time();
$articleCategory['update_time'] = time();
$articleCategory['original_id'] = $articleCategory['category_id'];
$articleCategory['store_id'] = $store['store_id'];
unset($articleCategory['category_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$articleCategory['image_id'] = $image_id ?? 0;
$ret = RecoveryCategory::create($articleCategory);
var_dump($ret->category_id);
}
unset($articleCategory);
}
//维修数据同步
$articleList = Db::connect("shopMysql")->name('yoshop_server_recovery')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($articleList) {
foreach ($articleList as &$article) {
$info = ServerRecovery::where('store_id', $store['store_id'])->where('original_id', $article['recovery_id'])->find();
if ($info) {
echo $article['recovery_id']."回收已存在".PHP_EOL;
continue;
}
//查询分类id
$articleCategory = RecoveryCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
if (!$articleCategory) {
continue;
}
$article['create_time'] = time();
$article['update_time'] = time();
$article['original_id'] = $article['recovery_id'];
$article['category_id'] = $articleCategory['category_id'];
$article['store_id'] = $store['store_id'];
unset($article['recovery_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$article['image_id'] = $image_id;
$ret = ServerRecovery::create($article);
//写入图片id
var_dump($ret->recovery_id);
}
unset($article);
}
}
/**
* 同步服务数据
* [syncHelpData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncServerData($store){
//服务分类数据同步
$articleCategoryList = Db::connect("shopMysql")->name('yoshop_server_category')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($articleCategoryList) {
foreach ($articleCategoryList as &$articleCategory) {
$info = ServerCategory::where('store_id', $store['store_id'])->where('original_id', $articleCategory['category_id'])->find();
if ($info) {
echo $articleCategory['category_id']."服务分类已存在".PHP_EOL;
continue;
}
$articleCategory['create_time'] = time();
$articleCategory['update_time'] = time();
$articleCategory['original_id'] = $articleCategory['category_id'];
$articleCategory['store_id'] = $store['store_id'];
unset($articleCategory['category_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$articleCategory['image_id'] = $image_id ?? 0;
$ret = ServerCategory::create($articleCategory);
var_dump($ret->category_id);
}
unset($articleCategory);
}
//服务数据同步
$articleList = Db::connect("shopMysql")->name('yoshop_server')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 1)->select()->toArray();
if ($articleList) {
foreach ($articleList as &$article) {
$info = Server::where('store_id', $store['store_id'])->where('original_id', $article['server_id'])->find();
if ($info) {
echo $article['server_id']."服务已存在".PHP_EOL;
continue;
}
//查询分类id
$articleCategory = ServerCategory::where('original_id', $article['category_id'])->where('store_id', $store['store_id'])->find();
if (!$articleCategory) {
continue;
}
$article['create_time'] = time();
$article['update_time'] = time();
$article['original_id'] = $article['server_id'];
$article['category_id'] = $articleCategory['category_id'];
$article['store_id'] = $store['store_id'];
unset($article['server_id']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $article['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$article['image_id'] = $image_id;
$ret = Server::create($article);
//写入图片id
var_dump($ret->server_id);
}
unset($article);
}
}
/**
* 同步轮播图数据
* [syncHelpData description]
* @param [type] $store [description]
* @return [type] [description]
*/
private function syncBannerData($store){
//服务分类数据同步
$articleCategoryList = Db::connect("shopMysql")->name('yoshop_banner')->where('store_id',self::DEFAULT_STORE_ID)->where('status', 10)->select()->toArray();
if ($articleCategoryList) {
foreach ($articleCategoryList as &$articleCategory) {
$info = Banner::where('store_id', $store['store_id'])->where('original_id', $articleCategory['id'])->find();
if ($info) {
echo $articleCategory['id']."轮播图已存在".PHP_EOL;
continue;
}
$articleCategory['create_time'] = time();
$articleCategory['update_time'] = time();
$articleCategory['original_id'] = $articleCategory['id'];
$articleCategory['store_id'] = $store['store_id'];
unset($articleCategory['id']);
unset($articleCategory['redirect_url']);
//复制图片
$upload_file = Db::connect("shopMysql")->name('yoshop_upload_file')->where('file_id', $articleCategory['image_id'])->find();
if ($upload_file) {
$upload_file['store_id'] = $store['store_id'];
$upload_file['create_time'] = time();
unset($upload_file['file_id']);
$image_id = Db::name('upload_file')->insertGetId($upload_file);
}
//写入维修数据
$articleCategory['image_id'] = $image_id ?? 0;
$ret = Banner::create($articleCategory);
var_dump($ret->id);
}
unset($articleCategory);
}
}
}

@ -30,17 +30,17 @@ class UserTypeEnum extends EnumBasics
'value' => self::NORMAL, 'value' => self::NORMAL,
], ],
self::MEMBER => [ self::MEMBER => [
'name' => '会员', 'name' => '采购商',
'value' => self::MEMBER, 'value' => self::MEMBER,
], ],
self::DEALER => [ self::DEALER => [
'name' => '分销商', 'name' => '服务商',
'value' => self::DEALER, 'value' => self::DEALER,
], ],
self::STORE => [ // self::STORE => [
'name' => '店长', // 'name' => '店长',
'value' => self::STORE, // 'value' => self::STORE,
] // ]
]; ];
} }
@ -55,32 +55,33 @@ class UserTypeEnum extends EnumBasics
} }
public static function homeLocation(string $mobile): string
public static function homeLocation(string $mobile){ {
$datatype = 'txt'; $datatype = 'txt';
$url = 'https://api.ip138.com/mobile/?mobile='.$mobile.'&datatype='.$datatype; $url = 'https://api.ip138.com/mobile/?mobile=' . $mobile . '&datatype=' . $datatype;
$header = array('token:00d5cb1fac5dc5cbfe2ff218292a2dfd33'); $header = array('token:00d5cb1fac5dc5cbfe2ff218292a2dfd33');
return self::getName($url,$header ); return self::getName($url, $header);
} }
public function getData($url,$header){ public function getData($url, $header)
{
$curl = curl_init();
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3);
$handles = curl_exec($curl);
$handles = curl_exec($curl);
curl_close($curl);
curl_close($curl);
return $handles;
} return $handles;
}
} }

@ -76,6 +76,7 @@ class Wholesaler
public function applySetOrderPathInfo(array $appid, string $path = 'pages/order/index') public function applySetOrderPathInfo(array $appid, string $path = 'pages/order/index')
{ {
$msg = '操作失败(未知错误)';
$token = $this->getComponentAccessToken(); $token = $this->getComponentAccessToken();
$data['batch_req'] = [ $data['batch_req'] = [
'path' => $path, 'path' => $path,
@ -83,7 +84,8 @@ class Wholesaler
]; ];
$url = "https://api.weixin.qq.com/wxa/security/applysetorderpathinfo?component_access_token=$token"; $url = "https://api.weixin.qq.com/wxa/security/applysetorderpathinfo?component_access_token=$token";
$result = $this->curlPost($url, json_encode($data)); $result = $this->curlPost($url, json_encode($data));
return json_decode($result, true); $result = json_decode($result, true);
return !empty($result['errmsg']) ? $result['errmsg'] : $msg;
} }
public function getStableAccessToken() public function getStableAccessToken()
@ -211,12 +213,13 @@ class Wholesaler
* @notes:发布体验版 * @notes:发布体验版
* @param $appid * @param $appid
* @param $template_id * @param $template_id
* @return bool * @return mixed|string
* @throws BaseException * @throws BaseException
* @author: wanghousheng * @author: wanghousheng
*/ */
public function commit($appid, $template_id): bool public function commit($appid, $template_id): string
{ {
$msg = '提交体验版失败';
$version = ''; $version = '';
$access_token = $this->authorizerAccessToken($appid); $access_token = $this->authorizerAccessToken($appid);
//获取模板 //获取模板
@ -244,14 +247,14 @@ class Wholesaler
$result = json_decode($result, true); $result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') {
//体验码 //体验码
$msg = $result['errmsg'];
$qr_code = $this->getQrcode($appid); $qr_code = $this->getQrcode($appid);
if ($qr_code) { if ($qr_code) {
$model = new WxwholesalerAccount(); $model = new WxwholesalerAccount();
$model->update(['experience_code' => $qr_code], ['appid' => $appid]); $model->update(['experience_code' => $qr_code], ['appid' => $appid]);
} }
return true;
} }
return false; return !empty($result['errmsg']) ? $result['errmsg'] : $msg;
} }
/** /**
@ -277,17 +280,20 @@ class Wholesaler
/** /**
* @notes:获取版本信息 * @notes:获取版本信息
* @param $appid * @param $appid
* @return bool * @return array
* @author: wanghousheng * @author: wanghousheng
*/ */
public function getVersioninfo($appid): bool public function getVersioninfo($appid): array
{ {
$msg = '操作失败';
$code = 0;
$access_token = $this->authorizerAccessToken($appid); $access_token = $this->authorizerAccessToken($appid);
$url = 'https://api.weixin.qq.com/wxa/getversioninfo?access_token=' . $access_token; $url = 'https://api.weixin.qq.com/wxa/getversioninfo?access_token=' . $access_token;
$result = $this->curlPost($url, '{}'); $result = $this->curlPost($url, '{}');
$result = json_decode($result, true); $result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') {
$up = []; $up = [];
$code = 1;
if (!empty($result['exp_info'])) { if (!empty($result['exp_info'])) {
$up['exp_info'] = json_encode($result['exp_info']); $up['exp_info'] = json_encode($result['exp_info']);
} }
@ -298,9 +304,8 @@ class Wholesaler
$model = new WxwholesalerAccount(); $model = new WxwholesalerAccount();
$model->update($up, ['appid' => $appid]); $model->update($up, ['appid' => $appid]);
} }
return true;
} }
return false; return ['code' => $code, 'msg' => !empty($result['errmsg']) ? $result['errmsg'] : $msg];
} }
/** /**
@ -499,11 +504,12 @@ class Wholesaler
* @notes:设置域名 * @notes:设置域名
* @param $appid * @param $appid
* @param $domain * @param $domain
* @return bool * @return mixed|string
* @author: wanghousheng * @author: wanghousheng
*/ */
public function setDomain($appid, $domain): bool public function setDomain($appid, $domain)
{ {
$msg = '操作失败(未知错误)';
$token = $this->authorizerAccessToken($appid); $token = $this->authorizerAccessToken($appid);
if ($token) { if ($token) {
$url = "https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=$token"; $url = "https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=$token";
@ -512,24 +518,21 @@ class Wholesaler
$data['uploaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn']; $data['uploaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn'];
$data['downloaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn']; $data['downloaddomain'] = [$domain, 'https://qiniu.shop.royaum.com.cn'];
$result = $this->curlPost($url, json_encode($data)); $result = $this->curlPost($url, json_encode($data));
Db::table('yoshop_wx_server')->insertGetId(['content' => "设置域名信息", 'created_at' => date('Y-m-d H:i:s')]);
Db::table('yoshop_wx_server')->insertGetId(['content' => $result, 'created_at' => date('Y-m-d H:i:s')]);
$result = json_decode($result, true); $result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg;
return true;
}
} }
return false; return $msg;
} }
/** /**
* @notes:设置隐私 * @notes:设置隐私
* @param $appid * @param $appid
* @return bool * @return mixed|string
* @author: wanghousheng * @author: wanghousheng
*/ */
public function getPrivacySetting($appid): bool public function getPrivacySetting($appid)
{ {
$msg = '操作失败(未知错误)';
$token = $this->authorizerAccessToken($appid); $token = $this->authorizerAccessToken($appid);
if ($token) { if ($token) {
$url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=$token"; $url = "https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=$token";
@ -547,11 +550,9 @@ class Wholesaler
$data['owner_setting']['notice_method'] = '公告'; $data['owner_setting']['notice_method'] = '公告';
$result = $this->curlPost($url, json_encode($data)); $result = $this->curlPost($url, json_encode($data));
$result = json_decode($result, true); $result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg;
return true;
}
} }
return false; return $msg;
} }
public function apiText($authorization_code, $touser) public function apiText($authorization_code, $touser)
@ -621,7 +622,7 @@ class Wholesaler
$insert_data['create_time'] = time(); $insert_data['create_time'] = time();
$model->insertGetId($insert_data); $model->insertGetId($insert_data);
} }
$this->setOther($appid, $domain); // $this->setOther($appid, $domain);
} }
} }
} }
@ -638,7 +639,7 @@ class Wholesaler
$up['privacy_status'] = 1; $up['privacy_status'] = 1;
} }
//设置业务域名 //设置业务域名
if ($this->modifyJumpDomain($appid)) { if ($this->modifyJumpDomain($appid, $domain)) {
$up['jump_domain_status'] = 1; $up['jump_domain_status'] = 1;
} }
//设置订单页path信息 //设置订单页path信息
@ -649,20 +650,19 @@ class Wholesaler
} }
} }
private function modifyJumpDomain($appid, $domain): bool public function modifyJumpDomain($appid, $domain)
{ {
$msg = '操作失败(未知错误)';
$token = $this->authorizerAccessToken($appid); $token = $this->authorizerAccessToken($appid);
if ($token) { if ($token) {
$url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=$token"; $url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=$token";
$data['action'] = 'set'; $data['action'] = 'add';
$data['webviewdomain'] = $domain; $data['webviewdomain'] = $domain;
$result = $this->curlPost($url, json_encode($data)); $result = $this->curlPost($url, json_encode($data));
$result = json_decode($result, true); $result = json_decode($result, true);
if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { $msg = !empty($result['errmsg']) ? $result['errmsg'] : $msg;
return true;
}
} }
return false; return $msg;
} }
/** /**

@ -12,12 +12,12 @@ declare (strict_types=1);
namespace app\common\model\dealer; namespace app\common\model\dealer;
use cores\BaseModel; use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use app\common\library\helper; use app\common\library\helper;
use app\common\model\Order as OrderModel; use app\common\model\Order as OrderModel;
use app\common\model\OrderGoods as OrderGoodsModel; use app\common\model\OrderGoods as OrderGoodsModel;
use app\common\enum\order\refund\RefundType as RefundTypeEnum; use cores\BaseModel;
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
/** /**
@ -156,18 +156,18 @@ class Order extends BaseModel
if (!$goods['is_ind_dealer']) { if (!$goods['is_ind_dealer']) {
// 全局分销比例 // 全局分销比例
return [ return [
'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 100)), 'first_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['first_money'], 1000, 3)),
'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 100)), 'second_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['second_money'], 1000, 3)),
'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 100)) 'third_money' => helper::bcmul($goodsPrice, helper::bcdiv($setting['third_money'], 1000, 3))
]; ];
} }
// 商品单独分销 // 商品单独分销
if ($goods['dealer_money_type'] == 10) { if ($goods['dealer_money_type'] == 10) {
// 分销佣金类型:百分比 // 分销佣金类型:百分比
return [ return [
'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 100), 'first_money' => $goodsPrice * helper::bcdiv($goods['first_money'], 1000, 3),
'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 100), 'second_money' => $goodsPrice * helper::bcdiv($goods['second_money'], 1000, 3),
'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 100) 'third_money' => $goodsPrice * helper::bcdiv($goods['third_money'], 1000, 3)
]; ];
} else { } else {
// 分销佣金类型:固定金额 // 分销佣金类型:固定金额

@ -63,6 +63,20 @@ class Referee extends BaseModel
return $isDealer ? (User::isDealerUser($dealerId) ? $dealerId : 0) : $dealerId; return $isDealer ? (User::isDealerUser($dealerId) ? $dealerId : 0) : $dealerId;
} }
/**
* 获取上级用户id
* @param int $userId
* @param int $level
* @param bool $isBuyer 必须是采购商
* @return bool|mixed
*/
public static function getRefereeBuyUser(int $userId, int $level, bool $isBuyer = false)
{
$dealerId = (new self)->where(['user_id' => $userId, 'level' => $level])->value('dealer_id');
if (!$dealerId) return 0;
return $isBuyer ? (User::isBuyer($userId) ? $dealerId : 0) : $dealerId;
}
/** /**
* 获取我的团队列表 * 获取我的团队列表
* @param int $dealerId 分销商ID * @param int $dealerId 分销商ID

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\common\model\dealer; namespace app\common\model\dealer;
use app\common\enum\dealer\DealerUserEnum; use app\common\enum\dealer\DealerUserEnum;
use app\common\enum\user\UserTypeEnum;
use app\common\library\helper; use app\common\library\helper;
use cores\BaseModel; use cores\BaseModel;
use think\Collection; use think\Collection;
@ -106,6 +107,19 @@ class User extends BaseModel
return self::get($userId, $with); return self::get($userId, $with);
} }
/**
* @notes:是否为采购商
* @param int $userId
* @return mixed
* @author: wanghousheng
*/
public static function isBuyer(int $userId)
{
return (new \app\common\model\User())->where('user_id', '=', $userId)
->where('user_type', '=', UserTypeEnum::MEMBER)
->value('user_id');
}
/** /**
* 是否为分销商 * 是否为分销商
* @param int $userId * @param int $userId

@ -23,7 +23,7 @@ class RetailDescribe extends RetDescribeModel
$filter = $this->getFilter($param); $filter = $this->getFilter($param);
$list = $this->field('*') $list = $this->field('*')
->where($filter) ->where($filter)
->order(['create_time' => 'asc','sort' => 'asc']) ->order(['sort' => 'asc','create_time' => 'asc'])
->paginate($param['pageSize'] ?? 15); ->paginate($param['pageSize'] ?? 15);
return $list; return $list;
} }

@ -97,9 +97,13 @@ class Apply extends ApplyModel
$info = UserModel::detail(['user_id' => $this['user_id']]); $info = UserModel::detail(['user_id' => $this['user_id']]);
if (!empty($info)) { if (!empty($info)) {
$info = $info->toArray(); $info = $info->toArray();
if ($info['effective_time'] && strtotime($info['effective_time']) > time() && $info['user_type'] == UserTypeEnum::MEMBER) { if ($info['user_type'] == UserTypeEnum::NORMAL) {
$up['user_type'] = UserTypeEnum::DEALER; $up['user_type'] = UserTypeEnum::DEALER;
$up['fx_effective_time'] = $info['effective_time']; if ($info['effective_time']) {
$up['effective_time'] = null;
}
$current_date = date('Y-m-d'); // 获取当前日期
$up['fx_effective_time'] = date('Y-m-d', strtotime('+1 year', strtotime($current_date)));
$userModel->where(['user_id' => $info['user_id']])->save($up); $userModel->where(['user_id' => $info['user_id']])->save($up);
} }
} }

@ -12,8 +12,10 @@ declare (strict_types=1);
namespace app\store\model\dealer; namespace app\store\model\dealer;
use app\store\model\dealer\Referee as RefereeModel; use app\common\enum\user\UserTypeEnum;
use app\common\model\dealer\User as UserModel; use app\common\model\dealer\User as UserModel;
use app\store\model\dealer\Apply as ApplyModel;
use app\store\model\dealer\Referee as RefereeModel;
/** /**
* 分销商用户模型 * 分销商用户模型
@ -85,6 +87,13 @@ class User extends UserModel
} }
// 清空下级推荐记录 // 清空下级推荐记录
$RefereeModel->onClearTeam($this['user_id']); $RefereeModel->onClearTeam($this['user_id']);
// 删除申请记录
$applyModel = new ApplyModel();
$applyModel->where(['user_id' => $this['user_id']])->delete();
//修改会员身份
$userModel = new \app\common\model\User();
$userModel->where(['user_id' => $this['user_id']])->save(['user_type' => UserTypeEnum::NORMAL, 'fx_effective_time' => null]);
$this->onDeleteReferee($this['user_id']);
// 标记当前分销商记录为已删除 // 标记当前分销商记录为已删除
return $this->delete(); return $this->delete();
}); });

@ -12,9 +12,9 @@ declare (strict_types=1);
namespace app\timer\model\dealer; namespace app\timer\model\dealer;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use app\common\model\dealer\Order as OrderModel; use app\common\model\dealer\Order as OrderModel;
use app\timer\model\dealer\Setting as DealerSettingModel; use app\timer\model\dealer\Setting as DealerSettingModel;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
/** /**
* 分销商订单模型 * 分销商订单模型

@ -13,10 +13,10 @@ declare (strict_types=1);
namespace app\timer\service\dealer; namespace app\timer\service\dealer;
use app\common\library\helper; use app\common\library\helper;
use app\common\service\BaseService;
use app\timer\library\Tools; use app\timer\library\Tools;
use app\timer\model\dealer\User as DealerUserModel;
use app\timer\model\dealer\Order as DealerOrderModel; use app\timer\model\dealer\Order as DealerOrderModel;
use app\common\service\BaseService; use app\timer\model\dealer\User as DealerUserModel;
use think\model\Collection; use think\model\Collection;
/** /**

@ -111,7 +111,45 @@ return [
// 字段缓存路径 // 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR, 'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
], ],
'shopMysql' => [
// 数据库类型
'type' => env('sdatabase.type', 'mysql'),
// 服务器地址
'hostname' => env('sdatabase.hostname', $config['host']),
// 数据库名
'database' => env('sdatabase.database', $config['database']),
// 用户名
'username' => env('sdatabase.username', $config['username']),
// 密码
'password' => env('sdatabase.password', $config['password']),
// 端口
'hostport' => env('sdatabase.hostport', $config['hostport']),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('sdatabase.charset', 'utf8'),
// 数据库表前缀
'prefix' => "",
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => true,
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
// 更多的数据库配置信息 // 更多的数据库配置信息
], ],

@ -27,7 +27,7 @@ return [
'host' => env('redis.hostname', '127.0.0.1'), 'host' => env('redis.hostname', '127.0.0.1'),
'port' => env('redis.hostport', '6379'), 'port' => env('redis.hostport', '6379'),
'password' => env('redis.password', ''), 'password' => env('redis.password', ''),
'select' => 1,//env('redis.select', '0'), 'select' => 3,//env('redis.select', '0'),
'timeout' => 0, 'timeout' => 0,
'persistent' => false, 'persistent' => false,
'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒 'retry_after' => 60, // 队列任务无响应时(例如die exit)重试的间隔时间, 默认60秒

Loading…
Cancel
Save