This commit is contained in:
luofei 2024-03-15 17:20:56 +08:00
commit eefde6451a
4 changed files with 151 additions and 0 deletions

View File

@ -23,6 +23,7 @@ use app\common\model\store\order\StoreOrderStatus;
use app\common\model\store\order\StoreRefundOrder;
use app\common\model\system\merchant\FinancialRecord;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\User;
use app\common\model\user\UserAddress;
use app\common\model\user\UserBill;
use app\common\model\user\UserRecharge;
@ -38,6 +39,7 @@ use app\validate\api\ChangePasswordValidate;
use app\validate\api\UserAuthValidate;
use crmeb\basic\BaseController;
use crmeb\services\MiniProgramService;
use crmeb\services\PayService;
use crmeb\services\SmsService;
use crmeb\services\WechatService;
use Exception;
@ -921,4 +923,61 @@ class Auth extends BaseController
return app('json')->success($data);
}
public function marginList()
{
$user = $this->request->userInfo();
[$page, $limit] = $this->getPage();
$count = Db::name('margin_order')->where('uid', $user['uid'])->where('paid', 1)->count();
$list = Db::name('margin_order')->where('uid', $user['uid'])->where('paid', 1)->page($page, $limit)->order('order_id', 'desc')->select()->toArray();
return app('json')->success(compact('count', 'list'));
}
public function doMargin()
{
$user = $this->request->userInfo();
$merchant = Db::name('merchant')->where('uid', $user['uid'])->where('status', 1)->find();
if (!$merchant) {
return app('json')->fail('没有店铺');
}
if ($merchant['is_margin'] == 10) {
return app('json')->fail('押金已缴纳');
}
if ($merchant['margin'] == 0) {
$margin = Db::name('MerchantType')->where('mer_type_id', $merchant['type_id'])->value('margin');
$margin = bcsub($margin, $merchant['paid_margin'], 2);
} else {
$margin = $merchant['margin'];
}
if ($margin == 0) {
return app('json')->fail('当前金额为0,不能进行充值');
}
$orderSn = "bzj" . date('YmdHis') . uniqid();
Db::name('margin_order')->insert([
'uid' => $user['uid'],
'mer_id' => $merchant['mer_id'],
'order_sn' => $orderSn,
'total_price' => $margin,
'pay_type' => 1,
'create_time' => date('Y-m-d H:i:s')
]);
$param = [
"status" => 0,
"is_del" => 0,
"mer_id" => $merchant['mer_id'],
"pay_type" => 1,
"attach" => "margin",
"order_info" => '{"is_margin":1,"margin":"' . $margin . '"}',
"pay_price" => $margin,
"order_sn" => $orderSn,
"body" => $merchant['mer_name'] . ' - ' . $margin,
];
$payType = 'weixinApp';
$service = new PayService($payType, $param);
$payInfo = $service->pay(User::where(['uid' => $user['uid']])->find());
return app('json')->success($payInfo);
}
}

View File

@ -353,4 +353,70 @@ class StoreOrder extends BaseController
return app('json')->success('订单核销成功');
}
/**
* 订单结算
* @return mixed
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function settle(StoreOrderRepository $repository)
{
$id = $this->request->param('id/d');
$payType = $this->request->param('pay_type');
if ($payType == 'creditBuy') {
return app('json')->fail('支付方式不支持');
}
try {
$data = $repository->settle($id, $payType, $this->request->userInfo());
return app('json')->success('success', $data);
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());
}
}
/**
* 确认接单
* @return mixed
*/
public function confirm(StoreOrderRepository $repository)
{
$id = $this->request->param('id/d');
$type = $this->request->param('type/d');
try {
$repository->confirm($id, $type);
return app('json')->success('success');
} catch (\Exception $e) {
return app('json')->fail($e->getMessage());
}
}
/**
* 采购订单列表
* @param $merId
* @param StoreOrderRepository $orderRepository
* @return \think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function purchaseOrder($merId, StoreOrderRepository $orderRepository)
{
[$page, $limit] = $this->getPage();
$keyword = $this->request->param('keyword');
$list = $orderRepository->purchaseOrder(['mer_id' => $merId], $keyword, $page, $limit);
return app('json')->success($list);
}
/**
* 获取商户押金列表
*/
public function getOrderAutoMarginList($merId){
[$page, $limit] = $this->getPage();
$select= Db::name('financial_record')->where('mer_id',$merId)
->where('financial_type','auto_margin')
->page($page)->limit($limit)->order('financial_record_id','desc')->select();
return app('json')->success($select);
}
}

View File

@ -365,6 +365,25 @@ class Merchant extends BaseController
public function marginInfo(MerchantTakeRepository $repository)
{
$id = $this->request->param('id');
if (empty($id)) {
return app('json')->fail('参数不能为空');
}
$merchantInfo = Db::name('merchant')->where('mer_id', $id)->field('uid,mer_id,type_id,mer_name,margin,paid_margin,is_margin')->find();
if (empty($merchantInfo)) {
return app('json')->fail('参数错误');
}
$merchantInfo['unpaid_margin'] = bcsub($merchantInfo['margin'], $merchantInfo['paid_margin'], 2);
if ($merchantInfo['margin'] <= 0) {
$merchantInfo['unpaid_margin'] = 0;
$merchantInfo['paid_margin'] = 0;
}
return app('json')->success($merchantInfo);
}

View File

@ -40,6 +40,11 @@ Route::group('api/', function () {
})->prefix('api.store.order.StoreOrder');
});
//用户缴纳押金
Route::post('user/margin', 'api.Auth/doMargin');
Route::get('user/margin/list', 'api.Auth/marginList');
//退出登录
Route::post('logout', 'api.Auth/logout');
//用户信息
@ -310,6 +315,7 @@ Route::group('api/', function () {
//管理员订单
Route::group('admin/:merId', function () {
Route::get('/statistics', '/orderStatistics');
Route::get('/auto_margin', '/getOrderAutoMarginList');
Route::get('/order_price', '/orderDetail');
Route::get('/order_list', '/orderList');
Route::get('/order/:id', '/order');
@ -548,6 +554,7 @@ Route::group('api/', function () {
//编辑商户信息
Route::post('update', 'Merchant/update');
Route::get('info', 'Merchant/info');
Route::get('margin', 'Merchant/marginInfo');
})->prefix('api.store.merchant.');
Route::post('store/certificate/:merId', 'api.Auth/getMerCertificate');