| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\workerapi\logic\shops;
- use app\common\model\shops\ShopCart;
- use app\common\model\shops\ShopGoods;
- use app\common\logic\BaseLogic;
- use app\common\model\shops\ShopGoodSpecsInventory;
- use think\db\Query;
- use think\facade\Db;
- /**
- * ShopGoods逻辑
- * Class ShopGoodsLogic
- * @package app\adminapi\logic\shops
- */
- class ShopCartLogic extends BaseLogic
- {
- /**
- * @notes 获取详情
- * @param $params
- * @return array
- * @author likeadmin
- * @date 2024/08/04 11:07
- */
- public static function add($params)
- {
- Db::startTrans();
- try{
- Db::commit();
- $goodsModel = ShopGoods::findOrEmpty($params['shop_goods_id']);
- if($goodsModel->isEmpty()){
- throw new \Exception('商品不存在');
- }
- $goodSpecInventoryModel = ShopGoodSpecsInventory::where(['id'=>$params['goods_specs_inventory_id'],'shop_goods_id'=>$params['shop_goods_id']])->findOrEmpty();
- if($goodSpecInventoryModel->isEmpty()){
- throw new \Exception('规格不存在');
- }
- ShopCart::create([
- 'shop_goods_id' => $params['shop_goods_id'],
- 'goods_specs_inventory_id' => $params['goods_specs_inventory_id'],
- 'number' => $params['number'],
- 'worker_id' => $params['worker_id'],
- ]);
- Db::commit();
- return true;
- }catch(\Exception $e){
- Db::rollback();
- self::setError($e->getMessage());
- return false;
- }
- }
- public static function delete($params){
- try{
- ShopCart::whereIn('id',$params['ids'])->where('worker_id',$params['worker_id'])->delete();
- Db::commit();
- return true;
- }catch (\Exception $e){
- Db::rollback();
- self::setError($e->getMessage());
- return false;
- }
- }
- }
|