Merge branch 'dev' of https://gitea.lihaink.cn/mkm/shop-php into dev
This commit is contained in:
commit
9513aceba0
File diff suppressed because it is too large
Load Diff
@ -90,7 +90,7 @@ class SpuRepository extends BaseRepository
|
|||||||
'keyword' => $param['keyword'] ?? '',
|
'keyword' => $param['keyword'] ?? '',
|
||||||
'image' => $param['image'],
|
'image' => $param['image'],
|
||||||
'price' => $param['price'],
|
'price' => $param['price'],
|
||||||
'status' => 0,
|
'status' => $param['status']??0,
|
||||||
'rank' => $param['rank'] ?? 0,
|
'rank' => $param['rank'] ?? 0,
|
||||||
'temp_id' => $param['temp_id'],
|
'temp_id' => $param['temp_id'],
|
||||||
'sort' => $param['sort'] ?? 0,
|
'sort' => $param['sort'] ?? 0,
|
||||||
|
@ -244,7 +244,14 @@ class Merchant extends BaseController
|
|||||||
if (!$this->repository->exists($id))
|
if (!$this->repository->exists($id))
|
||||||
return app('json')->fail('数据不存在');
|
return app('json')->fail('数据不存在');
|
||||||
$admins=$this->request->adminInfo();
|
$admins=$this->request->adminInfo();
|
||||||
if($admins['admin_id']!=1){
|
$admin_arr=explode(',',env('MERCHANT_Arr'));
|
||||||
|
$is_true=false;
|
||||||
|
foreach ($admins['roles'] as $k=>$v){
|
||||||
|
if(in_array($v,$admin_arr)){
|
||||||
|
$is_true=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($admins['admin_id']!=1 && $is_true==false){
|
||||||
$adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2);
|
$adminInfo = $adminRepository->merIdByAdmin($id,['account'=>'yy'.$admins['account']],2);
|
||||||
if(!$adminInfo){
|
if(!$adminInfo){
|
||||||
$pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT);
|
$pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT);
|
||||||
|
@ -109,11 +109,11 @@ class Statistics extends BaseController
|
|||||||
if (isset($parmas['keyword']) && $parmas['keyword'] != '') {
|
if (isset($parmas['keyword']) && $parmas['keyword'] != '') {
|
||||||
$where[] = ['store_name', 'like', '%' . $parmas['keyword'] . '%'];
|
$where[] = ['store_name', 'like', '%' . $parmas['keyword'] . '%'];
|
||||||
}
|
}
|
||||||
$count=Db::name('store_product')->where($where)->count();
|
$count = Db::name('store_product')->where($where)->count();
|
||||||
$list = Db::name('store_product')->where($where)->page($parmas['page'])
|
$list = Db::name('store_product')->where($where)->page($parmas['page'])
|
||||||
->field('product_id,store_name,image,price')
|
->field('product_id,store_name,image,price')
|
||||||
->limit(10)->select();
|
->limit(10)->select();
|
||||||
return app('json')->success(['page' => $parmas['page'], 'data' => $list,'count'=>$count]);
|
return app('json')->success(['page' => $parmas['page'], 'data' => $list, 'count' => $count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,7 +149,7 @@ class Statistics extends BaseController
|
|||||||
if (!isset($parmas['goods_id']) || $parmas['goods_id'] == '') {
|
if (!isset($parmas['goods_id']) || $parmas['goods_id'] == '') {
|
||||||
return app('json')->fail('goods_id:格式错误');
|
return app('json')->fail('goods_id:格式错误');
|
||||||
}
|
}
|
||||||
$mer_id=Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id');
|
$mer_id = Db::name('merchant_intention')->where('mer_intention_id', $parmas['mer_intention_id'])->value('mer_id');
|
||||||
$where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]];
|
$where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]];
|
||||||
$where[] = ['p.product_id', 'in', explode(',', $parmas['goods_id'])];
|
$where[] = ['p.product_id', 'in', explode(',', $parmas['goods_id'])];
|
||||||
$where[] = ['p.is_refund', '=', 0];
|
$where[] = ['p.is_refund', '=', 0];
|
||||||
@ -231,7 +231,7 @@ class Statistics extends BaseController
|
|||||||
// return app('json')->fail('type:格式错误');
|
// return app('json')->fail('type:格式错误');
|
||||||
// }
|
// }
|
||||||
$area[] = ['street_id', 'in', explode(',', $parmas['responsible_area'])];
|
$area[] = ['street_id', 'in', explode(',', $parmas['responsible_area'])];
|
||||||
$area[] = ['type_id', '=',17];
|
$area[] = ['type_id', '=', 17];
|
||||||
|
|
||||||
$merchant = Db::name('merchant')->where($area)->column('mer_id');
|
$merchant = Db::name('merchant')->where($area)->column('mer_id');
|
||||||
if (!$merchant) {
|
if (!$merchant) {
|
||||||
@ -262,17 +262,53 @@ class Statistics extends BaseController
|
|||||||
if (!isset($parmas['phone']) || $parmas['phone'] == '') {
|
if (!isset($parmas['phone']) || $parmas['phone'] == '') {
|
||||||
return app('json')->fail('phone:格式错误');
|
return app('json')->fail('phone:格式错误');
|
||||||
}
|
}
|
||||||
$user_id= Db::name('user')->where('account',$parmas['phone'])->value('uid');
|
$account[] = ['account', 'in', explode(',', $parmas['phone'])];
|
||||||
if(!$user_id){
|
$user_id = Db::name('user')->where($account)->value('uid');
|
||||||
|
if (!$user_id) {
|
||||||
return app('json')->fail('查询的手机号用户不存在');
|
return app('json')->fail('查询的手机号用户不存在');
|
||||||
}
|
}
|
||||||
$where[]=['create_time','between time',[date("Y-m-d H:i:s",$parmas['start_time']),date("Y-m-d H:i:s",$parmas['end_time'])]];
|
$where[] = ['create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]];
|
||||||
$where[]=['paid','=',1];
|
$where[] = ['paid', '=', 1];
|
||||||
$where[]=['status','<>',-1];
|
$where[] = ['status', '<>', -1];
|
||||||
$where[]=['uid','=',$user_id];
|
$where[] = ['uid', '=', $user_id];
|
||||||
$count=Db::name('store_order')
|
$count = Db::name('store_order')
|
||||||
->where($where)
|
->where($where)
|
||||||
->sum('pay_price');
|
->sum('pay_price');
|
||||||
return app('json')->success(['trade_amount'=>$count]);
|
return app('json')->success(['trade_amount' => $count]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询镇农科公司负责片区内的种养殖商户和供应链商户交易额
|
||||||
|
*暂无种养殖商户分类
|
||||||
|
*/
|
||||||
|
public function SupplyChainVillageBreedingPriceCount()
|
||||||
|
{
|
||||||
|
$parmas = $this->request->param();
|
||||||
|
|
||||||
|
if (!isset($parmas['start_time']) || $parmas['start_time'] == '') {
|
||||||
|
return app('json')->fail('start_time:格式错误');
|
||||||
}
|
}
|
||||||
|
if (!isset($parmas['end_time']) || $parmas['end_time'] == '') {
|
||||||
|
return app('json')->fail('end_time:格式错误');
|
||||||
|
}
|
||||||
|
if (!isset($parmas['village']) || $parmas['village'] == '') {
|
||||||
|
return app('json')->fail('village:格式错误');
|
||||||
|
}
|
||||||
|
$village_id = Db::name('geo_village')->where('village_code', $parmas['village'])->value('village_id');
|
||||||
|
$merchant_category_id = Db::name('merchant_category')->where('code', 'zhongyangzhi')->value('merchant_category_id');
|
||||||
|
$area[] = ['village_id', '=', $village_id];
|
||||||
|
$area[] = ['category_id', '=', $merchant_category_id];
|
||||||
|
|
||||||
|
$merchant = Db::name('merchant')->where($area)->column('mer_id');
|
||||||
|
if (!$merchant) {
|
||||||
|
return app('json')->fail('查询商户为空');
|
||||||
|
}
|
||||||
|
$where[] = ['p.create_time', 'between time', [date("Y-m-d H:i:s", $parmas['start_time']), date("Y-m-d H:i:s", $parmas['end_time'])]];
|
||||||
|
$where[] = ['p.is_refund', '=', 0];
|
||||||
|
$count = Db::name('store_order_product')->alias('p')
|
||||||
|
->where($where)
|
||||||
|
->join('store_order o', 'o.mer_id in (' . implode(',', $merchant) . ') and o.paid=1 and o.is_del=0')
|
||||||
|
->sum('p.total_price');
|
||||||
|
return app('json')->success(['trade_amount' => $count]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,14 +58,14 @@ class StoreProduct extends BaseController
|
|||||||
public function lst($merId)
|
public function lst($merId)
|
||||||
{
|
{
|
||||||
[$page, $limit] = $this->getPage();
|
[$page, $limit] = $this->getPage();
|
||||||
$where = $this->request->params(['cate_id', 'keyword', ['type',20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels',['order','sort']]);
|
$where = $this->request->params(['cate_id', 'keyword', ['type', 20], 'mer_cate_id', 'is_gift_bag', 'status', 'us_status', 'product_id', 'mer_labels', ['order', 'sort']]);
|
||||||
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
||||||
$typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code');
|
$typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code');
|
||||||
// if ($merchant['type_id']==12){
|
// if ($merchant['type_id']==12){
|
||||||
if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){
|
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
|
||||||
$product_type=98;//供应链
|
$product_type = 98; //供应链
|
||||||
}else{
|
} else {
|
||||||
$product_type=0;//普通商品
|
$product_type = 0; //普通商品
|
||||||
}
|
}
|
||||||
$where = array_merge($where, $this->repository->switchType($where['type'], $merId, $product_type));
|
$where = array_merge($where, $this->repository->switchType($where['type'], $merId, $product_type));
|
||||||
return app('json')->success($this->repository->getList($merId, $where, $page, $limit));
|
return app('json')->success($this->repository->getList($merId, $where, $page, $limit));
|
||||||
@ -82,21 +82,26 @@ class StoreProduct extends BaseController
|
|||||||
public function create($merId, StoreProductValidate $validate)
|
public function create($merId, StoreProductValidate $validate)
|
||||||
{
|
{
|
||||||
$res = $this->request->params($this->repository::CREATE_PARAMS);
|
$res = $this->request->params($this->repository::CREATE_PARAMS);
|
||||||
$data = $this->repository->checkParams($res,$merId);
|
$data = $this->repository->checkParams($res, $merId);
|
||||||
$data['mer_id'] = $merId;
|
$data['mer_id'] = $merId;
|
||||||
$data['is_gift_bag'] = 0;
|
$data['is_gift_bag'] = 0;
|
||||||
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
||||||
$data['status'] = $merchant->is_audit ? 0 : 1;
|
$data['status'] = $merchant->is_audit ? 0 : 1;
|
||||||
$data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
|
$data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
|
||||||
$data['rate'] = 3;
|
$data['rate'] = 3;
|
||||||
$typeCode=Db::name('merchant_type')->where('mer_type_id',$merchant['type_id'])->value('type_code');
|
$typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code');
|
||||||
if ($merchant['type_id']==12){
|
$product_type = 0; //普通商品
|
||||||
if ($typeCode==Merchant::TypeCode['TypeSupplyChain']){
|
if ($merchant['type_id'] == 12) {
|
||||||
$product_type=98;//供应链
|
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
|
||||||
}else{
|
$product_type = 98; //供应链
|
||||||
$product_type=0;//普通商品
|
}
|
||||||
}
|
}
|
||||||
$productId = $this->repository->create($data, $product_type, 1);
|
$productId = $this->repository->create($data, $product_type, 1);
|
||||||
|
if ($productId) {
|
||||||
|
return app('json')->success('添加成功');
|
||||||
|
} else {
|
||||||
|
return app('json')->fail('添加失败');
|
||||||
|
}
|
||||||
// $unique = Db::name('store_product_attr_value')->where('product_id', $productId)->value('unique');
|
// $unique = Db::name('store_product_attr_value')->where('product_id', $productId)->value('unique');
|
||||||
// if (!empty($unique) && $stockNum > 0) {
|
// if (!empty($unique) && $stockNum > 0) {
|
||||||
// $this->repository->stockIn($merId, [
|
// $this->repository->stockIn($merId, [
|
||||||
@ -104,8 +109,6 @@ class StoreProduct extends BaseController
|
|||||||
// 'unique' => $unique,
|
// 'unique' => $unique,
|
||||||
// 'number' => $stockNum,
|
// 'number' => $stockNum,
|
||||||
// ]);
|
// ]);
|
||||||
}
|
|
||||||
return app('json')->success('添加成功');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,7 +123,7 @@ class StoreProduct extends BaseController
|
|||||||
public function update($merId, $id, StoreProductValidate $validate)
|
public function update($merId, $id, StoreProductValidate $validate)
|
||||||
{
|
{
|
||||||
$res = $this->request->params($this->repository::CREATE_PARAMS);
|
$res = $this->request->params($this->repository::CREATE_PARAMS);
|
||||||
$data = $this->repository->checkParams($res,$merId,$id);
|
$data = $this->repository->checkParams($res, $merId, $id);
|
||||||
|
|
||||||
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
||||||
if (!$this->repository->merExists($merId, $id))
|
if (!$this->repository->merExists($merId, $id))
|
||||||
@ -135,8 +138,12 @@ class StoreProduct extends BaseController
|
|||||||
$data['mer_id'] = $merId;
|
$data['mer_id'] = $merId;
|
||||||
$typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
|
$typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
|
||||||
$productType = $merchant->type_id == $typeSupplyChainId ? 98 : 0;
|
$productType = $merchant->type_id == $typeSupplyChainId ? 98 : 0;
|
||||||
$this->repository->edit($id, $data, $merId, $productType, 1);
|
$product=$this->repository->edit($id, $data, $merId, $productType, 1);
|
||||||
return app('json')->success('编辑成功');
|
if ($product) {
|
||||||
|
return app('json')->success('编辑成功');
|
||||||
|
} else {
|
||||||
|
return app('json')->fail('编辑失败');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,7 +174,7 @@ class StoreProduct extends BaseController
|
|||||||
$status = $this->request->param('status', 0) == 1 ? 1 : 0;
|
$status = $this->request->param('status', 0) == 1 ? 1 : 0;
|
||||||
if (!$this->repository->merExists($merId, $id))
|
if (!$this->repository->merExists($merId, $id))
|
||||||
return app('json')->fail('数据不存在');
|
return app('json')->fail('数据不存在');
|
||||||
$this->repository->switchShow($id,$status, 'is_show',$merId);
|
$this->repository->switchShow($id, $status, 'is_show', $merId);
|
||||||
return app('json')->success('修改成功');
|
return app('json')->success('修改成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,9 +201,9 @@ class StoreProduct extends BaseController
|
|||||||
$data['extension_status'] = systemConfig('extension_status');
|
$data['extension_status'] = systemConfig('extension_status');
|
||||||
$data['integral_status'] = 0;
|
$data['integral_status'] = 0;
|
||||||
$data['integral_rate'] = 0;
|
$data['integral_rate'] = 0;
|
||||||
if(systemConfig('integral_status') && merchantConfig($merId,'mer_integral_status')) {
|
if (systemConfig('integral_status') && merchantConfig($merId, 'mer_integral_status')) {
|
||||||
$data['integral_status'] = 1;
|
$data['integral_status'] = 1;
|
||||||
$data['integral_rate'] = merchantConfig($merId,'mer_integral_rate');
|
$data['integral_rate'] = merchantConfig($merId, 'mer_integral_rate');
|
||||||
}
|
}
|
||||||
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
$merchant = app()->make(MerchantRepository::class)->get($merId);
|
||||||
$data['delivery_way'] = $merchant->delivery_way;
|
$data['delivery_way'] = $merchant->delivery_way;
|
||||||
@ -239,8 +246,14 @@ class StoreProduct extends BaseController
|
|||||||
public function stockIn()
|
public function stockIn()
|
||||||
{
|
{
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
$this->repository->stockIn($this->merId, $params);
|
if ($params['unique'] == '') {
|
||||||
return app('json')->success('入库成功');
|
return app('json')->fail('多规格编号不能为空');
|
||||||
|
}
|
||||||
|
$res = $this->repository->stockIn($this->merId, $params);
|
||||||
|
if ($res) {
|
||||||
|
return app('json')->success('入库成功');
|
||||||
|
} else {
|
||||||
|
return app('json')->fail('入库失败');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ class MerchantIntention extends BaseController
|
|||||||
'street' => $data['street_id'] ?? '',
|
'street' => $data['street_id'] ?? '',
|
||||||
'address' => $data['address'] ?? '',
|
'address' => $data['address'] ?? '',
|
||||||
'mer_intention_id' => $intention->mer_intention_id,
|
'mer_intention_id' => $intention->mer_intention_id,
|
||||||
'type_id'=>$data['mer_type_id']
|
'type_id'=>$data['mer_type_id']??''
|
||||||
];
|
];
|
||||||
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
||||||
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
||||||
@ -203,7 +203,9 @@ class MerchantIntention extends BaseController
|
|||||||
'bank_back' => $data['bank_back'] ?? '',
|
'bank_back' => $data['bank_back'] ?? '',
|
||||||
'cardno_front' => $data['cardno_front'] ?? '',
|
'cardno_front' => $data['cardno_front'] ?? '',
|
||||||
'cardno_back' => $data['cardno_back'] ?? '',
|
'cardno_back' => $data['cardno_back'] ?? '',
|
||||||
'mer_intention_id' => $intentionId
|
'mer_intention_id' => $intentionId,
|
||||||
|
'type_id'=>$merInfo['type_id']??''
|
||||||
|
|
||||||
];
|
];
|
||||||
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
||||||
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
||||||
@ -297,7 +299,9 @@ class MerchantIntention extends BaseController
|
|||||||
'area' => $data['area_id'] ?? '',
|
'area' => $data['area_id'] ?? '',
|
||||||
'street' => $data['street_id'] ?? '',
|
'street' => $data['street_id'] ?? '',
|
||||||
'address' => $data['address'] ?? '',
|
'address' => $data['address'] ?? '',
|
||||||
'mer_intention_id' => $id
|
'mer_intention_id' => $id,
|
||||||
|
'type_id'=>$data['mer_type_id']??''
|
||||||
|
|
||||||
];
|
];
|
||||||
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
$postUrl = env('TASK_WORKER_HOST_URL') . '/adminapi/company/createShopMerchant';
|
||||||
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
$res = $this->sendMerIntentionApply($sendData, $postUrl);
|
||||||
|
@ -75,6 +75,7 @@ return [
|
|||||||
'refund.after'=>[\app\listener\AfterRefund::class],
|
'refund.after'=>[\app\listener\AfterRefund::class],
|
||||||
'refund.deliver'=>[\app\listener\DeliverRefund::class],
|
'refund.deliver'=>[\app\listener\DeliverRefund::class],
|
||||||
'order.create'=>[\app\listener\OrderCreate::class],
|
'order.create'=>[\app\listener\OrderCreate::class],
|
||||||
|
'order.take'=>[\app\listener\OrderTake::class],
|
||||||
],
|
],
|
||||||
|
|
||||||
'subscribe' => [],
|
'subscribe' => [],
|
||||||
|
194
app/listener/OrderTake.php
Normal file
194
app/listener/OrderTake.php
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace app\listener;
|
||||||
|
|
||||||
|
use app\common\dao\store\order\StoreCartDao;
|
||||||
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
|
use app\common\model\system\merchant\Merchant;
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
|
use app\common\repositories\store\product\ProductRepository;
|
||||||
|
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||||
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
|
use crmeb\utils\DingTalk;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
use app\common\model\store\product\PurchaseRecord;
|
||||||
|
use app\common\model\system\Extend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收货后的逻辑
|
||||||
|
*/
|
||||||
|
class OrderTake
|
||||||
|
{
|
||||||
|
|
||||||
|
public $totalAmount;
|
||||||
|
public $event;
|
||||||
|
public $finance = [];
|
||||||
|
public $streetId;
|
||||||
|
public $financeSn;
|
||||||
|
public $index = 1;
|
||||||
|
public $remain;
|
||||||
|
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$order = $event['order'];
|
||||||
|
if ($order['source'] == 200 && $order['activity_type'] == 98) {
|
||||||
|
$product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select();
|
||||||
|
foreach ($product_arr as $k => $v) {
|
||||||
|
$this->import($v, $order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error($e->getMessage() . 'lien:' . $e->getLine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function import($product, $order)
|
||||||
|
{
|
||||||
|
$mer_id = Db::name('store_service')->where('uid', $order['uid'])->where('status', 1)->value('mer_id');
|
||||||
|
if ($mer_id == 0) {
|
||||||
|
Log::error('采购导入商品:商户不存在');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**原始商品数据 */
|
||||||
|
$find = Db::name('store_product')->where('product_id', $product['product_id'])->find();
|
||||||
|
if ($find) {
|
||||||
|
if (!in_array($find['product_type'], [0, 98])) {
|
||||||
|
Log::error('采购导入商品:不是普通商品');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**查询是否导入过该商品 */
|
||||||
|
$exist = Db::name('store_product')->where('source_product_id', $product['product_id'])->where('mer_id', $mer_id)->find();
|
||||||
|
if ($exist) {
|
||||||
|
$store_product_attr_value = Db::name('store_product_attr_value')->where('product_id', $exist['product_id'])->where('unique', $product['product_sku'])->find();
|
||||||
|
if ($store_product_attr_value) {
|
||||||
|
Log::error('采购导入商品:已经导入过该规格了');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**查询原始商品的规格 */
|
||||||
|
$attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']])
|
||||||
|
->where('unique', $product['product_sku'])
|
||||||
|
->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku')
|
||||||
|
->withAttr('detail', function ($value) {
|
||||||
|
return empty($value) ? [] : json_decode($value, true);
|
||||||
|
})
|
||||||
|
->find();
|
||||||
|
$find['attr'] = [];
|
||||||
|
$is_update=false;
|
||||||
|
if ($attrValue['detail']) {
|
||||||
|
foreach ($attrValue['detail'] as $kk => $vv) {
|
||||||
|
/**查询当前规格是否存在 */
|
||||||
|
$attr_values_find = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)
|
||||||
|
->find();
|
||||||
|
if ($attr_values_find) {
|
||||||
|
$attr_values= $attr_values_find['attr_values'];
|
||||||
|
$attr_values = explode('-!-', $attr_values);
|
||||||
|
if (!in_array($vv, $attr_values)) {
|
||||||
|
$attr_values[] = $vv;
|
||||||
|
$attr_values = implode('-!-', $attr_values);
|
||||||
|
Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
|
||||||
|
}
|
||||||
|
$is_update=true;
|
||||||
|
} else {
|
||||||
|
$attr_values = $vv;
|
||||||
|
|
||||||
|
Db::name('store_product_attr')->insert(
|
||||||
|
[
|
||||||
|
'product_id' => $exist['product_id'],
|
||||||
|
'attr_name' => $kk, 'attr_values' => $attr_values
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**规格新增还是更新 */
|
||||||
|
if($is_update==false){
|
||||||
|
$attrValue['stock'] = $product['refund_num'];
|
||||||
|
$unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0);
|
||||||
|
$attrValue['unique'] = $unique;
|
||||||
|
$attrValue['detail'] = json_encode($attrValue['detail']);
|
||||||
|
$attrValue['product_id'] = $exist['product_id'];
|
||||||
|
$attrValue['mer_id'] = $mer_id;
|
||||||
|
Db::name('store_product_attr_value')->insert($attrValue);
|
||||||
|
}else{
|
||||||
|
Db::name('store_product_attr_value')->where(['unique'=>$attr_values_find['unique'],'product_id',
|
||||||
|
$attr_values_find['product_id'],'mer_id'=>$mer_id,])->update(['stock'=>$product['refund_num']+$attr_values_find['stock']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]);
|
||||||
|
$data = [
|
||||||
|
'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'],
|
||||||
|
'product_id' => $exist['product_id'], 'number' => $product['refund_num'], 'order_unique' => $product['product_sku'],
|
||||||
|
'price' => $attrValue['price'], 'supplierMerId' => $order['mer_id'], 'mer_id' => $mer_id, 'unique' => $unique
|
||||||
|
];
|
||||||
|
$this->purchase_record($data);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']])
|
||||||
|
->where('unique', $product['product_sku'])
|
||||||
|
->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku')
|
||||||
|
->withAttr('detail', function ($value) {
|
||||||
|
return empty($value) ? [] : json_decode($value, true);
|
||||||
|
})
|
||||||
|
->find();
|
||||||
|
|
||||||
|
$find['attr'] = [];
|
||||||
|
if ($find['attrValue']['detail']) {
|
||||||
|
foreach ($find['attrValue']['detail'] as $kk => $vv) {
|
||||||
|
$find['attr'][] = ['attr_name' => $kk, 'detail' => $vv];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$find['attrValue']['stock'] = $product['refund_num'];
|
||||||
|
|
||||||
|
$find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content');
|
||||||
|
$find['is_show'] = 0;
|
||||||
|
$find['mer_id'] = $mer_id;
|
||||||
|
$find['temp_id'] = "";
|
||||||
|
$find['give_coupon_ids'] = [];
|
||||||
|
$find['params'] = [];
|
||||||
|
$find['extend'] = [];
|
||||||
|
$find['param_temp_id'] = [];
|
||||||
|
$find['mer_labels'] = [];
|
||||||
|
$find['delivery_way'] = [0 => "2"];
|
||||||
|
$find["guarantee_template_id"] = "";
|
||||||
|
$find['product_type'] = 0;
|
||||||
|
$find['mer_cate_id'] = [0 => 0];
|
||||||
|
$find['is_used'] = 1;
|
||||||
|
$find['status'] = 1;
|
||||||
|
$find['mer_status'] = 1;
|
||||||
|
$find['source_product_id'] = $product['product_id'];
|
||||||
|
$find['slider_image'] = explode(',', $find['slider_image']);
|
||||||
|
unset($find['product_id'], $find['create_time']);
|
||||||
|
$productId = app(ProductRepository::class)->create($find, 0);
|
||||||
|
$data = [
|
||||||
|
'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'],
|
||||||
|
'product_id' => $productId, 'number' => $product['refund_num'], 'order_unique' => $product['product_sku'],
|
||||||
|
'price' => $find['attrValue']['price'], 'supplierMerId' => $order['mer_id'], 'mer_id' => $mer_id
|
||||||
|
];
|
||||||
|
$this->purchase_record($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function purchase_record($data)
|
||||||
|
{
|
||||||
|
$model = new PurchaseRecord();
|
||||||
|
$data = [
|
||||||
|
'order_id' => $data['order_id'] ?? 0,
|
||||||
|
'order_product_id' => $data['order_product_id'] ?? 0,
|
||||||
|
'product_id' => $data['product_id'],
|
||||||
|
'number' => $data['number'],
|
||||||
|
'order_unique' => $data['order_unique'] ?? '',
|
||||||
|
'unique' => $data['unique'] ?? '',
|
||||||
|
'price' => $data['price'],
|
||||||
|
'mer_id' => $data['mer_id'],
|
||||||
|
'supplier_mer_id' => $data['supplierMerId'],
|
||||||
|
];
|
||||||
|
$model->save($data);
|
||||||
|
}
|
||||||
|
}
|
@ -705,6 +705,7 @@ Route::group('api/', function () {
|
|||||||
Route::get('supply_chain_product_price_count', '/SupplyChainProductPriceCount');
|
Route::get('supply_chain_product_price_count', '/SupplyChainProductPriceCount');
|
||||||
Route::get('supply_chain_street_product_price_count', '/SupplyChainStreetProductPriceCount');
|
Route::get('supply_chain_street_product_price_count', '/SupplyChainStreetProductPriceCount');
|
||||||
Route::get('supply_chain_breeding_street_product_count', '/SupplyChainBreedingStreetProductCount');
|
Route::get('supply_chain_breeding_street_product_count', '/SupplyChainBreedingStreetProductCount');
|
||||||
|
Route::get('supply_chain_village_breeding_price_count', '/SupplyChainVillageBreedingPriceCount');
|
||||||
Route::get('store_order_user_trade_amount', '/StoreOrderUserTradeAmount');
|
Route::get('store_order_user_trade_amount', '/StoreOrderUserTradeAmount');
|
||||||
})->prefix('api.Statistics');
|
})->prefix('api.Statistics');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user