新增委托商品接口
This commit is contained in:
parent
f84bc9e7f1
commit
16909c252d
@ -19,6 +19,7 @@ use app\common\model\store\order\StoreCart;
|
|||||||
use app\common\model\store\product\ProductAttrValue;
|
use app\common\model\store\product\ProductAttrValue;
|
||||||
use app\common\model\store\product\PurchaseRecord;
|
use app\common\model\store\product\PurchaseRecord;
|
||||||
use app\common\model\store\Resale;
|
use app\common\model\store\Resale;
|
||||||
|
use app\common\model\store\Entrust;
|
||||||
use app\common\repositories\BaseRepository;
|
use app\common\repositories\BaseRepository;
|
||||||
use app\common\repositories\store\order\StoreCartRepository;
|
use app\common\repositories\store\order\StoreCartRepository;
|
||||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||||
@ -375,6 +376,9 @@ class CommunityRepository extends BaseRepository
|
|||||||
if ($data['product_info'] && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
if ($data['product_info'] && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||||
$this->resale($community->community_id, $data['product_info'], $data['resale_type'] ?? 0);
|
$this->resale($community->community_id, $data['product_info'], $data['resale_type'] ?? 0);
|
||||||
}
|
}
|
||||||
|
if ($data['product_info'] && $data['is_type'] == self::COMMUNITY_TYPE_ENTRUST) {
|
||||||
|
$this->entrust($community->community_id, $data['product_info'], $data['entrust_mer_id'] ?? 0, $data['entrust_day'] ?? 0);
|
||||||
|
}
|
||||||
event('community.create',compact('community'));
|
event('community.create',compact('community'));
|
||||||
return $community->community_id;
|
return $community->community_id;
|
||||||
});
|
});
|
||||||
@ -406,6 +410,9 @@ class CommunityRepository extends BaseRepository
|
|||||||
if ($productInfo && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
if ($productInfo && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||||
$this->resale($id, $productInfo, $data['resale_type'] ?? 0);
|
$this->resale($id, $productInfo, $data['resale_type'] ?? 0);
|
||||||
}
|
}
|
||||||
|
if ($productInfo && $data['is_type'] == self::COMMUNITY_TYPE_ENTRUST) {
|
||||||
|
$this->entrust($community->community_id, $data['product_info'], $data['entrust_mer_id'] ?? 0, $data['entrust_day'] ?? 0);
|
||||||
|
}
|
||||||
event('community.update.before',compact('id','community'));
|
event('community.update.before',compact('id','community'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -644,6 +651,61 @@ class CommunityRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 委托贴
|
||||||
|
* @param $id
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function entrust($id, array $data, $entrustMerId, $entrustDay)
|
||||||
|
{
|
||||||
|
|
||||||
|
$insert = [];
|
||||||
|
foreach ($data as $value) {
|
||||||
|
if (isset($value['id'])) {
|
||||||
|
$entrustInfo = Entrust::find($value['id']);
|
||||||
|
unset($value['product_attr_unique']);
|
||||||
|
$entrustInfo->update($value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
|
||||||
|
$totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
|
||||||
|
$totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
|
||||||
|
if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
|
||||||
|
throw new ValidateException('进货记录不存在或已售罄');
|
||||||
|
}
|
||||||
|
if (($totalNumber - $totalSalesVolume) < $value['number']) {
|
||||||
|
throw new ValidateException('库存不足');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value) {
|
||||||
|
$insert[] = [
|
||||||
|
'community_id' => $id,
|
||||||
|
'purchase_record_id' => $purchaseRecord['id'],
|
||||||
|
'product_id' => $purchaseRecord['product_id'],
|
||||||
|
'product_attr_unique' => $purchaseRecord['unique'],
|
||||||
|
'mer_id' => $purchaseRecord['mer_id'],
|
||||||
|
'entrust_mer_id' => $entrustMerId,
|
||||||
|
'entrust_day' => $entrustDay,
|
||||||
|
'number' => $value['number'],
|
||||||
|
'price' => $value['price'],
|
||||||
|
'update_time' => date('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$purchaseRecord->product->stock -= $value['number'];
|
||||||
|
$purchaseRecord->product->save();
|
||||||
|
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
|
||||||
|
$attrValue->stock -= $value['number'];
|
||||||
|
$attrValue->save();
|
||||||
|
}
|
||||||
|
if ($insert) {
|
||||||
|
Entrust::getInstance()->insertAll($insert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转售加入购物车
|
* 转售加入购物车
|
||||||
* @param $uid
|
* @param $uid
|
||||||
|
@ -613,4 +613,17 @@ class Community extends BaseController
|
|||||||
$res = $this->repository->create($data);
|
$res = $this->repository->create($data);
|
||||||
return app('json')->success(['community_id' => $res]);
|
return app('json')->success(['community_id' => $res]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布委托商品
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function entrust()
|
||||||
|
{
|
||||||
|
$data = $this->checkParams();
|
||||||
|
$this->checkUserAuth();
|
||||||
|
$data['uid'] = $this->request->uid();
|
||||||
|
$res = $this->repository->create($data);
|
||||||
|
return app('json')->success(['community_id' => $res]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,6 +372,8 @@ Route::group('api/', function () {
|
|||||||
Route::post('resale/delete/:id', 'Community/deleteResale');
|
Route::post('resale/delete/:id', 'Community/deleteResale');
|
||||||
Route::post('resale/check/:id', 'Community/checkResale');
|
Route::post('resale/check/:id', 'Community/checkResale');
|
||||||
|
|
||||||
|
Route::post('/entrust', 'Community/entrust');
|
||||||
|
|
||||||
})->prefix('api.community.');
|
})->prefix('api.community.');
|
||||||
|
|
||||||
Route::group('svip', function () {
|
Route::group('svip', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user