This commit is contained in:
luofei 2024-06-05 11:00:47 +08:00
commit 516078ead1
15 changed files with 162 additions and 62 deletions

View File

@ -55,13 +55,14 @@ class StoreBranchProductController extends BaseAdminController
*/
public function edit()
{
d(1);
$params = (new StoreProductValidate())->post()->goCheck('edit');
$result = StoreProductLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
$params =$this->request->post();
foreach($params['data'] as $k=>$v){
StoreProductLogic::stock($v);
if(StoreProductLogic::hasError()){
return $this->fail(StoreProductLogic::getError());
}
}
return $this->fail(StoreProductLogic::getError());
return $this->success('编辑成功', [], 1, 1);
}

View File

@ -257,4 +257,21 @@ class StoreProductLogic extends BaseLogic
return false;
}
}
/**
* 增加库存
*/
public static function stock($data){
Db::startTrans();
try {
StoreBranchProduct::where(['id' => $data['id']])->inc('stock',$data['stock'])->update();
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -6,6 +6,7 @@ use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic;
use app\common\model\retail\Cashierclass;
use app\common\service\pay\PayService;
use support\Cache;
use support\Log;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\NotParse()]
@ -27,6 +28,8 @@ class PayController extends BaseApiController
{
$app = new PayService(1);
$result = $app->wechat->callback(Request()->post());
Cache::set('log'.time(),$result);
Cache::set('logJ'.time(),json_encode($result));
if ($result && $result->event_type == 'TRANSACTION.SUCCESS') {
$ciphertext = $result->resource['ciphertext'];
if ($ciphertext['trade_state'] === 'SUCCESS') {

View File

@ -24,7 +24,7 @@ class CartController extends BaseApiController
{
$params = (new CartValidate())->post()->goCheck('add');
$params['uid'] = $this->request->userId;
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'delete_time' => null])->find();
$result = Cart::where(['uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0,'delete_time' => null])->find();
$count = Cart::where(['uid' => $params['uid'], 'delete_time' => null, 'is_pay' => 0])->count();
if ($count > 100) {
return $this->fail('购物车商品不能大于100个请先结算');

View File

@ -2,8 +2,6 @@
namespace app\api\controller\order;
//use app\admin\logic\order\CartLogic;
//use app\admin\logic\retail\StoreOrderLogic;
use app\api\logic\order\OrderLogic;
use app\api\controller\BaseApiController;
use app\api\lists\order\OrderList;
@ -12,12 +10,8 @@ use app\api\validate\OrderValidate;
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
use app\common\logic\PayNotifyLogic;
use app\common\model\order\Cart;
use app\common\model\store_order\StoreOrder;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\service\wechat\WeChatConfigService;
use support\Log;
use Webman\RedisQueue\Redis;
use hg\apidoc\annotation as ApiDoc;
@ -48,7 +42,6 @@ class OrderController extends BaseApiController
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array", children:[
['name' => 'order', 'desc' => '订单信息', 'type' => 'array', 'children' => [
['name' => 'add_time', 'desc' => '添加时间', 'type' => 'int'],
['name' => 'create_time', 'desc' => '订单创建时间', 'type' =>'int'],
['name' => 'order_id', 'desc' => '订单id', 'type' => 'int'],
['name' => 'total_price', 'desc' => '订单总金额', 'type' => 'float'],
@ -350,7 +343,15 @@ class OrderController extends BaseApiController
}
}
//核销
#[
ApiDoc\Title('核销'),
ApiDoc\url('/api/order/order/writeoff_order'),
ApiDoc\Method('POST'),
ApiDoc\Param(name: "verify_code", type: "string", require: true, desc: "验证码"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function writeoff_order()
{
$params = (new OrderValidate())->post()->goCheck('check');
@ -359,7 +360,7 @@ class OrderController extends BaseApiController
if ($res) {
return $this->success('核销成功');
}
return $this->fail('核销失败');
return $this->fail('核销失败'.OrderLogic::getError());
}

View File

@ -4,11 +4,13 @@ namespace app\api\controller\user;
use app\api\controller\BaseApiController;
use app\api\logic\user\UserLogic;
use app\api\validate\PasswordValidate;
use app\api\validate\SetUserInfoValidate;
use app\api\validate\UserValidate;
use app\common\enum\PayEnum;
use app\common\logic\PaymentLogic;
use hg\apidoc\annotation as ApiDoc;
#[ApiDoc\NotParse()]
use taoser\Validate;
#[ApiDoc\title('用户')]
/**
* 用户控制器
@ -17,14 +19,15 @@ use hg\apidoc\annotation as ApiDoc;
*/
class UserController extends BaseApiController
{
/**
* @notes 获取小程序手机号
* @return
* @author 段誉
* @date 2022/9/21 16:46
*/
#[
ApiDoc\Title('获取小程序手机号'),
ApiDoc\url('/api/user/user/getMobileByMnp'),
ApiDoc\Method('POST'),
ApiDoc\Param(name: "code", type: "string", require: true, desc: "换取手机的code"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function getMobileByMnp()
{
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
@ -38,11 +41,44 @@ class UserController extends BaseApiController
}
#[
ApiDoc\Title('用户个人信息'),
ApiDoc\url('/api/user/user/info'),
ApiDoc\Method('POST'),
ApiDoc\Param(),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function info()
{
return $this->success('success', UserLogic::info($this->userId));
}
#[
ApiDoc\Title('小程序充值'),
ApiDoc\url('/api/user/user/recharge'),
ApiDoc\Method('POST'),
ApiDoc\Param(name: "price", type: "string", require: true, desc: "金额"),
ApiDoc\NotHeaders(),
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
ApiDoc\ResponseSuccess("data", type: "array"),
]
public function recharge()
{
$params = (new UserValidate())->post()->goCheck('rechargeMoney');
$params['uid'] = $this->userId;
$params['channel_type'] = $this->userInfo['terminal'];
$order = UserLogic::recharge($params);
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY, 'StoreOrder', $order, $this->userInfo['terminal'], $redirectUrl);
if (PaymentLogic::hasError()) {
return $this->fail(PaymentLogic::getError(), $params);
}
return $this->success('', $result);
}
}

View File

@ -5,9 +5,6 @@ namespace app\api\lists\order;
use app\admin\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\goods\Goods;
use app\common\model\retail\Cashierclass;
use app\common\model\retail\Cashierinfo;
use app\common\model\store_order\StoreOrder;
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
@ -28,7 +25,7 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['paid','status'],
'=' => ['paid','status','is_writeoff'],
'between_time' => 'create_time',
'%like%' => ['order_id'],
];
@ -47,12 +44,12 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
{
$userId=$this->request->userId;
if(!$userId) return [];
return StoreOrder::where($this->searchWhere)->where('uid',$userId)
return StoreOrder::with(['store'])->where($this->searchWhere)->where('uid',$userId)
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->each(function($item){
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num')->limit(3)->select();
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select();
$item['goods_count']=count(explode(',',$item['cart_id']));
})
->toArray();
@ -66,7 +63,8 @@ class OrderList extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
return StoreOrder::where($this->searchWhere)->count();
$userId=$this->request->userId;
return StoreOrder::where($this->searchWhere)->where('uid',$userId)->count();
}
}

View File

@ -36,7 +36,6 @@ class CartLogic extends BaseLogic
'staff_id' => $params['staff_id']??0,
'product_attr_unique' => '',
'cart_num' => $params['cart_num'],
'add_time' => time(),
'is_new' => $params['is_new']??0,
]);
Db::commit();

View File

@ -8,7 +8,6 @@ use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\logic\CapitalFlowLogic;
use app\common\logic\StoreFinanceFlowLogic;
use app\common\model\merchant\Merchant;
use app\common\model\order\Cart;
use app\common\model\store_branch_product\StoreBranchProduct;
use app\common\model\store_order\StoreOrder;
@ -19,7 +18,6 @@ use app\common\model\store_product_unit\StoreProductUnit;
use app\common\model\system_store\SystemStore;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\Request;
use support\Log;
use taoser\exception\ValidateException;
use think\Exception;
@ -71,7 +69,6 @@ class OrderLogic extends BaseLogic
self::$total = bcadd(self::$total, $cart_select[$k]['total'], 2);
}
$order = [
'add_time' => time(),
'create_time' => time(),
'order_id' => getNewOrderId('PF'),
'total_price' => self::$total,//总价
@ -101,10 +98,6 @@ class OrderLogic extends BaseLogic
if (!$orderInfo) {
return false;
}
// `delivery_name`快递名称/送货人姓名',
// `delivery_code`'快递公司编码',
// `delivery_type` '发货类型',
// `delivery_id'快递单号/手机号',
$_order = $orderInfo['order'];
$_order['deduction_price'] = 0;
$_order['uid'] = request()->userId;
@ -113,7 +106,10 @@ class OrderLogic extends BaseLogic
$_order['mobile'] = $user['mobile'];
$_order['pay_type'] = $orderInfo['order']['pay_type'];
$_order['verify_code'] = $verify_code;
if (isset($params['reservation_time'])) {
$_order['reservation_time'] = $params['reservation_time'];
$_order['reservation'] = YesNoEnum::YES;
}
if ($addressId > 0) {
$address = UserAddress::where(['id' => $addressId, 'uid' => Request()->userId])->find();
if ($address) {
@ -122,12 +118,6 @@ class OrderLogic extends BaseLogic
$_order['user_address'] = $address['detail'];
}
}
// if($params['pay_type']==PayEnum::WECHAT_PAY_BARCODE){
// $_order['source']=1;
// }
// if($params['pay_type']==PayEnum::CASH_PAY){
// $_order['money']=$_order['total'];
// }
Db::startTrans();
try {
@ -141,7 +131,7 @@ class OrderLogic extends BaseLogic
}
(new StoreOrderCartInfo())->saveAll($goods_list);
$where = ['is_pay' => 0];
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1, 'delete_time' => time()]);
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
Db::commit();
return $order;
} catch (\Exception $e) {
@ -361,7 +351,6 @@ class OrderLogic extends BaseLogic
$store_id = StoreProduct::where('id', $v['product_id'])->value('store_id');
$data[$k]['store_id'] = $store_id;
$data[$k]['staff_id'] = $v['staff_id'];
$data[$k]['add_time'] = time();
$data[$k]['combination_id'] = 0;
$data[$k]['seckill_id'] = 0;
$data[$k]['bargain_id'] = 0;
@ -391,9 +380,9 @@ class OrderLogic extends BaseLogic
$item['msg'] = '预计48小时发货';
$item['unit_name'] = StoreProductUnit::where('id', $item['unit'])->value('name');
});
$merchant = Merchant::where('mer_id', $find['merchant'])->field('mer_id,uid,mer_name,service_phone,mer_address')->find();
$merchant['real_name'] = User::where('id', $merchant['uid'])->value('real_name');
$find['merchant_info'] = $merchant;
$store = SystemStore::where('id', $find['store_id'])->field('id,name,phone,address,detailed_address')->find();
$find['store_info'] = $store;
}
return $find;
@ -425,6 +414,7 @@ class OrderLogic extends BaseLogic
try {
StoreOrder::update([
'status' => OrderEnum::RECEIVED_GOODS,
'is_writeoff' => OrderEnum::IS_OK,
'update_time' => time(),
], ['id' => $data['id']]);
(new StoreOrderCartInfo())->update([

View File

@ -3,7 +3,11 @@
namespace app\api\logic\user;
use app\common\{logic\BaseLogic, model\system_store\SystemStore, model\user\User, service\wechat\WeChatMnpService};
use app\common\{logic\BaseLogic,
model\system_store\SystemStore,
model\user\User,
model\user\UserRecharge,
service\wechat\WeChatMnpService};
/**
* 会员逻辑层
@ -78,4 +82,13 @@ class UserLogic extends BaseLogic
}
public static function recharge($param)
{
$param['order_id'] = getNewOrderId('rc');
$param['recharge_type'] = 'wechat';
return UserRecharge::create($param);
}
}

View File

@ -47,4 +47,15 @@ class UserValidate extends BaseValidate
}
/**
* @notes 充值
* @return UserValidate
* @author: codeliu
* @Time: 2024/6/4 22:50
*/
public function sceneRechargeMoney()
{
return $this->only(['price']);
}
}

View File

@ -47,6 +47,12 @@ class OrderEnum
const RECEIVED_GOODS = 2;
/**
* 核销
* @IS_OK 已核销
*/
const IS_OK = 1;
/**
* 账户类型
* @USER 用户

View File

@ -12,7 +12,7 @@ class CapitalFlowLogic extends BaseLogic
public function __construct($obj, $type = 'user')
{
if (isset($type)) {
if (isset($type) && $type == 'user') {
$this->user = $obj;
} else {
$this->store = $obj;
@ -85,7 +85,7 @@ class CapitalFlowLogic extends BaseLogic
public function storeIncome($category, $linkType, $linkId, $amount, $mark = '')
{
$model = new CapitalFlow();
$model->store_id = $this->store['store_id'];
$model->store_id = $this->store['id'];
$model->category = $category;
$model->link_type = $linkType;
$model->link_id = $linkId;

View File

@ -7,8 +7,7 @@ namespace app\common\logic;
use app\common\enum\PayEnum;
use app\common\model\user\UserAuth;
use app\common\service\pay\PayService;
use Yansongda\Artful\Exception\Exception as ExceptionException;
use Yansongda\Pay\Exception\Exception;
use Exception;
use function DI\string;
@ -39,6 +38,7 @@ class PaymentLogic extends BaseLogic
PayNotifyLogic::handle($from, $order['order_id']);
return ['pay_way' => PayEnum::BALANCE_PAY];
}
try {
switch ($payWay) {
case PayEnum::WECHAT_PAY:
$auth = UserAuth::where(['user_id' => $order['uid'], 'terminal' => $terminal])->findOrEmpty();
@ -50,7 +50,7 @@ class PaymentLogic extends BaseLogic
'currency' => 'CNY',
],
"payer" => [
"openid" => $auth['openid'] ?? 'onoIP7c1qgjfIr2ce7GJAAmVGcL0'
"openid" => $auth['openid']
],
'attach' => $from
];
@ -61,6 +61,10 @@ class PaymentLogic extends BaseLogic
self::$error = '订单异常';
$result = false;
}
} catch (Exception $e) {
\support\Log::info($e->extra['message']?? $e->getMessage());
throw new \Exception($e->extra['message']?? $e->getMessage());
}
return $result;
}
@ -93,7 +97,7 @@ class PaymentLogic extends BaseLogic
$wechat = new PayService(1);
try {
$result = $wechat->wechat->pos($order)->toArray();
} catch (ExceptionException $e) {
} catch (Exception $e) {
if (getenv('APP_DEBUG') == true) {
self::$error = $e->extra['message'] ?? $e->getMessage();
} else {
@ -125,7 +129,7 @@ class PaymentLogic extends BaseLogic
$wechat = new PayService();
try {
$result = $wechat->alipay->pos($order)->toArray();
} catch (ExceptionException $e) {
} catch (Exception $e) {
if (getenv('APP_DEBUG') == true) {
self::$error = $e->extra['message'] ?? $e->getMessage();
} else {

View File

@ -0,0 +1,21 @@
<?php
namespace app\common\model\user;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 用户充值表
* Class UserAddress
* @package app\common\model
*/
class UserRecharge extends BaseModel
{
use SoftDelete;
protected $pk = 'id';
protected $deleteTime = 'delete_time';
}