This commit is contained in:
yaooo 2023-11-20 16:16:09 +08:00
commit 9513aceba0
9 changed files with 536 additions and 279 deletions

View File

@ -314,7 +314,7 @@ class ProductRepository extends BaseRepository
$data['svip_price_type'] = $res['svip_price_type'];
$settleParams = $this->setAttrValue($data, $id, 0, 1, $merId);
$settleParams['cate'] = $this->setMerCate($data['mer_cate_id'], $id, $merId);
// $settleParams['attr'] = $this->setAttr($data['attr'], $id);
$settleParams['attr'] = $this->setAttr($data['attr'], $id);
$data['price'] = $settleParams['data']['price'];
unset($data['attrValue'], $data['attr'], $data['mer_cate_id']);
$ret = Spu::getInstance()->where('product_id', $id)->whereIn('product_type', [0, 98, 99])->find();
@ -378,7 +378,7 @@ class ProductRepository extends BaseRepository
$res = $this->dao->update($id, $data);
if (isset($data['status']) && $data['status'] !== 1) {
$message = '您有1个新的'. ($productType ? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) . '待审核';
$message = '您有1个新的' . $productType . '商品待审核'; //? '秒杀商品' : ($data['is_gift_bag'] ? '礼包商品' :'商品')) .
$type = $productType ? 'new_seckill' : ($data['is_gift_bag'] ? 'new_bag' : 'new_product');
SwooleTaskService::admin('notice', [
'type' => $type,
@ -454,7 +454,6 @@ class ProductRepository extends BaseRepository
$integral_rate = $data['integral_rate'];
if ($data['integral_rate'] < 0) $integral_rate = -1;
if ($data['integral_rate'] > 100) $integral_rate = 100;
}
$result = [
'store_name' => $data['store_name'],
@ -668,7 +667,8 @@ class ProductRepository extends BaseRepository
*/
public function getAdminOneProduct(int $id, ?int $activeId, $conType = 0)
{
$with = ['attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive',
$with = [
'attr', 'attrValue', 'oldAttrValue', 'merCateId.category', 'storeCategory', 'brand', 'temp', 'seckillActive',
'content',
'merchant' => function ($query) {
$query->field('mer_id,mer_avatar,mer_name,is_trader');
@ -772,15 +772,19 @@ class ProductRepository extends BaseRepository
$content .= '<img src=' . $v . '></br>';
}
}
}
} else {
$content = $arr;
}
}
unset($data['content']);
$data['content'] = $content;
// $attr = $this->detailAttr($data['attr']);
$attrValue =$data['attrValue'];
$sku = $this->detailAttrValue($attrValue, null, $data['product_type'], null);
$data['sku'] = $sku;
return $data;
}
@ -1266,7 +1270,6 @@ class ProductRepository extends BaseRepository
// $img =$img. '<img src="'.$v.'"/>';
// }
$res['content']['content'] = ['image' => $image];
} elseif (is_object($content)) {
$image = $content->image ?? [];
// $img='<p>';
@ -1274,8 +1277,7 @@ class ProductRepository extends BaseRepository
// $img =$img. '<img src="'.$v.'"/>';
// }
$res['content']['content'] = ['image' => $image];
}
else{
} else {
if (is_Array($content)) {
$res['content']['content'] = ['image' => $content];
} else {
@ -1695,7 +1697,6 @@ class ProductRepository extends BaseRepository
app()->make(SpuRepository::class)->changeStatus($id, $product->product_type);
event('product.sell', ['product_id' => [$id]]);
$this->switchShow($id, $status, 'is_used', 0);
}
/**
@ -1724,7 +1725,6 @@ class ProductRepository extends BaseRepository
if ($data['status'] == 1) {
$this->switchShow($product['product_id'], 1, 'is_used', 0);
}
}
$this->dao->updates($id, $data);
Queue(ChangeSpuStatusJob::class, ['id' => $id, 'product_type' => $product_type]);
@ -2086,7 +2086,8 @@ class ProductRepository extends BaseRepository
$query->field('guarantee_id,guarantee_name,guarantee_info');
}
],
])->find();
]
)->find();
return $data ?? [];
}
@ -2218,8 +2219,7 @@ class ProductRepository extends BaseRepository
*/
public function getPreview(array $data)
{
switch($data['product_type'])
{
switch ($data['product_type']) {
case 0:
case 98:
case 99:
@ -2344,29 +2344,30 @@ class ProductRepository extends BaseRepository
$model = new PurchaseRecord();
$stockIn = $params['number'] ?? 0;
$price = $params['price'] ?? 0;
if($stockIn==0){
$stockIn=1;
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])
->where('product_sku', $params['order_unique'])->find();
$stockIn=$orderProduct['product_num'];
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
}
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
//有商品无规格或者无商品无规格,导入商品和规格
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
if (!empty($product)) {
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->find();
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('unique', $params['unique'])->find();
if (!empty($params['order_id'])) {
//采购、委托订单导入
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find();
if (empty($orderProduct)) {
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
if (!$unique) {
throw new \Exception('商品规格导入出错', 500);
throw new ValidateException('商品规格导入出错');
}
}
if( $orderProduct->is_imported == 1){
if ($orderProduct->is_imported == 0) {
ProductAttrValue::where('mer_id', $merId)
->where('product_id', $product['product_id'])
->update(['stock'=>$attrValue->stock + $stockIn]);
$attrValue->stock=$attrValue->stock + $stockIn;
$product->stock = $stockIn + $product->stock;
$data = [
'order_id' => $params['order_id'] ?? 0,
'order_product_id' => $params['order_product_id'] ?? 0,
@ -2379,10 +2380,15 @@ class ProductRepository extends BaseRepository
'supplier_mer_id' => $orderMerId ?? 0,
];
if (!$model->save($data)) {
throw new \Exception('入库失败', 500);
throw new ValidateException('入库失败');
}
$orderProduct->save(['is_imported' => 1]);
$attrValue->save();
$product->save();
Db::commit();
return true;
}else{
throw new ValidateException('该商品已导入过');
}
$stockIn = $orderProduct['product_num'] ?? 0;
$price = $orderProduct['product_price'] ?? 0;
@ -2396,7 +2402,6 @@ class ProductRepository extends BaseRepository
$productId = $this->import($params['order_product_id'], request()->userInfo());
$product = $this->get($productId);
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find();
}
} else {
//有商品有规格
@ -2404,16 +2409,13 @@ class ProductRepository extends BaseRepository
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find();
}
if (!$product || !$attrValue) {
throw new DataNotFoundException('商品或规格不存在');
}
if ($stockIn <= 0) {
throw new ValidateException('入库数量不能小于等于0');
throw new ValidateException('商品或规格不存在');
}
$attrValue->stock = $attrValue->stock + $stockIn;
$attrValue->save();
$product->stock = $stockIn + $product->stock;
if (!$product->save()) {
throw new \Exception('商品库存保存失败', 500);
throw new ValidateException('商品库存保存失败');
}
$data = [
'order_id' => $params['order_id'] ?? 0,
@ -2427,15 +2429,15 @@ class ProductRepository extends BaseRepository
'supplier_mer_id' => $supplierMerId,
];
if (!$model->save($data)) {
throw new \Exception('入库失败', 500);
throw new ValidateException('入库失败');
}
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
throw new \Exception('订单商品更新出错', 500);
throw new ValidateException('订单商品更新出错');
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
throw new \Exception($e->getMessage(), $e->getCode());
throw new ValidateException($e->getMessage(), $e->getCode());
}
return true;
}
@ -2546,5 +2548,4 @@ class ProductRepository extends BaseRepository
);
return compact('count', 'list');
}
}

View File

@ -90,7 +90,7 @@ class SpuRepository extends BaseRepository
'keyword' => $param['keyword'] ?? '',
'image' => $param['image'],
'price' => $param['price'],
'status' => 0,
'status' => $param['status']??0,
'rank' => $param['rank'] ?? 0,
'temp_id' => $param['temp_id'],
'sort' => $param['sort'] ?? 0,

View File

@ -244,7 +244,14 @@ class Merchant extends BaseController
if (!$this->repository->exists($id))
return app('json')->fail('数据不存在');
$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);
if(!$adminInfo){
$pwd =password_hash(rand(100000,999999), PASSWORD_BCRYPT);

View File

@ -262,7 +262,8 @@ class Statistics extends BaseController
if (!isset($parmas['phone']) || $parmas['phone'] == '') {
return app('json')->fail('phone:格式错误');
}
$user_id= Db::name('user')->where('account',$parmas['phone'])->value('uid');
$account[] = ['account', 'in', explode(',', $parmas['phone'])];
$user_id = Db::name('user')->where($account)->value('uid');
if (!$user_id) {
return app('json')->fail('查询的手机号用户不存在');
}
@ -275,4 +276,39 @@ class Statistics extends BaseController
->sum('pay_price');
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]);
}
}

View File

@ -90,13 +90,18 @@ class StoreProduct extends BaseController
$data['mer_status'] = ($merchant['is_del'] || !$merchant['mer_state'] || !$merchant['status']) ? 0 : 1;
$data['rate'] = 3;
$typeCode = Db::name('merchant_type')->where('mer_type_id', $merchant['type_id'])->value('type_code');
$product_type = 0; //普通商品
if ($merchant['type_id'] == 12) {
if ($typeCode == Merchant::TypeCode['TypeSupplyChain']) {
$product_type = 98; //供应链
}else{
$product_type=0;//普通商品
}
}
$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');
// if (!empty($unique) && $stockNum > 0) {
// $this->repository->stockIn($merId, [
@ -105,8 +110,6 @@ class StoreProduct extends BaseController
// 'number' => $stockNum,
// ]);
}
return app('json')->success('添加成功');
}
/**
* TODO 编辑
@ -135,8 +138,12 @@ class StoreProduct extends BaseController
$data['mer_id'] = $merId;
$typeSupplyChainId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeSupplyChain'])->value('mer_type_id');
$productType = $merchant->type_id == $typeSupplyChainId ? 98 : 0;
$this->repository->edit($id, $data, $merId, $productType, 1);
$product=$this->repository->edit($id, $data, $merId, $productType, 1);
if ($product) {
return app('json')->success('编辑成功');
} else {
return app('json')->fail('编辑失败');
}
}
/**
@ -239,8 +246,14 @@ class StoreProduct extends BaseController
public function stockIn()
{
$params = $this->request->param();
$this->repository->stockIn($this->merId, $params);
if ($params['unique'] == '') {
return app('json')->fail('多规格编号不能为空');
}
$res = $this->repository->stockIn($this->merId, $params);
if ($res) {
return app('json')->success('入库成功');
} else {
return app('json')->fail('入库失败');
}
}
}

View File

@ -93,7 +93,7 @@ class MerchantIntention extends BaseController
'street' => $data['street_id'] ?? '',
'address' => $data['address'] ?? '',
'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';
$res = $this->sendMerIntentionApply($sendData, $postUrl);
@ -203,7 +203,9 @@ class MerchantIntention extends BaseController
'bank_back' => $data['bank_back'] ?? '',
'cardno_front' => $data['cardno_front'] ?? '',
'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';
$res = $this->sendMerIntentionApply($sendData, $postUrl);
@ -297,7 +299,9 @@ class MerchantIntention extends BaseController
'area' => $data['area_id'] ?? '',
'street' => $data['street_id'] ?? '',
'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';
$res = $this->sendMerIntentionApply($sendData, $postUrl);

View File

@ -75,6 +75,7 @@ return [
'refund.after'=>[\app\listener\AfterRefund::class],
'refund.deliver'=>[\app\listener\DeliverRefund::class],
'order.create'=>[\app\listener\OrderCreate::class],
'order.take'=>[\app\listener\OrderTake::class],
],
'subscribe' => [],

194
app/listener/OrderTake.php Normal file
View 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);
}
}

View File

@ -705,6 +705,7 @@ Route::group('api/', function () {
Route::get('supply_chain_product_price_count', '/SupplyChainProductPriceCount');
Route::get('supply_chain_street_product_price_count', '/SupplyChainStreetProductPriceCount');
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');
})->prefix('api.Statistics');