getProductAttrs($val['key'],$data); if (!empty($keyVal)) { $product_attrs[$val['key']] = $keyVal; } } foreach ($valMap['sku_attrs'] as $val) { $keyVal = $this->getProductAttrs($val['key'],$data); if (!empty($keyVal)) { $sku_attrs[$val['key']] = $keyVal; } } $param = [ "account_id" => $store['store_id'], // 商家id "product" => [ "account_name" => $store['poi_name'], // 商家名 "biz_line" => 5, // 业务线 固定 5 小程序 "category_id" => $data['category_id']??0, // 品类id "product_name" => $data['product_name'], // 商品名 "product_type" => $data['product_type'], // 商品类型 "attr_key_value_map" => $product_attrs, "out_id" => $data['product_id'], // 第三方id "out_url" => json_encode([ "app_id" => sConf("wechat.mini_appid"), "params" => json_encode(['goods' => $data['product_id']]), "path" => "pages/goods/detail" ]), // 第三方跳转链接,小程序商品必填 "pois" => [ [ "poi_id" => $store['poi_id'], // 门店POI ] ], "sold_end_time" => strtotime($data['sold_start_times'][1]), // 售卖结束时间 "sold_start_time" => strtotime($data['sold_start_times'][0]), // 售卖开始时间 "spu_id" => (string)$data['spu_id'], // spuid "account_id" => $store['store_id'], // 商家id ] ]; if (empty($sku)) { // 单sku $param['sku'] = [ "attr_key_value_map" => $sku_attrs, "actual_amount" => $data['price'], // 售价 实际支付价格 "sku_name" => $data['product_name'], // sku名 "origin_amount" => $data['line_price'], "status" => 1, "stock" => [ "limit_type" => $data['limit_use_rule'], // 库存上限类型,为2时stock_qty和avail_qty字段无意义 1 有限库存 2 无限库存 "avail_qty" => $data['use_num_per_consume']??0, // 可用库存,limit_type=2时无意义,始终保证stock_qty=avail_qty+frozen_qty+sold_qty ] ]; } else { // 多sku } return $this->curlPostApi("goodlife/v1/goods/product/save/",$param); } /** * 参数处理 * @param string $key * @param array $data * @return string */ protected function getProductAttrs(string $key = "",array $data = []): string { switch ($key) { case "trade_url": // 小程序提单页跳转 return json_encode([ "app_id" => sConf("wechat.mini_appid"), "params" => json_encode(['goods' => $data['product_id']]), "path" => "pages/goods/detail" ]); break; case "commodity": // 商品搭配 $specs = json_decode($data['specs'],true); $commodity = []; foreach ($specs as $key=>$val) { $commodity[$key] = [ "group_name" => $val['name'], "total_count" => count($val['list']), "option_count" => $val['num']==0?count($val['list']):$val['num'] ]; foreach ($val['list'] as $sKey=>$sub) { $commodity[$key]['item_list'][$sKey] = [ "name" => $sub['name'], "price" => $sub['price'] * 100, "count" => 1, "unit" => "份" ]; } } $return = json_encode($commodity); break; case "customer_reserved_info": if ($data['customer_reserved_info'] == 1) { // 不需要留资 $return = json_encode([ "allow" => false ]); } else { $return = json_encode([ "allow" => true, "allow_tel" => true, "require_for_tel" => true ]); } break; case "appointment": // 预约规则 if ($data['booking_type'] == 1) { // 无需预约 $return = json_encode([ "need_appointment" => false ]); } else { if ($data['booking_unit'] == 1) { $return = json_encode([ "need_appointment" => true, "ahead_day_num" => $data['booking_date'] ]); } else { $return = json_encode([ "need_appointment" => true, "ahead_hour_num" => $data['booking_date'] ]); } } break; case "EntryType": // 入口类型 1:H5 2:小程序 3:抖音 4:lynx $return = "2"; break; case "market_price": // 划线价格 $return = (string)$data['line_price']; break; case "can_no_use_date": // 不可使用日期 if ($data['can_no_use_date'] == 1) { $return = json_encode(["enable" => false]); } else { // 指定日期 $noUse = ["enable" => true]; if ($data['can_no_use_week']) { // 每周几不可用 $noUse['days_of_week'] = $data['no_use_weeks']; } if ($data['can_no_use_holiday']) { // 节假日不可用 $noUse['holidays'] = $data['no_use_weeks']; } if ($data['can_no_use_day']) { // 指定某天不可用 $noUse['date_list'] = $data['no_use_days']; } $return = json_encode($noUse); } break; case "image_list": // 封面图 图片比例:375:280 $image_list = json_decode($data['image_list'],true); $return = json_encode([ [ "url" => $image_list[0]['url'] ] ]); break; case "limit_use_rule": // 限制使用规则 if ($data['rec_person_type']==1) { $return = json_encode(["is_limit_use" => false]); } else { $return = json_encode(['is_limit_use' => true, 'use_num_per_consume' => $data['rec_person_num_max']??0]); } break; case "show_channel": $return = (string) $data['show_channel']; break; case "use_date": // 使用日期 券码的可以核销日期,履约核销强依赖 if ($data['use_date_type'] == 1) { // 指定天数 $return = json_encode([ "use_date_type" => 2, "day_duration" => $data['day_duration'] ]); } else { // 指定日期 $return = json_encode([ "use_date_type" => 1, "use_start_date" => $data['use_times'][0], "use_end_date" => $data['use_times'][0] ]); } break; case "use_time": // 使用时间 用户可以消费的时间 $return = json_encode([ "use_time_type" => 1 ]); break; case "Notification": // 使用规则 $return = $data['notification']; break; case "RefundPolicy": // 退款政策 1-允许退款 2-不可退款 3-有条件退 $return = "1"; break; case "refund_need_merchant_confirm": // 退款是否需商家审核 $return = "true"; break; case "code_source_type": // 券码生成方式 "1-抖音码 2-三方码 3-预导码 $return = (string)$data['code_source_type']; break; case "settle_type": // 收款方式 1-总店结算 2-分店结算 $return = (string)$data['code_source_type']; break; case "limit_rule": // 限制购买 if ($data['limit_rule_type'] == 2) { $return = json_encode(['is_limit' => true,"total_buy_num" => $data['limit_rule']]); } else { $return = json_encode(['is_limit' => false]); } break; case "auto_renew": $return = $data['auto_renew']==1?'true':'false'; break; default: $return = ""; break; } return $return; } /** * 获取来客绑定的所有门店 * 一页最多50条 */ public function getStoreData(string $account,int $page = 1,int $size = 50): array { $data = [ "account_id" => $account, "page" => $page, "size" => $size ]; return $this->curlGetApi("goodlife/v1/shop/poi/query/",$data); } /** * 获取来客绑定的所有分类 */ public function getStoreCategoryData(string $account): array { $data = [ "account_id" => $account, "query_category_type" => 1 ]; return $this->curlGetApi("goodlife/v1/goods/category/get/",$data); } /** * 查下商品模板 */ public function getStoreCategoryTemplate(string $category_id,int $product_type = 1): array { $data = compact("category_id","product_type"); return $this->curlGetApi("goodlife/v1/goods/template/get/",$data); } }