提交扫码枪信息
This commit is contained in:
parent
7f35cdc98f
commit
9384b1a4d1
@ -62,9 +62,9 @@ class StoreCartDao extends BaseDao
|
||||
* @param int $uid
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAll(int $uid)
|
||||
public function getAll(int $uid,$product_type)
|
||||
{
|
||||
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0,'is_dg'=>0])
|
||||
$query = ($this->getModel())::where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0,'is_dg'=>0,'product_type' => $product_type])
|
||||
->with([
|
||||
'product' => function ($query) {
|
||||
$query->field('product_id,image,store_name,is_show,status,is_del,unit_name,price,mer_status,is_used,product_type,once_max_count,once_min_count,pay_limit,mer_svip_status,svip_price_type');
|
||||
@ -137,9 +137,9 @@ class StoreCartDao extends BaseDao
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getCartCount(int $uid)
|
||||
public function getCartCount(int $uid,$product_type)
|
||||
{
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'is_dg' => 0])->field('SUM(cart_num) as count')->select();
|
||||
$data = ($this->getModel()::getDB())->where(['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'is_dg' => 0,'product_type' => $product_type])->field('SUM(cart_num) as count')->select();
|
||||
$data[0]['count'] = $data[0]['count'] ? $data[0]['count'] : 0;
|
||||
return $data;
|
||||
}
|
||||
|
@ -235,6 +235,11 @@ class StoreCart extends BaseModel
|
||||
//库存不足
|
||||
if($sku->stock < $this->cart_num || $sku->sku->stock < $this->cart_num) return false;
|
||||
break;
|
||||
case 100: //扫码枪商品
|
||||
if ($this->product->product_type !== 0 || $this->product->is_show !== 1 || $this->productAttr->stock < $this->cart_num || $this->product->is_used !== 1) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ class StoreCartRepository extends BaseRepository
|
||||
* @return array
|
||||
* @author Qinii
|
||||
*/
|
||||
public function getList($user)
|
||||
public function getList($user,$product_type)
|
||||
{
|
||||
$res = $this->dao->getAll($user->uid)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku', 'attrValue', 'attr','spu']);
|
||||
$res = $this->dao->getAll($user->uid,$product_type)->append(['checkCartProduct', 'UserPayCount', 'ActiveSku', 'attrValue', 'attr','spu']);
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$res->map(function ($item) use ($make) {
|
||||
$item['attr'] = $make->detailAttr($item['attr']);
|
||||
|
@ -224,7 +224,7 @@ class ProductRepository extends BaseRepository
|
||||
return Db::transaction(function () use ($data, $productType,$conType,$content,$product) {
|
||||
$activity_id = 0;
|
||||
$result = $this->dao->create($product);
|
||||
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0);
|
||||
$settleParams = $this->setAttrValue($data, $result->product_id, $productType, 0,$data['mer_id']);
|
||||
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $result->product_id, $data['mer_id']);
|
||||
$settleParams['attr'] = $this->setAttr($data['attr'], $result->product_id);
|
||||
if ($productType ==0 ) app()->make(ParameterValueRepository::class)->create($result->product_id, $data['params'] ?? [],$data['mer_id']);
|
||||
@ -260,7 +260,7 @@ class ProductRepository extends BaseRepository
|
||||
}
|
||||
event('product.update.before', compact('id','data','merId','productType','conType'));
|
||||
$spuData = $product = $this->setProduct($data);
|
||||
$settleParams = $this->setAttrValue($data, $id, $productType, 1);
|
||||
$settleParams = $this->setAttrValue($data, $id, $productType, 1,$merId);
|
||||
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
|
||||
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
|
||||
$content = [
|
||||
@ -270,7 +270,6 @@ class ProductRepository extends BaseRepository
|
||||
$spuData['price'] = $settleParams['data']['price'];
|
||||
$spuData['mer_id'] = $merId;
|
||||
$spuData['mer_labels'] = $data['mer_labels'];
|
||||
|
||||
Db::transaction(function () use ($id, $data, $productType, $settleParams,$content,$product,$spuData,$merId) {
|
||||
$this->save($id, $settleParams, $content, $product, $productType);
|
||||
if ($productType == 1) { //秒杀商品
|
||||
@ -543,7 +542,7 @@ class ProductRepository extends BaseRepository
|
||||
* @param int $productId
|
||||
* @return mixed
|
||||
*/
|
||||
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0)
|
||||
public function setAttrValue(array $data, int $productId, int $productType, int $isUpdate = 0,int $merId = 0)
|
||||
{
|
||||
$extension_status = systemConfig('extension_status');
|
||||
if ($isUpdate) {
|
||||
@ -594,6 +593,7 @@ class ProductRepository extends BaseRepository
|
||||
"unique" => $unique,
|
||||
'sales' => $isUpdate ? ($oldSku[$sku]['sales'] ?? 0) : 0,
|
||||
'svip_price' => $svip_price,
|
||||
'mer_id' => $merId,
|
||||
];
|
||||
$stock = $stock + intval($value['stock']);
|
||||
}
|
||||
|
@ -216,7 +216,6 @@ class Common extends BaseController
|
||||
|
||||
public function routineNotify()
|
||||
{
|
||||
Log::error(11111);
|
||||
try {
|
||||
return response(MiniProgramService::create()->handleNotify()->getContent());
|
||||
} catch (Exception $e) {
|
||||
|
@ -53,10 +53,10 @@ class StoreCart extends BaseController
|
||||
* @Date: 2020/5/28
|
||||
* @return mixed
|
||||
*/
|
||||
public function lst()
|
||||
public function lst($product_type=0)
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
return app('json')->success($this->repository->getList($this->request->userInfo()));
|
||||
return app('json')->success($this->repository->getList($this->request->userInfo(),$product_type));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +67,6 @@ class StoreCart extends BaseController
|
||||
public function create(validate $validate)
|
||||
{
|
||||
$data = $this->checkParams($validate);
|
||||
|
||||
if(!in_array($data['product_type'],[0,1,2,3,4])) return app('json')->fail('商品类型错误');
|
||||
if ($data['cart_num'] <= 0) return app('json')->fail('购买数量有误');
|
||||
$user = $this->request->userInfo();
|
||||
@ -170,9 +169,9 @@ class StoreCart extends BaseController
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
*/
|
||||
public function cartCount()
|
||||
public function cartCount($product_type=0)
|
||||
{
|
||||
return app('json')->success($this->repository->getCartCount($this->request->uid()));
|
||||
return app('json')->success($this->repository->getCartCount($this->request->uid(),$product_type));
|
||||
}
|
||||
|
||||
/**
|
||||
|
161
app/controller/api/store/order/StoreMicropayOrder.php
Normal file
161
app/controller/api/store/order/StoreMicropayOrder.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?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\store\order;
|
||||
|
||||
|
||||
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use crmeb\services\LockService;
|
||||
use crmeb\services\WechatService;
|
||||
use think\facade\Db;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use think\App;
|
||||
|
||||
/**
|
||||
* Class StoreOrder
|
||||
* @package app\controller\api\store\order
|
||||
* @author xaboy
|
||||
* @day 2020/6/10
|
||||
*/
|
||||
class StoreMicropayOrder extends BaseController
|
||||
{
|
||||
/**
|
||||
* @var StoreCartRepository
|
||||
*/
|
||||
private $StoreCartRepository;
|
||||
|
||||
public function __construct(App $app, StoreCartRepository $StoreCartRepository)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->StoreCartRepository = $StoreCartRepository;
|
||||
}
|
||||
public function addCart(){
|
||||
$bar_code = $this->request->param('bar_code', 0);
|
||||
$mer_id = $this->request->param('mer_id', 0);
|
||||
if ($mer_id==0) return app('json')->fail('商户id不能为空');
|
||||
if ($bar_code==0) return app('json')->fail('条形码不能为空');
|
||||
$find=Db::name('store_product_attr_value')->where('mer_id',$mer_id)->where('bar_code', $bar_code)->find();
|
||||
if (!$find) return app('json')->fail('商品不存在,您没有将该商品添加到店铺中');
|
||||
$data = [
|
||||
'product_type'=>100,
|
||||
'cart_num'=>1,
|
||||
'is_new'=>0,
|
||||
'product_attr_unique'=>$find['unique'],
|
||||
'product_id'=>$find['product_id'],
|
||||
'spread_id'=>'',
|
||||
];
|
||||
$user = $this->request->userInfo();
|
||||
event('user.cart.before',compact('user','data'));
|
||||
switch ($data['product_type'])
|
||||
{
|
||||
case 100:
|
||||
$result = app()->make(ProductRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||
|
||||
[$source, $sourceId, $pid] = explode(':', $this->request->param('source', '0'), 3) + ['', '', ''];
|
||||
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
|
||||
if ($data['source'] > 0) $data['source_id'] = intval($sourceId);
|
||||
break;
|
||||
}
|
||||
|
||||
unset($data['group_buying_id']);
|
||||
|
||||
if ($cart = $result['cart']) {
|
||||
//更新购物车
|
||||
$cart_id = $cart['cart_id'];
|
||||
$cart_num = ['cart_num' => ($cart['cart_num'] + $data['cart_num'])];
|
||||
$storeCart = $this->StoreCartRepository->update($cart_id,$cart_num);
|
||||
} else {
|
||||
//添加购物车
|
||||
$data['uid'] = $this->request->uid();
|
||||
$data['mer_id'] = $result['product']['mer_id'];
|
||||
$cart = $storeCart = $this->StoreCartRepository->create($data);
|
||||
}
|
||||
$product=Db::name('store_product')->where('product_id',$find['product_id'])->find();
|
||||
event('user.cart', compact('user','storeCart'));
|
||||
return app('json')->success(['product'=>$product,'product_attr' => $cart]);
|
||||
}
|
||||
|
||||
public function v2CreateOrder(StoreCartRepository $cartRepository, StoreOrderCreateRepository $orderCreateRepository)
|
||||
{
|
||||
$cartId = (array)$this->request->param('cart_id', []);
|
||||
$mer_id = $this->request->param('mer_id', 0);
|
||||
$auth_code = $this->request->param('auth_code', 0);
|
||||
$post=[];
|
||||
$couponIds=[];
|
||||
$takes=[];
|
||||
$useIntegral = false;
|
||||
$receipt_data = [];
|
||||
$extend = [];
|
||||
$mark = [];
|
||||
$payType = 'routine';
|
||||
$source = 2; // 默认来源为2 普通商品订单
|
||||
$uid = $this->request->uid();
|
||||
if (!$mer_id&&$mer_id!=0){
|
||||
return app('json')->fail('商户id不能为空');
|
||||
}
|
||||
if (!$auth_code&&$auth_code!=0){
|
||||
return app('json')->fail('付款码不能为空');
|
||||
}
|
||||
$addressId=Db::name('user_address')->where('uid',$uid)->find();
|
||||
$merchant=Db::name('merchant')->where('mer_id',$mer_id)->find();
|
||||
if (!$addressId){
|
||||
$merchant_address=Db::name('merchant_address')->where('mer_id',$mer_id)->find();
|
||||
if (!$merchant_address){
|
||||
return app('json')->fail('商户地址不存在');
|
||||
}
|
||||
$area_name=Db::name('geo_area')->where('area_code',$merchant_address['area_id'])->value('area_name');
|
||||
$street_name=Db::name('geo_street')->where('street_code',$merchant_address['street_id'])->value('street_name');
|
||||
$district_id=Db::name('city_area')->where('name',$area_name)->value('id');
|
||||
$street_id=Db::name('city_area')->where('name',$street_name)->value('id');
|
||||
$data=[
|
||||
'province'=>'四川',
|
||||
'province_id'=>22,
|
||||
'city'=>'泸州市',
|
||||
'city_id'=>1954,
|
||||
'district'=>$area_name,
|
||||
'district_id'=>$district_id,
|
||||
'street'=>$street_name,
|
||||
'street_id'=>$street_id,
|
||||
'uid'=>$uid,
|
||||
'real_name'=>$merchant['mer_name'],
|
||||
'phone'=>$merchant['mer_phone'],
|
||||
'detail'=>'付款码订单默认地址',
|
||||
'create_time'=>date('Y-m-d H:i:s'),
|
||||
];
|
||||
$addressId=Db::name('user_address')->insertGetId($data);
|
||||
}else{
|
||||
$addressId=$addressId['address_id'];
|
||||
$post=[
|
||||
'phone'=>$merchant['mer_phone'],
|
||||
'real_name'=>$merchant['mer_name'],
|
||||
];
|
||||
}
|
||||
if (!in_array($payType, StoreOrderRepository::PAY_TYPE, true))
|
||||
return app('json')->fail('请选择正确的支付方式');
|
||||
if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid)))
|
||||
return app('json')->fail('数据无效');
|
||||
|
||||
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post,$source) {
|
||||
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post,$source);
|
||||
});
|
||||
try {
|
||||
$attach['type']=1;
|
||||
return WechatService::create()->paymentMicropay($groupOrder['group_order_sn'],$groupOrder['pay_price'],'付款码支付','商户号'.$mer_id,md5(time()),$auth_code,$attach);
|
||||
} catch (\Exception $e) {
|
||||
return app('json')->status('error', $e->getMessage(), ['order_id' => $groupOrder->group_order_id]);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@ class StoreProductValidate extends Validate
|
||||
"extension_type|分销类型" => "in:0,1",
|
||||
"attr|商品规格" => "requireIf:spec_type,1|Array|checkUnique",
|
||||
"attrValue|商品属性" => "require|array|productAttrValue",
|
||||
'type|商品类型' => 'require|in:0,1',
|
||||
'type|商品类型' => 'require|in:0,1,99',
|
||||
'delivery_way|发货方式' => 'requireIf:is_ficti,0|require',
|
||||
'once_min_count|最小限购' => 'min:0',
|
||||
'pay_limit|是否限购' => 'require|in:0,1,2|payLimit',
|
||||
|
@ -403,6 +403,34 @@ class WechatService
|
||||
}
|
||||
}
|
||||
|
||||
/** 扫码枪支付
|
||||
* @param $out_trade_no
|
||||
* @param $total_fee
|
||||
* @param $body
|
||||
* @param $device_info
|
||||
* @param $nonce_str
|
||||
* @param $auth_code
|
||||
* @return Collection|\Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
public function paymentMicropay($out_trade_no, $total_fee, $body, $device_info,$nonce_str,$auth_code,$attach)
|
||||
{
|
||||
$total_fee = bcmul($total_fee, 100, 0);
|
||||
$order = array_merge(compact('out_trade_no', 'total_fee', 'body', 'device_info','nonce_str','auth_code','attach'));
|
||||
$order['spbill_create_ip'] = \request()->ip();
|
||||
$order= new Order($order);
|
||||
$result = $this->application->payment->pay($order);
|
||||
if ($result->return_code == 'SUCCESS' && $result->result_code == 'SUCCESS') {
|
||||
return $result;
|
||||
} else {
|
||||
if ($result->return_code == 'FAIL') {
|
||||
throw new WechatException('微信支付错误返回:' . $result->return_msg);
|
||||
} else if (isset($result->err_code)) {
|
||||
throw new WechatException('微信支付错误返回:' . $result->err_code_des);
|
||||
} else {
|
||||
throw new WechatException('没有获取微信支付的预支付ID,请重新发起支付!');
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param $openid
|
||||
* @param $out_trade_no
|
||||
|
Loading…
x
Reference in New Issue
Block a user