更新
This commit is contained in:
parent
be635affa2
commit
8faa050a78
@ -83,9 +83,8 @@ class ProductLibrary extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
public function caiji()
|
||||
public function caiji($code='')
|
||||
{
|
||||
$code = $this->request->param('code');
|
||||
$url_host=$this->request->host();
|
||||
if ($code=='') {
|
||||
return app('json')->fail('编码不能为空');
|
||||
@ -100,6 +99,7 @@ class ProductLibrary extends BaseController
|
||||
$bodys = "";
|
||||
$url = $host . $path . "?" . $querys;
|
||||
|
||||
try{
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
@ -139,31 +139,31 @@ class ProductLibrary extends BaseController
|
||||
$data['image']= $url_host.'/uploads/img/'.date('Y-m-d').'/'. $filename;
|
||||
file_put_contents($destination, file_get_contents($param['img']));
|
||||
}else{
|
||||
$data['image'] = '';
|
||||
$data['image'] = 'https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230130/00ebcfdf75684f5494c0193075055d1.png';
|
||||
}
|
||||
$res = Db::name('product_library')->insert($data);
|
||||
if($res){
|
||||
return app('json')->success('添加成功');
|
||||
}else{
|
||||
return app('json')->fail('添加失败');
|
||||
throw new \think\exception\ValidateException('添加失败');
|
||||
}
|
||||
} else {
|
||||
if ($httpCode == 400 && strpos($header, "Invalid Param Location") !== false) {
|
||||
return app('json')->fail("参数错误");
|
||||
throw new \think\exception\ValidateException("参数错误");
|
||||
} elseif ($httpCode == 400 && strpos($header, "Invalid AppCode") !== false) {
|
||||
return app('json')->fail("AppCode错误");
|
||||
throw new \think\exception\ValidateException("AppCode错误");
|
||||
} elseif ($httpCode == 400 && strpos($header, "Invalid Url") !== false) {
|
||||
return app('json')->fail("请求的 Method、Path 或者环境错误");
|
||||
throw new \think\exception\ValidateException("请求的 Method、Path 或者环境错误");
|
||||
} elseif ($httpCode == 403 && strpos($header, "Unauthorized") !== false) {
|
||||
return app('json')->fail("服务未被授权(或URL和Path不正确)");
|
||||
throw new \think\exception\ValidateException("服务未被授权(或URL和Path不正确)");
|
||||
} elseif ($httpCode == 403 && strpos($header, "Quota Exhausted") !== false) {
|
||||
return app('json')->fail("套餐包次数用完");
|
||||
throw new \think\exception\ValidateException("套餐包次数用完");
|
||||
} elseif ($httpCode == 403 && strpos($header, "Api Market Subscription quota exhausted") !== false) {
|
||||
return app('json')->fail("套餐包次数用完,请续购套餐");
|
||||
throw new \think\exception\ValidateException("套餐包次数用完,请续购套餐");
|
||||
} elseif ($httpCode == 500) {
|
||||
return app('json')->fail("API网关错误");
|
||||
throw new \think\exception\ValidateException("API网关错误");
|
||||
} elseif ($httpCode == 0) {
|
||||
return app('json')->fail("URL错误");
|
||||
throw new \think\exception\ValidateException("URL错误");
|
||||
} else {
|
||||
$headers = explode("\r\n", $header);
|
||||
$headList = array();
|
||||
@ -172,9 +172,12 @@ class ProductLibrary extends BaseController
|
||||
$headList[$value[0]] = $value[1];
|
||||
}
|
||||
Log::error('商品采集错误:'.$headList['x-ca-error-message']);
|
||||
return app('json')->fail("参数名错误 或 其他错误");
|
||||
throw new \think\exception\ValidateException("参数名错误 或 其他错误");
|
||||
|
||||
}
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
throw new \think\exception\ValidateException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,32 +3,36 @@ namespace app\controller\api\store\product;
|
||||
use app\common\dao\system\merchant\MerchantDao;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use app\controller\admin\ProductLibrary;
|
||||
use think\facade\Db;
|
||||
use crmeb\basic\BaseController;
|
||||
use Exception;
|
||||
|
||||
class StoreMicro extends BaseController
|
||||
{
|
||||
function seach_bar_code($mer_id,$code='',$name=''){
|
||||
|
||||
$category_id=Db::name('merchant')->where('mer_id',$mer_id)->value('category_id');
|
||||
$mer_type_id = Db::name('MerchantType')->where('type_code', 'in',[Merchant::TypeCode['TypeSupplyChain'],Merchant::TypeCode['TypeTownSupplyChain'],Merchant::TypeCode['TypeStore']])->column('mer_type_id');
|
||||
$platformMerId = app()->make(MerchantDao::class)->getValidMerchant(['category_id' => $category_id])->whereIn('type_id',$mer_type_id)->column('mer_id');
|
||||
if($platformMerId==null){
|
||||
return app('json')->fail('没有市级供应链或者镇级供应链');
|
||||
}
|
||||
$productWhere = ['is_show' => 1, 'status' => 1, 'mer_status' => 1, 'is_del' => 0];
|
||||
$where = ['is_used' => 1, 'status' => 1, 'is_del' => 0];
|
||||
$field = 'id,store_name,bar_code,unit_name,price,cost,ot_price,stock,image';
|
||||
if($code!=''){
|
||||
if (strlen($code) != 13) {
|
||||
if (strlen($code) <13) {
|
||||
return app('json')->success('条形码长度不正确');
|
||||
}
|
||||
$product_id_arr=Db::name('store_product_attr_value')->whereIn('mer_id',$platformMerId)->where('bar_code',$code)->column('product_id');
|
||||
$product_id_arr=implode(',',$product_id_arr);
|
||||
$find=Db::name('store_product')->where('product_id',$product_id_arr)->where($productWhere)->select();
|
||||
$res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field)->find();
|
||||
if($res==null){
|
||||
$ProductLibrary = app()->make(ProductLibrary::class);
|
||||
try{
|
||||
$ProductLibrary->caiji($code);
|
||||
$res=Db::name('product_library')->where('bar_code',$code)->where($where)->field($field)->find();
|
||||
}catch(Exception $e){
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
$find[]=$res;
|
||||
}else{
|
||||
if($name==''){
|
||||
return app('json')->fail('参数不能为空');
|
||||
}
|
||||
$find=Db::name('store_product')->whereIn('mer_id',$platformMerId)->where('store_name','like','%'.$name.'%')->where($productWhere)->select();
|
||||
$find=Db::name('product_library')->where('store_name','like','%'.$name.'%')->where($where)->field($field)->select();
|
||||
}
|
||||
if (count($find)==0){
|
||||
if($code!=''){
|
||||
|
Loading…
x
Reference in New Issue
Block a user