$params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'], 'is_pay' => 0 ])->field('id')->find(); if ($check) { Cart::where('id', $check['id'])->inc('cart_num', $params['cart_num']) ->update(); $cart['id'] = $check['id']; } else { $cart = Cart::create([ 'uid' => $params['uid'], 'type' => $params['type'] ?? '', 'product_id' => $params['product_id'], 'store_id' => $params['store_id'] ?? 0, 'staff_id' => $params['staff_id'] ?? 0, 'product_attr_unique' => '', 'cart_num' => $params['cart_num'], 'is_new' => $params['is_new'] ?? 0, ]); } StoreProductLog::create([ 'type' => 'cart', 'uid' => $params['uid'], 'cart_id' => $cart['id'], 'store_id' => $params['store_id'] ?? 0, 'visit_num' => 1, 'product_id' => $params['product_id'], 'cart_num' => $params['cart_num'], ]); Db::commit(); return $cart; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑购物车表 * @param array $params * @return bool * @author likeadmin * @date 2024/04/24 10:37 */ public static function edit(array $params, $type = 'inc'): bool { Db::startTrans(); try { Cart::where([ 'uid' => $params['uid'], 'store_id' => $params['store_id'], 'product_id' => $params['product_id'] ]) ->update(['cart_num' => $params['cart_num']]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除购物车表 * @param array $params * @return bool * @author likeadmin * @date 2024/04/24 10:37 */ public static function delete(array $params): bool { return Cart::destroy($params['id']); } /** * @notes 获取购物车表详情 * @param $params * @return array * @author likeadmin * @date 2024/04/24 10:37 */ public static function detail($params): array { return Cart::findOrEmpty($params['id'])->toArray(); } }