count(); $lists = LiveGoods::where($where) ->order(['id' => 'desc']) ->page($params['page'], $params['limit']) ->append(['audit_status_text', 'price_text', 'goods_stock']) ->select()->toArray(); foreach ($lists as &$item) { $item['cover_img'] = UrlServer::getFileUrl($item['cover_img']); } return ['count' => $count, 'lists' => $lists]; } /** * @notes 添加直播商品 * @param array $params * @return bool * @throws \GuzzleHttp\Exception\GuzzleException * @author 段誉 * @date 2023/2/15 18:26 */ public static function add(array $params) { try { $price = 0; $price2 = 0; switch ($params['price_type']) { case LiveGoodsEnum::PRICE_ONE: $price = $params['price']; break; case LiveGoodsEnum::PRICE_RANGE: $price = $params['section_price_start']; $price2 = $params['section_price_end']; break; case LiveGoodsEnum::PRICE_DISCOUNT: $price = $params['discount_price_start']; $price2 = $params['discount_price_end']; break; } $data = [ 'shop_id' => $params['shop_id'], 'source_type' => LiveGoodsEnum::SOURCE_TYPE_SELF, 'name' => $params['name'], 'price_type' => $params['price_type'], 'price' => $price, 'price2' => $price2, 'url' => $params['url'], 'cover_img_url' => FileServer::wechatLiveMaterial($params['cover_img']), 'cover_img' => UrlServer::setFileUrl($params['cover_img']), ]; if (isset($params['source_type']) && $params['source_type'] == LiveGoodsEnum::SOURCE_TYPE_GOODS) { $data['source_id'] = $params['source_id']; $data['source_type'] = LiveGoodsEnum::SOURCE_TYPE_GOODS; } LiveGoods::create($data); return true; } catch (\Exception $e) { self::$error = $e->getMessage(); return false; } } /** * @notes 直播商品详情 * @param $id * @return array * @author 段誉 * @date 2023/2/16 10:42 */ public static function detail($params) { $detail = LiveGoods::where(['id' => $params['id'], 'shop_id' => $params['shop_id']]) ->append(['price_type_text', 'price_tips', 'source_type_text', 'audit_status_text']) ->findOrEmpty()->toArray(); $detail['cover_img'] = UrlServer::getFileUrl($detail['cover_img']); return $detail; } /** * @notes 删除直播商品 * @param array $params * @return bool|string * @author 段誉 * @date 2023/2/16 10:37 */ public static function del(array $params) { Db::startTrans(); try { $goods = LiveGoods::findOrEmpty($params['id'])->toArray(); if ($goods['sys_audit_status'] < LiveGoodsEnum::SYS_AUDIT_STATUS_WAIT_WECHAT) { throw new \Exception('当前商品暂不可删除'); } $where = [ 'id' => $params['id'], 'shop_id' => $params['shop_id'] ]; LiveGoods::where($where)->update([ 'del' => 1, 'update_time' => time() ]); // 删除微信商品库 if (!empty($goods['wx_goods_id'])) { (new WxMnpLiveServer())->handle('delGoods', $goods['wx_goods_id']); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); return $e->getMessage(); } } }