chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材 添加系统版本配置文件(.version)和常量定义文件(.constant) 更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件 添加验证码配置文件(captcha.php)和.gitignore规则
This commit is contained in:
175
app/controller/api/v2/PublicController.php
Normal file
175
app/controller/api/v2/PublicController.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use app\services\diy\DiyServices;
|
||||
use app\services\other\CityAreaServices;
|
||||
use app\services\product\category\StoreProductCategoryServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\wechat\WechatUserServices;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\SystemConfigService;
|
||||
|
||||
class PublicController
|
||||
{
|
||||
/**
|
||||
* 主页获取
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
|
||||
$data = SystemConfigService::more(['fast_number', 'bast_number', 'first_number', 'promotion_number', 'tengxun_map_key', 'site_name']);
|
||||
$site_name = $data['site_name'] ?? '';
|
||||
$tengxun_map_key = $data['tengxun_map_key'] ?? '';
|
||||
$fastNumber = (int)($data['fast_number'] ?? 0);// 快速选择分类个数
|
||||
$bastNumber = (int)($data['bast_number'] ?? 0);// 精品推荐个数
|
||||
$firstNumber = (int)($data['first_number'] ?? 0);// 首发新品个数
|
||||
$promotionNumber = (int)($data['promotion_number'] ?? 0);// 首发新品个数
|
||||
$info['fastList'] = [];
|
||||
if ($fastNumber) {
|
||||
/** @var StoreProductCategoryServices $categoryService */
|
||||
$categoryService = app()->make(StoreProductCategoryServices::class);
|
||||
$info['fastList'] = $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic');// 快速选择分类个数
|
||||
}
|
||||
/** @var StoreProductServices $storeProductServices */
|
||||
$storeProductServices = app()->make(StoreProductServices::class);
|
||||
$info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($uid, ['is_best' => 1], $bastNumber) : [];// 精品推荐个数
|
||||
$info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($uid, ['is_new' => 1], $firstNumber) : [];// 首发新品个数
|
||||
$benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($uid, ['is_benefit' => 1], $promotionNumber) : [];// 首页促销单品
|
||||
$likeInfo = $storeProductServices->getRecommendProduct($uid, ['is_hot' => 1], 3);// 热门榜单 猜你喜欢
|
||||
if ($request->uid()) {
|
||||
/** @var WechatUserServices $wechatUserService */
|
||||
$wechatUserService = app()->make(WechatUserServices::class);
|
||||
$subscribe = (bool)$wechatUserService->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe');
|
||||
} else {
|
||||
$subscribe = true;
|
||||
}
|
||||
return app('json')->successful(compact('info', 'benefit', 'likeInfo', 'subscribe', 'tengxun_map_key', 'site_name'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取页面数据
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getDiy($name = '')
|
||||
{
|
||||
/** @var DiyServices $diyService */
|
||||
$diyService = app()->make(DiyServices::class);
|
||||
$data = CacheService::redisHandler('diy')->remember('diy_' . $name, function () use ($name, $diyService) {
|
||||
$data = $diyService->getDiy($name);
|
||||
if (isset($data['f_scroll_box']['goodsList']['list'])) {
|
||||
$data['f_scroll_box']['goodsList']['list'] = get_thumb_water($data['f_scroll_box']['goodsList']['list'], 'small', ['pic']);
|
||||
}
|
||||
return $data;
|
||||
});
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否强制绑定手机号
|
||||
* @return mixed
|
||||
*/
|
||||
public function bindPhoneStatus()
|
||||
{
|
||||
$status = (bool)sys_config('store_user_mobile');
|
||||
return app('json')->success(compact('status'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否关注
|
||||
* @param Request $request
|
||||
* @param WechatUserServices $services
|
||||
* @return mixed
|
||||
*/
|
||||
public function subscribe(Request $request, WechatUserServices $services)
|
||||
{
|
||||
return app('json')->success(['subscribe' => (bool)$services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提货点自提开启状态
|
||||
* @return mixed
|
||||
*/
|
||||
public function getStoreStatus()
|
||||
{
|
||||
$data['store_status'] = 0;
|
||||
if (sys_config('store_func_status', 1)) {
|
||||
$data['store_status'] = sys_config('store_self_mention', 0);
|
||||
}
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取颜色选择和分类模板选择
|
||||
* @param DiyServices $services
|
||||
* @param $name
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function colorChange(DiyServices $services, $name)
|
||||
{
|
||||
$colorData = $services->getColorChange((string)$name);
|
||||
$status = (int)$colorData['value'];
|
||||
$color_data = json_decode($colorData['color_data'], true);
|
||||
$navigation = (int)sys_config('navigation_open');
|
||||
$product_category_level = (int)sys_config('product_category_level');//商品分类层级
|
||||
return app('json')->success(compact('status', 'color_data', 'navigation', 'product_category_level'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取城市
|
||||
* @param CityAreaServices $services
|
||||
* @return mixed
|
||||
*/
|
||||
public function city(Request $request, CityAreaServices $services)
|
||||
{
|
||||
$pid = $request->get('pid', 0);
|
||||
return app('json')->success($services->getCityTreeList((int)$pid));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析(获取导入微信地址)
|
||||
* @param CityAreaServices $services
|
||||
* @return mixed
|
||||
*/
|
||||
public function cityList(Request $request, CityAreaServices $services)
|
||||
{
|
||||
$address = $request->param('address', '');
|
||||
if (!$address)
|
||||
return app('json')->fail('地址不存在');
|
||||
|
||||
$city = $services->searchCity(compact('address'));
|
||||
if (!$city) return app('json')->fail('地址暂未录入,请联系管理员');
|
||||
$where = [['id', 'in', array_merge([$city['id']], explode('/', trim($city->path, '/')))]];
|
||||
return app('json')->success($services->getCityList($where, 'id as value,id,name as label,parent_id as pid', ['children']));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服类型配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCustomerType()
|
||||
{
|
||||
$data = SystemConfigService::more(['routine_contact_type', 'customer_type', 'customer_phone', 'customer_url', 'wechat_work_corpid']);
|
||||
$data['userInfo'] = [];
|
||||
return app('json')->success($data);
|
||||
}
|
||||
}
|
||||
165
app/controller/api/v2/activity/LuckLottery.php
Normal file
165
app/controller/api/v2/activity/LuckLottery.php
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\activity;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use app\services\activity\lottery\LuckLotteryRecordServices;
|
||||
use app\services\activity\lottery\LuckLotteryServices;
|
||||
use app\services\other\QrcodeServices;
|
||||
use app\services\wechat\WechatServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LuckLottery
|
||||
* @package app\controller\api\v1\activity
|
||||
*/
|
||||
class LuckLottery
|
||||
{
|
||||
|
||||
/**
|
||||
* @var LuckLotteryServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected LuckLotteryServices $services;
|
||||
|
||||
/**
|
||||
* 抽奖活动信息
|
||||
* @param Request $request
|
||||
* @param $factor
|
||||
* @return mixed
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function LotteryInfo(Request $request, $factor)
|
||||
{
|
||||
if (!$factor) $factor = 1;
|
||||
$lottery = $this->services->getFactorLotteryCache((int)$factor);
|
||||
if (!$lottery) {
|
||||
return app('json')->fail('抽奖活动不存在');
|
||||
}
|
||||
$uid = (int)$request->uid();
|
||||
$prizeArr = isset($lottery['prize']) && $lottery['prize'] ? $lottery['prize'] : [];
|
||||
$prize = [];
|
||||
if ($prizeArr) {
|
||||
foreach ($prizeArr as &$item) {
|
||||
$prize[] = [
|
||||
'id' => $item['id'],
|
||||
'type' => $item['type'],
|
||||
'name' => $item['name'],
|
||||
'image' => $item['image'],
|
||||
'prompt' => $item['prompt'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$lottery['prize'] = $prize;
|
||||
$lotteryData = ['lottery' => $lottery];
|
||||
$this->services->checkoutUserAuth($uid, (int)$lottery['id'], [], $lottery);
|
||||
$lotteryData['lottery_num'] = $this->services->getLotteryNum($uid, (int)$lottery['id'], [], $lottery);
|
||||
if ($factor == 3 && $lotteryData['lottery_num'] < 1) {
|
||||
return app('json')->successful('ok', []);
|
||||
}
|
||||
$all_record = $user_record = [];
|
||||
/** @var LuckLotteryRecordServices $lotteryRecordServices */
|
||||
$lotteryRecordServices = app()->make(LuckLotteryRecordServices::class);
|
||||
if ($lottery['is_all_record'] || $lottery['is_personal_record']) {
|
||||
if ($lottery['is_all_record']) {
|
||||
$all_record = $lotteryRecordServices->getWinList(['lottery_id' => $lottery['id']]);
|
||||
}
|
||||
if ($lottery['is_personal_record']) {
|
||||
$user_record = $lotteryRecordServices->getWinList(['lottery_id' => $lottery['id'], 'uid' => $uid]);
|
||||
}
|
||||
}
|
||||
if ($lottery['factor'] == 1) {//积分抽奖
|
||||
$data = $lotteryRecordServices->getLotteryNum($uid, (int)$lottery['id']);
|
||||
$lotteryData['todayCount'] = (int)max(bcsub((string)$lottery['lottery_num'], (string)$data['todayCount'], 0), 0);
|
||||
$lotteryData['totalCount'] = (int)max(bcsub((string)$lottery['total_lottery_num'], (string)$data['totalCount'], 0), 0);
|
||||
} else {
|
||||
$lotteryData['totalCount'] = $lotteryData['todayCount'] = $lotteryData['lottery_num'] = (int)$lotteryData['lottery_num'];
|
||||
}
|
||||
$lotteryData['all_record'] = $all_record;
|
||||
$lotteryData['user_record'] = $user_record;
|
||||
$lotteryData['cache_time'] = in_array($factor, [3, 4]) ? $this->services->getCacheLotteryExpireTime($uid, $factor == 3 ? 'order' : 'comment') : 0;
|
||||
return app('json')->successful('ok', $lotteryData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参与抽奖
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function luckLottery(Request $request)
|
||||
{
|
||||
[$id, $type, $channel_type] = $request->postMore([
|
||||
['id', 0],
|
||||
['type', 0],
|
||||
['channel_type','']
|
||||
], true);
|
||||
$uid = (int)$request->uid();
|
||||
if ($type == 5 && request()->isWechat()) {
|
||||
/** @var WechatServices $wechat */
|
||||
$wechat = app()->make(WechatServices::class);
|
||||
$subscribe = $wechat->get(['user_type' => 'wechat', 'uid' => $uid, 'subscribe' => 1]);
|
||||
if (!$subscribe) {
|
||||
$url = '';
|
||||
/** @var QrcodeServices $qrcodeService */
|
||||
$qrcodeService = app()->make(QrcodeServices::class);
|
||||
$url = $qrcodeService->getTemporaryQrcode('luckLottery-' . $uid, $uid)->url;
|
||||
return app('json')->successful('请先关注公众号', ['code' => 'subscribe', 'url' => $url]);
|
||||
}
|
||||
}
|
||||
if (!$id) {
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
return app('json')->successful($this->services->luckLottery($uid, $id,$channel_type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取奖品
|
||||
* @param Request $request
|
||||
* @param LuckLotteryRecordServices $lotteryRecordServices
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function lotteryReceive(Request $request, LuckLotteryRecordServices $lotteryRecordServices)
|
||||
{
|
||||
[$id, $name, $phone, $address, $mark] = $request->postMore([
|
||||
['id', 0],
|
||||
['name', ''],
|
||||
['phone', ''],
|
||||
['address', ''],
|
||||
['mark', '']
|
||||
], true);
|
||||
if (!$id) {
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
$uid = (int)$request->uid();
|
||||
return app('json')->successful($lotteryRecordServices->receivePrize($uid, $id, compact('name', 'phone', 'address', 'mark')) ? '领取成功' : '领取失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中奖记录
|
||||
* @param Request $request
|
||||
* @param LuckLotteryRecordServices $lotteryRecordServices
|
||||
* @return mixed
|
||||
*/
|
||||
public function lotteryRecord(Request $request, LuckLotteryRecordServices $lotteryRecordServices)
|
||||
{
|
||||
$uid = (int)$request->uid();
|
||||
return app('json')->successful($lotteryRecordServices->getRecord($uid));
|
||||
}
|
||||
}
|
||||
92
app/controller/api/v2/activity/StoreCoupons.php
Normal file
92
app/controller/api/v2/activity/StoreCoupons.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\activity;
|
||||
|
||||
use app\services\activity\coupon\StoreCouponIssueServices;
|
||||
use app\services\order\StoreOrderServices;use app\services\product\product\StoreProductCouponServices;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;use think\Request;
|
||||
|
||||
/**
|
||||
* 优惠券
|
||||
* Class StoreCoupons
|
||||
* @package app\controller\api\v2\store
|
||||
*/
|
||||
class StoreCoupons
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreCouponIssueServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreCouponIssueServices $services;
|
||||
|
||||
/**
|
||||
* 可领取优惠券列表
|
||||
* @param \app\Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function lst(Request $request)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
[['type', 'd'], ''],
|
||||
[['product_id', 'd'], 0],
|
||||
[['brand_id', 'd'], 0],
|
||||
['defaultOrder', ''],
|
||||
['timeOrder', ''],
|
||||
['priceOrder', '']
|
||||
]);
|
||||
return app('json')->successful($this->services->getIssueCouponList((int)$request->uid(), $where, '*', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新人券
|
||||
* @return mixed
|
||||
*/
|
||||
public function getNewCoupon(Request $request)
|
||||
{
|
||||
$userInfo = $request->user();
|
||||
$data = [];
|
||||
/** @var StoreCouponIssueServices $couponService */
|
||||
$couponService = app()->make(StoreCouponIssueServices::class);
|
||||
$data['list'] = $couponService->getNewCoupon();
|
||||
$data['image'] = '';
|
||||
if ($userInfo->add_time === $userInfo->last_time) {
|
||||
$data['show'] = 1;
|
||||
} else {
|
||||
$data['show'] = 0;
|
||||
}
|
||||
//会员领取优惠券
|
||||
//$couponService->sendMemberCoupon($userInfo->uid);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每日新增的优惠券
|
||||
* @param Request $request
|
||||
* @param StoreCouponIssueServices $couponIssueServices
|
||||
* @return \think\Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getTodayCoupon(Request $request, StoreCouponIssueServices $couponIssueServices)
|
||||
{
|
||||
$uid = 0;
|
||||
if ($request->hasMacro('uid')) $uid = (int)$request->uid();
|
||||
$data['list'] = $couponIssueServices->getTodayCoupon($uid);
|
||||
$data['image'] = '';
|
||||
return app('json')->success($data);
|
||||
}
|
||||
}
|
||||
125
app/controller/api/v2/activity/StorePromotions.php
Normal file
125
app/controller/api/v2/activity/StorePromotions.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\activity;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use app\services\activity\promotions\StorePromotionsServices;
|
||||
use app\services\activity\promotions\StorePromotionsAuxiliaryServices;
|
||||
use app\services\product\product\StoreProductRelationServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* 优惠活动
|
||||
*/
|
||||
class StorePromotions
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StorePromotionsServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StorePromotionsServices $services;
|
||||
|
||||
/**
|
||||
* 某个优惠活动商品列表
|
||||
* @param $type
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function productList($type)
|
||||
{
|
||||
$type = (int)($type ?? 0);
|
||||
$product_where = [];
|
||||
if ($type) {
|
||||
$product_where = $this->services->collectProductByType([$type]);
|
||||
}
|
||||
$list = [];
|
||||
if (!$product_where || (isset($product_where['ids']) && $product_where['ids'])) {
|
||||
/** @var StoreProductServices $productServices */
|
||||
$productServices = app()->make(StoreProductServices::class);
|
||||
$list = $productServices->getGoodsList($product_where, 0, $type);
|
||||
if ($list) {
|
||||
foreach ($list as $key => &$item) {
|
||||
if (isset($item['promotions']['promotions_type']) && $item['promotions']['promotions_type'] == 1) {
|
||||
$item['price'] = floatval(bcmul((string)$item['price'], (string)bcdiv((string)$item['promotions']['discount'] ?? '100', '100', 2), 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return app('json')->success(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取凑单商品列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function collectOrderProduct(Request $request, StoreProductServices $productServices, StorePromotionsAuxiliaryServices $auxiliaryService)
|
||||
{
|
||||
[$promotions_id] = $request->getMore([
|
||||
[['promotions_id', 'd'], 0]
|
||||
], true);
|
||||
$promotions = $this->services->get($promotions_id, ['*'], ['promotions']);
|
||||
if (!$promotions) {
|
||||
return app('json')->fail('活动已失效,请刷新页面');
|
||||
}
|
||||
$promotions = $promotions->toArray();
|
||||
$product_where = $this->services->collectProductById((int)$promotions_id);
|
||||
$list = $productServices->getGoodsList($product_where, (int)$request->uid());
|
||||
return app('json')->success(compact('promotions','list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠活动赠品
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPromotionsGive($id)
|
||||
{
|
||||
$result = [];
|
||||
if($id) {
|
||||
$promotionsInfo= $this->services->getInfo((int)$id);
|
||||
if ($promotionsInfo && $promotionsInfo['promotions_type'] == 4) {
|
||||
$giveIntegral = $giveCoupon = $giveProducts = [];
|
||||
$promotions_cate = $promotionsInfo['promotions_cate'];
|
||||
foreach ($promotionsInfo['promotions'] as $p) {
|
||||
if ($promotions_cate == 2) {
|
||||
$base = '每满' . floatval($p['threshold'] ?? 0);
|
||||
} else {
|
||||
$base = '满' . floatval($p['threshold'] ?? 0);
|
||||
}
|
||||
$base .= $p['threshold_type'] == 1 ? '元可领取' : '件可领取';
|
||||
if (isset($p['give_integral']) && $p['give_integral']) {
|
||||
$giveIntegral[] = ['threshold_title' => $base, 'give_integral' => intval($p['give_integral'])];
|
||||
}
|
||||
if (isset($p['giveCoupon']) && $p['giveCoupon']) {
|
||||
foreach ($p['giveCoupon'] as &$coupon) {
|
||||
$coupon['threshold_title'] = $base;
|
||||
}
|
||||
$giveCoupon = array_merge($giveCoupon, $p['giveCoupon']);
|
||||
}
|
||||
if (isset($p['giveProducts']) && $p['giveProducts']) {
|
||||
foreach ($p['giveProducts'] as &$product) {
|
||||
$product['threshold_title'] = $base;
|
||||
}
|
||||
$giveProducts = array_merge($giveProducts, $p['giveProducts']);
|
||||
}
|
||||
}
|
||||
$result = compact('giveIntegral', 'giveCoupon', 'giveProducts');
|
||||
}
|
||||
}
|
||||
return app('json')->success($result);
|
||||
}
|
||||
}
|
||||
62
app/controller/api/v2/agent/Agent.php
Normal file
62
app/controller/api/v2/agent/Agent.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\agent;
|
||||
|
||||
use app\Request;
|
||||
use app\services\other\AgreementServices;
|
||||
use app\services\user\UserBrokerageServices;
|
||||
use app\services\user\UserServices;
|
||||
|
||||
class Agent
|
||||
{
|
||||
/**
|
||||
* 获取用户推广用户列表
|
||||
* @param Request $request
|
||||
* @param UserServices $userServices
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function agentUserList(Request $request, UserServices $userServices)
|
||||
{
|
||||
[$type] = $request->getMore([
|
||||
['type', 0]
|
||||
], true);
|
||||
$uid = $request->uid();
|
||||
return app('json')->successful($userServices->agentUserList($uid, $type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户推广获得收益,佣金轮播,分销规则
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function agentInfo(Request $request)
|
||||
{
|
||||
/** @var AgreementServices $agreementService */
|
||||
$agreementService = app()->make(AgreementServices::class);
|
||||
/** @var UserBrokerageServices $userBrokerageServices */
|
||||
$userBrokerageServices = app()->make(UserBrokerageServices::class);
|
||||
$data['agreement'] = $agreementService->getAgreementBytype(2)['content'] ?? '';
|
||||
$data['price'] = $userBrokerageServices->sum(['uid' => $request->uid(), 'pm' => 1, 'not_type' => ['extract_fail', 'refund']], 'number', true);
|
||||
$list = $userBrokerageServices->getList(['pm' => 1, 'not_type' => ['extract_fail', 'refund']], '*', 1, 10, [], ['user']);
|
||||
foreach ($list as $item) {
|
||||
$data['list'][] = [
|
||||
'nickname' => $item['user']['nickname'] ?? '',
|
||||
'price' => $item['number']
|
||||
];
|
||||
}
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
}
|
||||
77
app/controller/api/v2/agent/AgentLevel.php
Normal file
77
app/controller/api/v2/agent/AgentLevel.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\agent;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use app\services\agent\AgentLevelServices;
|
||||
use app\services\agent\AgentLevelTaskServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class AgentLevel
|
||||
* @package app\controller\api\v2\agent
|
||||
*/
|
||||
class AgentLevel
|
||||
{
|
||||
|
||||
/**
|
||||
* @var AgentLevelServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected AgentLevelServices $services;
|
||||
|
||||
/**
|
||||
* 检测用户是否可以成为会员
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function detection(Request $request)
|
||||
{
|
||||
return app('json')->successful($this->services->detection((int)$request->uid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销员等级列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function levelList(Request $request)
|
||||
{
|
||||
return app('json')->successful($this->services->getUserlevelList((int)$request->uid()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取等级任务
|
||||
* @param Request $request
|
||||
* @param AgentLevelTaskServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function levelTaskList(Request $request, AgentLevelTaskServices $services, $id)
|
||||
{
|
||||
return app('json')->successful($services->getUserLevelTaskList((int)$request->uid(), (int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员详情
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function userLevelInfo(Request $request)
|
||||
{
|
||||
return app('json')->successful($this->services->getUserLevelInfo((int)$request->uid()));
|
||||
}
|
||||
|
||||
}
|
||||
92
app/controller/api/v2/order/StoreCart.php
Normal file
92
app/controller/api/v2/order/StoreCart.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\order;
|
||||
|
||||
|
||||
use app\services\order\StoreCartServices;
|
||||
use app\Request;
|
||||
use think\annotation\Inject;
|
||||
|
||||
class StoreCart
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreCartServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreCartServices $services;
|
||||
|
||||
/**
|
||||
* 购物车重选
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function resetCart(Request $request)
|
||||
{
|
||||
[$id, $unique, $num, $product_id] = $request->postMore([
|
||||
['id', 0],
|
||||
['unique', ''],
|
||||
['num', 1],
|
||||
['product_id', 0]
|
||||
], true);
|
||||
$this->services->resetCart((int)$id, (int)$request->uid(), (int)$product_id, $unique, (int)$num);
|
||||
return app('json')->successful('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户购物车
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCartList(Request $request)
|
||||
{
|
||||
$uid = (int)$request->uid();
|
||||
[$store_id] = $request->postMore([
|
||||
['store_id', 0]
|
||||
], true);
|
||||
$data = $this->services->getCartList(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'type' => 0, 'is_channel' => 0, 'is_send_gift' => 0], 0, 0, ['productInfo', 'attrInfo']);
|
||||
if ($store_id) $this->services->setItem('store_id', (int)$store_id);
|
||||
[$data, $valid, $invalid] = $this->services->handleCartList($uid, $data, [], -1);
|
||||
return app('json')->successful($valid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页加入购物车
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setCartNum(Request $request)
|
||||
{
|
||||
[$product_id, $num, $unique, $type, $is_channel, $is_send_gift] = $request->postMore([
|
||||
['product_id', 0],
|
||||
['num', 0],
|
||||
['unique', ''],
|
||||
['type', -1],
|
||||
['is_channel', 0],
|
||||
['is_send_gift', 0],
|
||||
], true);
|
||||
/** @var StoreCartServices $cartService */
|
||||
$cartService = app()->make(StoreCartServices::class);
|
||||
if (!$product_id || !is_numeric($product_id)) return app('json')->fail('参数错误');
|
||||
if (!(int)$num) return app('json')->fail('请提交加入购物车商品数量');
|
||||
$res = $cartService->setCartNum((int)$request->uid(), (int)$product_id, (int)$num, $unique, (int)$type, $is_channel, $is_send_gift);
|
||||
$str = $type == 1 ? '添加' : '删除';
|
||||
if ($res) return app('json')->successful($str . '成功');
|
||||
return app('json')->fail($str . '失败');
|
||||
}
|
||||
}
|
||||
121
app/controller/api/v2/order/StoreOrderInvoice.php
Normal file
121
app/controller/api/v2/order/StoreOrderInvoice.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\order;
|
||||
|
||||
|
||||
use app\services\order\StoreOrderInvoiceServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\system\attachment\SystemAttachmentServices;
|
||||
use app\services\store\SystemStoreServices;
|
||||
use crmeb\services\UtilService;
|
||||
use think\annotation\Inject;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* Class StoreOrderInvoice
|
||||
* @package app\api\controller\v2\order
|
||||
*/
|
||||
class StoreOrderInvoice
|
||||
{
|
||||
/**
|
||||
* @var StoreOrderInvoiceServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreOrderInvoiceServices $services;
|
||||
|
||||
/**
|
||||
* 订单开票
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function makeUp(Request $request)
|
||||
{
|
||||
[$order_id, $invoice_id] = $request->postMore([
|
||||
['order_id', 0],
|
||||
['invoice_id', 0]
|
||||
], true);
|
||||
if (!$order_id) return app('json')->fail('请选择要开票订单');
|
||||
if (!$invoice_id) return app('json')->fail('请选择发票');
|
||||
$uid = (int)$request->uid;
|
||||
return app('json')->successful($this->services->makeUp($uid, $order_id, (int)$invoice_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 开票记录
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
$uid = (int)$request->uid();
|
||||
return app('json')->successful($this->services->getOrderInvoiceList(['uid' => $uid]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @param \app\Request $request
|
||||
* @param $uni
|
||||
* @return mixed
|
||||
*/
|
||||
public function detail(StoreOrderServices $services, Request $request, $uni, $id)
|
||||
{
|
||||
if (!strlen(trim($uni))) return app('json')->fail('参数错误');
|
||||
$order = $services->getUserOrderDetail($uni, (int)$request->uid());
|
||||
if (!$order) return app('json')->fail('订单不存在');
|
||||
$order = $order->toArray();
|
||||
$orderInvoice = $this->services->get($id);
|
||||
$orderInvoice['invoice_time'] = $orderInvoice['invoice_time'] ? date('Y-m-d H:i:s', $orderInvoice['invoice_time']) : '';
|
||||
$order['invoice'] = $orderInvoice;
|
||||
//门店是否开启 || 门店自提是否开启
|
||||
if (!sys_config('store_func_status', 1) || !sys_config('store_self_mention')) {
|
||||
//关闭门店自提后 订单隐藏门店信息
|
||||
$order['shipping_type'] = 1;
|
||||
}
|
||||
if ($order['verify_code']) {
|
||||
$verify_code = $order['verify_code'];
|
||||
$verify[] = substr($verify_code, 0, 4);
|
||||
$verify[] = substr($verify_code, 4, 4);
|
||||
$verify[] = substr($verify_code, 8);
|
||||
$order['_verify_code'] = implode(' ', $verify);
|
||||
}
|
||||
$order['add_time_y'] = date('Y-m-d', $order['add_time']);
|
||||
$order['add_time_h'] = date('H:i:s', $order['add_time']);
|
||||
/** @var SystemStoreServices $storeServices */
|
||||
$storeServices = app()->make(SystemStoreServices::class);
|
||||
$order['system_store'] = $storeServices->getStoreDispose($order['store_id']);
|
||||
if (($order['shipping_type'] === 2 || $order['delivery_uid'] != 0) && $order['verify_code']) {
|
||||
$name = $order['verify_code'] . '.jpg';
|
||||
/** @var SystemAttachmentServices $attachmentServices */
|
||||
$attachmentServices = app()->make(SystemAttachmentServices::class);
|
||||
$imageInfo = $attachmentServices->getInfo(['name' => $name]);
|
||||
$siteUrl = sys_config('site_url');
|
||||
if (!$imageInfo) {
|
||||
$imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
|
||||
if (is_array($imageInfo)) {
|
||||
$attachmentServices->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
|
||||
$url = $imageInfo['dir'];
|
||||
} else
|
||||
$url = '';
|
||||
} else $url = $imageInfo['att_dir'];
|
||||
if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
|
||||
$order['code'] = $url;
|
||||
}
|
||||
$order['mapKey'] = sys_config('tengxun_map_key');
|
||||
$order['yue_pay_status'] = (int)sys_config('balance_func_status') ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
|
||||
$order['pay_weixin_open'] = (int)sys_config('pay_weixin_open') ?? 0;//微信支付 1 开启 0 关闭
|
||||
$order['ali_pay_status'] = (bool)sys_config('ali_pay_status');//支付包支付 1 开启 0 关闭
|
||||
return app('json')->successful('ok', $services->tidyOrder($order, true, true));
|
||||
}
|
||||
}
|
||||
111
app/controller/api/v2/product/StoreProduct.php
Normal file
111
app/controller/api/v2/product/StoreProduct.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\product;
|
||||
|
||||
use app\Request;
|
||||
use app\services\product\product\StoreProductReplyServices;
|
||||
use app\services\product\product\StoreProductServices;
|
||||
use app\services\product\sku\StoreProductAttrServices;
|
||||
use app\services\system\form\SystemFormServices;
|
||||
use app\services\user\level\SystemUserLevelServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
||||
class StoreProduct
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreProductServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreProductServices $services;
|
||||
|
||||
/**
|
||||
* 获取商品属性
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function getProductAttr(Request $request)
|
||||
{
|
||||
[$id, $cartNum, $is_channel, $uid] = $request->getMore([
|
||||
['id', 0],
|
||||
['type', 0],
|
||||
['is_channel', 0],
|
||||
['uid', 0]
|
||||
], true);
|
||||
if (!$id) return app('json')->fail('参数错误');
|
||||
/** @var StoreProductAttrServices $storeProductAttrServices */
|
||||
$storeProductAttrServices = app()->make(StoreProductAttrServices::class);
|
||||
$storeInfo = $this->services->getOne(['id' => $id]);
|
||||
if (!$storeInfo) {
|
||||
return app('json')->fail('商品不存在');
|
||||
}
|
||||
$storeInfo = $storeInfo ? $storeInfo->toArray() : [];
|
||||
//系统表单
|
||||
$storeInfo['custom_form'] = [];
|
||||
if ($storeInfo['system_form_id']) {
|
||||
/** @var SystemFormServices $systemFormServices */
|
||||
$systemFormServices = app()->make(SystemFormServices::class);
|
||||
$systemForm = $systemFormServices->value(['id' => $storeInfo['system_form_id']], 'value');
|
||||
if ($systemForm) {
|
||||
$storeInfo['custom_form'] = is_string($systemForm) ? json_decode($systemForm, true) : $systemForm;
|
||||
}
|
||||
}
|
||||
//有自定义表单或预售或虚拟不展示加入购物车按钮
|
||||
$storeInfo['cart_button'] = $storeInfo['custom_form'] || $storeInfo['is_presale_product'] || $storeInfo['product_type'] > 0 ? 0 : 1;
|
||||
$data['storeInfo'] = $storeInfo;
|
||||
$discount = 100;
|
||||
$uid = $uid ?: $request->uid();
|
||||
if ($uid) {
|
||||
/** @var UserServices $user */
|
||||
$user = app()->make(UserServices::class);
|
||||
$userInfo = $user->getUserCacheInfo($uid);
|
||||
//用户等级是否开启
|
||||
/** @var SystemUserLevelServices $systemLevel */
|
||||
$systemLevel = app()->make(SystemUserLevelServices::class);
|
||||
$levelInfo = $systemLevel->getLevel((int)($userInfo['level'] ?? 0));
|
||||
if (sys_config('member_func_status', 1) && $levelInfo) {
|
||||
$discount = $levelInfo['discount'] ?? 100;
|
||||
}
|
||||
}
|
||||
$minData = $this->services->getMinPrice($uid, $data['storeInfo'], $discount);
|
||||
$data['storeInfo']['price_type'] = $minData['price_type'] ?? '';
|
||||
if (!$this->services->vipIsOpen(!!$data['storeInfo']['is_vip'])) $data['storeInfo']['is_vip'] = 0;
|
||||
[$data['productAttr'], $data['productValue']] = $storeProductAttrServices->getProductAttrDetail($id, (int)$uid, $cartNum, 0, 0, $data['storeInfo'], -1, $is_channel);
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品评论
|
||||
* @param Request $request
|
||||
* @param StoreProductReplyServices $services
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function reply_list(Request $request, StoreProductReplyServices $services, $id)
|
||||
{
|
||||
[$type] = $request->getMore([
|
||||
[['type', 'd'], 0]
|
||||
], true);
|
||||
$list = $services->getNewProductReplyList($id, $type, $request->uid());
|
||||
return app('json')->successful(get_thumb_water($list, 'small', ['pics']));
|
||||
}
|
||||
}
|
||||
52
app/controller/api/v2/user/StoreService.php
Normal file
52
app/controller/api/v2/user/StoreService.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\user;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use app\services\message\service\StoreServiceLogServices;
|
||||
use app\services\message\service\StoreServiceServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class StoreService
|
||||
* @package app\api\controller\v2\user
|
||||
*/
|
||||
class StoreService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var StoreServiceLogServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected StoreServiceLogServices $services;
|
||||
|
||||
/**
|
||||
* 客服聊天记录
|
||||
* @param Request $request
|
||||
* @param StoreServiceServices $services
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function record(Request $request, StoreServiceServices $services)
|
||||
{
|
||||
[$uidTo, $limit, $toUid] = $request->getMore([
|
||||
[['uidTo', 'd'], 0],
|
||||
[['limit', 'd'], 10],
|
||||
[['toUid', 'd'], 0],
|
||||
], true);
|
||||
$uid = (int)$request->uid();
|
||||
return app('json')->successful($services->getRecord($uid, $uidTo, $limit, $toUid));
|
||||
}
|
||||
}
|
||||
91
app/controller/api/v2/user/User.php
Normal file
91
app/controller/api/v2/user/User.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\user;
|
||||
|
||||
use app\Request;
|
||||
use app\services\system\CapitalFlowServices;
|
||||
use app\services\user\UserBrokerageServices;
|
||||
use app\services\user\UserMoneyServices;
|
||||
use app\services\user\UserServices;
|
||||
use app\services\wechat\WechatServices;
|
||||
use think\annotation\Inject;
|
||||
|
||||
|
||||
/**
|
||||
* 用户类
|
||||
* Class User
|
||||
* @package app\controller\api\v2\user
|
||||
*/
|
||||
class User
|
||||
{
|
||||
|
||||
/**
|
||||
* @var UserServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserServices $services;
|
||||
|
||||
/**
|
||||
* 用户记录0:所有余额1:余额消费2:余额充值3:佣金4:提现
|
||||
* @param Request $request
|
||||
* @param $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function userMoneyList(Request $request, $type)
|
||||
{
|
||||
$where = $request->getMore([
|
||||
['start', 0],
|
||||
['stop', 0],
|
||||
['keyword', '']
|
||||
]);
|
||||
$uid = (int)$request->uid();
|
||||
switch ((int)$type) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
/** @var UserMoneyServices $services */
|
||||
$services = app()->make(UserMoneyServices::class);
|
||||
$data = $services->userMoneyList($uid, (int)$type, $where);
|
||||
break;
|
||||
case 3:
|
||||
/** @var UserBrokerageServices $services */
|
||||
$services = app()->make(UserBrokerageServices::class);
|
||||
$data = $services->userBrokerageList($uid, $where);
|
||||
break;
|
||||
case 4:
|
||||
/** @var UserBrokerageServices $services */
|
||||
$services = app()->make(UserBrokerageServices::class);
|
||||
$data = $services->userExtractList($uid, $where);
|
||||
break;
|
||||
case 9://资金记录
|
||||
/** @var CapitalFlowServices $services */
|
||||
$services = app()->make(CapitalFlowServices::class);
|
||||
$data = $services->userCapitalList($uid, $where);
|
||||
break;
|
||||
default:
|
||||
$data = [];
|
||||
}
|
||||
return app('json')->successful($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新公众号用户信息
|
||||
* @param Request $request
|
||||
* @param WechatServices $services
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateUserInfo(Request $request, WechatServices $services)
|
||||
{
|
||||
return app('json')->success($services->updateUserInfo((int)$request->uid()));
|
||||
}
|
||||
|
||||
}
|
||||
163
app/controller/api/v2/user/UserInvoice.php
Normal file
163
app/controller/api/v2/user/UserInvoice.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\user;
|
||||
|
||||
|
||||
use app\services\user\UserInvoiceServices;
|
||||
use think\annotation\Inject;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* Class UserInvoice
|
||||
* @package app\api\controller\v2\user
|
||||
*/
|
||||
class UserInvoice
|
||||
{
|
||||
/**
|
||||
* @var UserInvoiceServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserInvoiceServices $services;
|
||||
|
||||
/**
|
||||
* 获取单个发票信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function invoice($id)
|
||||
{
|
||||
if (!$id) {
|
||||
app('json')->fail('缺少参数');
|
||||
}
|
||||
return app('json')->successful($this->services->getInvoice((int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发票列表
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function invoiceList(Request $request)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
['header_type', ''],
|
||||
['type', '']
|
||||
]);
|
||||
$uid = (int)$request->uid();
|
||||
return app('json')->successful($this->services->getUserList($uid, $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认发票
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function setDefaultInvoice(Request $request)
|
||||
{
|
||||
[$id] = $request->getMore([
|
||||
['id', 0]
|
||||
], true);
|
||||
if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
|
||||
$uid = (int)$request->uid();
|
||||
$this->services->setDefaultInvoice($uid, (int)$id);
|
||||
return app('json')->successful('设置成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认发票
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefaultInvoice(Request $request)
|
||||
{
|
||||
[$type] = $request->postMore(['type', 1], true);
|
||||
$uid = (int)$request->uid();
|
||||
$defaultInvoice = $this->services->getUserDefaultInvoice($uid, (int)$type);
|
||||
if ($defaultInvoice) {
|
||||
$defaultInvoice = $defaultInvoice->toArray();
|
||||
return app('json')->successful('ok', $defaultInvoice);
|
||||
}
|
||||
return app('json')->successful('empty', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改 添加地址
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function saveInvoice(Request $request)
|
||||
{
|
||||
$data = $request->postMore([
|
||||
[['id', 'd'], 0],
|
||||
[['header_type', 'd'], 1],
|
||||
[['type', 'd'], 1],
|
||||
['drawer_phone', ''],
|
||||
['email', ''],
|
||||
['name', ''],
|
||||
['duty_number', ''],
|
||||
['tell', ''],
|
||||
['address', ''],
|
||||
['bank', ''],
|
||||
['card_number', ''],
|
||||
['is_default', 0]
|
||||
]);
|
||||
if (!$data['drawer_phone']) return app('json')->fail('请填写开票手机号');
|
||||
if (!check_phone($data['drawer_phone'])) return app('json')->fail('手机号码格式不正确');
|
||||
if (!$data['name']) return app('json')->fail('请填写发票抬头(开具发票企业名称)');
|
||||
if (!in_array($data['header_type'], [1, 2])) {
|
||||
$data['header_type'] = empty($data['duty_number']) ? 1 : 2;
|
||||
}
|
||||
if ($data['header_type'] == 1 && !preg_match('/^[\x80-\xff]{2,60}$/', $data['name'])) {
|
||||
return app('json')->fail('请填写正确的发票抬头(开具发票企业名称)');
|
||||
}
|
||||
if ($data['header_type'] == 2 && !preg_match('/^[0-9a-zA-Z&\(\)\(\)\x80-\xff]{2,150}$/', $data['name'])) {
|
||||
return app('json')->fail('请填写正确的发票抬头(开具发票企业名称)');
|
||||
}
|
||||
if ($data['header_type'] == 2 && !$data['duty_number']) {
|
||||
return app('json')->fail('请填写发票税号');
|
||||
}
|
||||
if ($data['header_type'] == 2 && !preg_match('/^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/', $data['duty_number'])) {
|
||||
return app('json')->fail('请填写正确的发票税号');
|
||||
}
|
||||
if ($data['header_type'] == 1) {//个人清空企业相关字段
|
||||
$data['duty_number'] = $data['tell'] = $data['address'] = $data['bank'] = $data['card_number'] = '';
|
||||
}
|
||||
$uid = (int)$request->uid();
|
||||
$re = $this->services->saveInvoice($uid, $data);
|
||||
if ($re) {
|
||||
return app('json')->success($re['type'] == 'edit' ? $re['msg'] : $re['data']);
|
||||
} else {
|
||||
return app('json')->fail('处理失败');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除发票
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function delInvoice(Request $request)
|
||||
{
|
||||
[$id] = $request->postMore([['id', 0]], true);
|
||||
if (!$id || !is_numeric($id)) return app('json')->fail('参数错误!');
|
||||
$uid = (int)$request->uid();
|
||||
$re = $this->services->delInvoice($uid, (int)$id);
|
||||
if ($re)
|
||||
return app('json')->successful();
|
||||
else
|
||||
return app('json')->fail('删除地址失败!');
|
||||
}
|
||||
}
|
||||
52
app/controller/api/v2/user/UserSearch.php
Normal file
52
app/controller/api/v2/user/UserSearch.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\user;
|
||||
|
||||
|
||||
use app\services\user\UserSearchServices;
|
||||
use think\annotation\Inject;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* Class UserSearch
|
||||
* @package app\api\controller\v2\user
|
||||
*/
|
||||
class UserSearch
|
||||
{
|
||||
/**
|
||||
* @var UserSearchServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserSearchServices $services;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \think\Response
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 等风来
|
||||
* @email 136327134@qq.com
|
||||
* @date 2023/9/19
|
||||
*/
|
||||
public function getUserSearchList(Request $request)
|
||||
{
|
||||
return app('json')->successful($this->services->getUserList((int)$request->uid()));
|
||||
}
|
||||
|
||||
public function cleanUserSearch(Request $request)
|
||||
{
|
||||
$uid = (int)$request->uid();
|
||||
$this->services->update(['uid' => $uid], ['is_del' => 1]);
|
||||
return app('json')->successful('删除成功');
|
||||
}
|
||||
}
|
||||
221
app/controller/api/v2/wechat/Routine.php
Normal file
221
app/controller/api/v2/wechat/Routine.php
Normal file
@@ -0,0 +1,221 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\api\v2\wechat;
|
||||
|
||||
use app\Request;
|
||||
use app\services\wechat\RoutineServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
|
||||
/**
|
||||
* Class Routine
|
||||
* @package app\api\controller\v2\wechat
|
||||
*/
|
||||
class Routine
|
||||
{
|
||||
|
||||
/**
|
||||
* @var RoutineServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected RoutineServices $services;
|
||||
|
||||
/**
|
||||
* 返回用户信息的缓存key,返回是否强制绑定手机号
|
||||
* @param $code
|
||||
* @param $spread_code
|
||||
* @param $spread_spid
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function authType($code, $spread_code = '', $spread_spid = '')
|
||||
{
|
||||
if (!$code) return app('json')->fail('参数有误');
|
||||
$data = $this->services->authType($code, $spread_spid, $spread_code);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据缓存获取token
|
||||
* @param $key
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function authLogin($key)
|
||||
{
|
||||
if (!$key) return app('json')->fail('参数有误');
|
||||
$data = $this->services->authLogin($key);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param $phone
|
||||
* @param $captcha
|
||||
* @param $spread_code
|
||||
* @param $spread_spid
|
||||
* @param $code
|
||||
* @return \think\Response
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function phoneLogin($key = '', $phone = '', $captcha = '', $spread_code = '', $spread_spid = '', $code = '')
|
||||
{
|
||||
//验证验证码
|
||||
$verifyCode = CacheService::get('code_' . $phone);
|
||||
if (!$verifyCode)
|
||||
return app('json')->fail('请先获取验证码');
|
||||
$verifyCode = substr($verifyCode, 0, 6);
|
||||
if ($verifyCode != $captcha) {
|
||||
return app('json')->fail('验证码错误');
|
||||
}
|
||||
CacheService::delete('code_' . $phone);
|
||||
$data = $this->services->phoneLogin($key, $phone, $spread_spid, $spread_code, $code);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序绑定手机号
|
||||
* @param $code
|
||||
* @param $iv
|
||||
* @param $encryptedData
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function bindingPhone($code = '', $iv = '', $encryptedData = '')
|
||||
{
|
||||
if (!$code || !$iv || !$encryptedData) return app('json')->fail('参数有误');
|
||||
$this->services->bindingPhone($code, $iv, $encryptedData);
|
||||
return app('json')->success(410016);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序授权登录
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function auth(Request $request)
|
||||
{
|
||||
[$code, $spread_spid, $spread_code, $iv, $encryptedData] = $request->postMore([
|
||||
['code', ''],
|
||||
['spread_spid', 0],
|
||||
['spread_code', ''],
|
||||
['iv', ''],
|
||||
['encryptedData', ''],
|
||||
], true);
|
||||
$token = $this->services->newAuth($code, $spread_spid, $spread_code, $iv, $encryptedData);
|
||||
if ($token) {
|
||||
if (isset($token['key']) && $token['key']) {
|
||||
return app('json')->successful('授权成功,请绑定手机号', $token);
|
||||
} else {
|
||||
return app('json')->successful('登录成功!', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp'], 'store_user_avatar' => $token['store_user_avatar'] ?? 0]);
|
||||
}
|
||||
} else
|
||||
return app('json')->fail('获取用户访问token失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默授权
|
||||
* @param $code
|
||||
* @param $spread
|
||||
* @return mixed
|
||||
*/
|
||||
public function silenceAuth($code, $spread_code = '', $spread_spid = '')
|
||||
{
|
||||
$token = $this->services->silenceAuth($code, (int)$spread_code, (int)$spread_spid);
|
||||
if ($token && isset($token['key'])) {
|
||||
return app('json')->success('授权成功,请绑定手机号', $token);
|
||||
} else if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'expires_time' => $token['params']['exp'], 'store_user_avatar' => $token['store_user_avatar'] ?? 0]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默授权 不登录
|
||||
* @param $code
|
||||
* @param $spread
|
||||
* @return mixed
|
||||
*/
|
||||
public function silenceAuthNoLogin($code, $spread_code = '', $spread_spid = '')
|
||||
{
|
||||
$token = $this->services->silenceAuth($code, (int)$spread_code, (int)$spread_spid, true);
|
||||
if ($token && isset($token['auth_login'])) {
|
||||
return app('json')->success('授权成功');
|
||||
} else if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp'], 'store_user_avatar' => $token['store_user_avatar'] ?? 0]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默授权
|
||||
* @param $code
|
||||
* @param $spread
|
||||
* @return mixed
|
||||
*/
|
||||
public function silenceAuthBindingPhone($code = '', $spread_code = '', $spread_spid = '', $phone = '', $captcha = '')
|
||||
{
|
||||
//验证验证码
|
||||
$verifyCode = CacheService::get('code_' . $phone);
|
||||
if (!$verifyCode)
|
||||
return app('json')->fail('请先获取验证码');
|
||||
$verifyCode = substr($verifyCode, 0, 6);
|
||||
if ($verifyCode != $captcha) {
|
||||
CacheService::delete('code_' . $phone);
|
||||
return app('json')->fail('验证码错误');
|
||||
}
|
||||
CacheService::delete('code_' . $phone);
|
||||
$token = $this->services->silenceAuthBindingPhone($code, $spread_code, $spread_spid, $phone);
|
||||
if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'expires_time' => $token['params']['exp'], 'store_user_avatar' => $token['store_user_avatar'] ?? 0]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 授权获取小程序用户手机号 直接绑定
|
||||
* @param $code
|
||||
* @param $iv
|
||||
* @param $encryptedData
|
||||
* @return mixed
|
||||
*/
|
||||
public function authBindingPhone($code = '', $iv = '', $encryptedData = '', $spread_code = '', $spread_spid = '', $key = '')
|
||||
{
|
||||
if (!$code || !$iv || !$encryptedData)
|
||||
return app('json')->fail('参数有误');
|
||||
$token = $this->services->authBindingPhone($code, $iv, $encryptedData, $spread_code, $spread_spid, $key);
|
||||
if ($token) {
|
||||
return app('json')->success('登录成功', $token);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
* @param $userInfo
|
||||
* @return mixed
|
||||
*/
|
||||
public function updateInfo(Request $request, $userInfo)
|
||||
{
|
||||
if (!$userInfo) {
|
||||
return app('json')->fail('参数有误');
|
||||
}
|
||||
$uid = (int)$request->uid();
|
||||
$re = $this->services->updateUserInfo($uid, $userInfo);
|
||||
if ($re) {
|
||||
return app('json')->success('更新成功');
|
||||
} else
|
||||
return app('json')->fail('更新失败');
|
||||
}
|
||||
}
|
||||
127
app/controller/api/v2/wechat/Wechat.php
Normal file
127
app/controller/api/v2/wechat/Wechat.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\api\v2\wechat;
|
||||
|
||||
use app\Request;
|
||||
use app\services\wechat\WechatServices;
|
||||
use crmeb\services\CacheService;
|
||||
use think\annotation\Inject;
|
||||
|
||||
/**
|
||||
* Class Wechat
|
||||
* @package app\api\controller\v2\wechat
|
||||
*/
|
||||
class Wechat
|
||||
{
|
||||
|
||||
/**
|
||||
* @var WechatServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected WechatServices $services;
|
||||
|
||||
|
||||
/**
|
||||
* @param $spread_spid
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function authLogin($spread_spid = '')
|
||||
{
|
||||
$data = $this->services->authLogin((int)$spread_spid);
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公众号授权登陆
|
||||
* @param Request $request
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function auth(Request $request)
|
||||
{
|
||||
[$spread_spid, $login_type] = $request->getMore([
|
||||
[['spread_spid', 'd'], 0],
|
||||
['login_type', 'wechat'],
|
||||
], true);
|
||||
$token = $this->services->newAuth($spread_spid, $login_type);
|
||||
if ($token && isset($token['key'])) {
|
||||
return app('json')->success('授权成功,请绑定手机号', $token);
|
||||
} else if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp']]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号静默授权
|
||||
* @param $code
|
||||
* @param $spread_spid
|
||||
* @return mixed
|
||||
*/
|
||||
public function silenceAuth($spread_spid = '')
|
||||
{
|
||||
$token = $this->services->silenceAuth($spread_spid);
|
||||
if ($token && isset($token['key'])) {
|
||||
return app('json')->success('授权成功,请绑定手机号', $token);
|
||||
} else if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'expires_time' => $token['params']['exp']]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信公众号静默授权
|
||||
* @param $code
|
||||
* @param $spread_spid
|
||||
* @return mixed
|
||||
*/
|
||||
public function silenceAuthNoLogin($spread_spid = '', $snsapi = '')
|
||||
{
|
||||
$token = $this->services->silenceAuth($spread_spid, true, $snsapi);
|
||||
if ($token && isset($token['auth_login'])) {
|
||||
return app('json')->success('授权成功', $token);
|
||||
} else if ($token) {
|
||||
return app('json')->success('登录成功', ['token' => $token['token'], 'userInfo' => $token['userInfo'], 'expires_time' => $token['params']['exp']]);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 静默授权 手机号直接注册登录
|
||||
* @param string $key
|
||||
* @param string $phone
|
||||
* @param string $captcha
|
||||
* @return mixed
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function silenceAuthBindingPhone($key = '', $phone = '', $captcha = '')
|
||||
{
|
||||
//验证验证码
|
||||
$verifyCode = CacheService::get('code_' . $phone);
|
||||
if (!$verifyCode)
|
||||
return app('json')->fail('请先获取验证码');
|
||||
$verifyCode = substr($verifyCode, 0, 6);
|
||||
if ($verifyCode != $captcha) {
|
||||
CacheService::delete('code_' . $phone);
|
||||
return app('json')->fail('验证码错误');
|
||||
}
|
||||
CacheService::delete('code_' . $phone);
|
||||
$token = $this->services->silenceAuthBindingPhone($key, $phone);
|
||||
if ($token) {
|
||||
return app('json')->success('登录成功', $token);
|
||||
} else
|
||||
return app('json')->fail('登录失败');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user