更新委托商品审核

This commit is contained in:
yaooo 2023-09-07 11:00:21 +08:00
parent d1aa9ec280
commit 0d50ea313d
4 changed files with 65 additions and 3 deletions

View File

@ -29,7 +29,8 @@ class StoreCartDao extends BaseDao
const SOURCE_STORE_CLOUD = 101; //店铺内云商品
const SOURCE_CLOUD = 102; //云仓内店铺商品
const SOURCE_COMMUNITY_RESALE = 201; //转售商品
const SOURCE_COMMUNITY_RESALE = 201; //转售商品
const SOURCE_COMMUNITY_ENTRUST = 202; //委托商品
protected function getModel(): string
{

View File

@ -16,6 +16,7 @@ namespace app\common\model\community;
use app\common\model\BaseModel;
use app\common\model\store\product\Spu;
use app\common\model\store\Resale;
use app\common\model\store\Entrust;
use app\common\model\system\Relevance;
use app\common\model\user\User;
use app\common\repositories\system\RelevanceRepository;
@ -177,4 +178,9 @@ class Community extends BaseModel
return $this->hasMany(Resale::class, 'community_id','community_id');
}
public function entrust()
{
return $this->hasMany(Entrust::class, 'community_id','community_id');
}
}

View File

@ -768,6 +768,55 @@ class CommunityRepository extends BaseRepository
}
}
/**
* 委托商品加入购物车
* @param $uid
* @param $id
* @return array
*/
public function addEntrustCart($uid, $id)
{
$where = [
$this->dao->getPk() => $id,
'is_del' => 0
];
$community = $this->dao->getSearch($where)->with('entrust')->find()->toArray();
if (empty($community) || $community['is_sale'] != 0) {
throw new ValidateException('委托数据不存在或已售出');
}
if (empty($community['entrust'])) {
throw new ValidateException('委托数据不存在');
}
StoreCart::startTrans();
try {
/** @var StoreCartRepository $cartRepo */
$cartRepo = app()->make(StoreCartRepository::class);
$cartIds = [];
foreach ($community['entrust'] as $item) {
$data = [
'uid' => $uid,
'mer_id' => $item['mer_id'],
'product_type' => 99,
'product_id' => $item['product_id'],
'product_attr_unique' => $item['product_attr_unique'],
'cart_num' => $item['number'],
'source' => StoreCartDao::SOURCE_COMMUNITY_ENTRUST,
'source_id' => $community['community_id'],
];
$cart = $cartRepo->create($data);
$cartIds[] = $cart['cart_id'];
}
if (empty($cartIds)) {
throw new ValidateException('加入购物车出错');
}
StoreCart::commit();
return $cartIds;
} catch (\Exception $exception) {
StoreCart::rollback();
throw new ValidateException('下单出错');
}
}
public function saleOrCancel($id, $status = 1)
{
$where = [

View File

@ -548,7 +548,10 @@ class Community extends BaseController
return app('json')->fail('请设置审核状态');
}
if ($status == 1) {
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]);
$res = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]);
if (!$res) {
return app('json')->fail('审核失败');
}
}
if ($status == 2) {
Db::startTrans();
@ -654,7 +657,10 @@ class Community extends BaseController
}
// 同意
if ($status == 1) {
Db::name('community')->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]);
$res = Db::name('community')->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]);
if (!$res) {
return app('json')->fail('审核失败');
}
}
// 拒绝
if ($status == 2) {