wugg 1 year ago
parent
commit
727fdb8d9a

+ 57 - 0
app/api/controller/Base.php

@@ -0,0 +1,57 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+use think\App;
+use think\exception\HttpResponseException;
+use think\Response;
+
+class Base extends \app\controller\Base
+{
+	public function __construct(App $app) {
+		parent::__construct($app);
+	}
+	 /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+    public function error($message='',$code=1003,$data=null){
+        $this->result($message,$data,$code);
+    }
+    /**
+	* @param string $message
+	* @param int $code
+	* @param null $data
+	 */
+     public function success($message='',$data=null,$code=0){
+        $this->result($message,$data,$code);
+    }
+    
+     /**
+	* @param string $msg
+	* @param null $data
+	* @param int $code
+	* @param string|null $type
+	* @param array $header
+	* @param array $options
+	 */
+    private function result(string $msg, $data = null, int $code = 0, string $type = 'json', array $header = [], array
+    $options = [])
+    {
+        $result = [
+            'code' => $code,
+            'message'  => $msg,
+            'data' => $data,
+        ];
+        $code = 200;
+        if (isset($header['statuscode'])) {
+            $code = $header['statuscode'];
+            unset($header['statuscode']);
+        }
+
+        $response = Response::create($result, $type, $code)->header($header)->options($options);
+         throw new HttpResponseException($response);
+    }
+}

+ 81 - 0
app/api/controller/Good.php

@@ -0,0 +1,81 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\controller;
+
+use app\api\model\ActGoodUrl;
+use app\api\model\Brand;
+use app\api\model\Cat;
+use app\api\model\GoodSpec;
+use app\api\model\PlatformYouzan;
+use app\api\model\Unit;
+use app\model\Good as YzGood;
+use think\App;
+use think\facade\Validate;
+
+class Good extends Base
+{
+	private $platform_id=37;
+	private  $origin_img_host ='http://stock.api.wanyuhengtong.com';
+    private  $ssl_img_host ='https://image.wanyuhengtong.com';
+	public function __construct(App $app) {
+		parent::__construct($app);
+	}
+  	public function list(){
+		$param = $this->request->param(['page'=>1,'size'=>15,'good_name'=>''],'post','trim');
+		$where = [['b.is_del', '=', 0],['a.is_del', '=', 0],['b.platform_id','=',$this->platform_id],['b.exam_status',
+		'=',6]];
+		$param['good_name']!=''??$where[]=['c.good_name','like',"%{$param['good_name']}%"];
+		$actUrl= new ActGoodurl();
+		$list = $actUrl->alias('a')
+		->leftJoin('platform_youzan b','a.act_good_id=b.id')
+		->leftJoin('good_basic c', 'c.spuCode=b.spuCode')
+		->where($where)
+		->field('b.skuCode,b.plat_code,b.id as platform_youzan_id,a.act_good_url,
+		            c.good_name,c.good_img,c.good_info_img,c.good_thumb_img,c.brand_id,c.cat_id,
+		            c.good_unit,a.addtime,a.updatetime,b.spuCode,b.sale_price,b.final_price')
+		->order('a.id desc')
+		->paginate(['list_rows'=>$param['size'],'page'=>$param['page']]);
+		foreach ($list->items() as $item){
+			$item['brand_name'] =Brand::where('id',$item['brand_id'])->value('brand_name','');
+			$item['good_unit'] =Unit::where('id',$item['good_unit'])->value('unit','');
+			$item['cat_name'] =Cat::where('id',$item['cat_id'])->value('search','');
+			$item['good_url'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('detail_url','');
+			$item['origin_price'] =YzGood::where(['item_no'=>$item['skuCode'],'is_del'=>0])->value('origin','');
+			$item['spec_info'] =GoodSpec::where(['spuCode' => $item['spuCode'], 'is_del' => 0])->with(['spec',
+			'Spec_info'])->field('spec_id,spec_value_id')->select();
+		}
+		$this->success('获取成功',['list'=>$list->items(),'count'=>$list->total()]);
+	}
+	
+	public function GoodInfo(){
+	    $param =$this->request->only(['skuCode'=>''],'post','trim');
+	    $valid =Validate::rule(['skuCode|商品上线编号'=>'require']);
+		if($valid->check($param)==false)$this->error($valid->getError());
+		$field='b.skuCode,b.plat_code,b.id as platform_youzan_id,a.cat_id,
+            a.good_name,a.good_img,a.good_info_img,a.good_thumb_img,a.brand_id,
+            a.good_unit,b.addtime,b.updatetime,a.spuCode, b.sale_price,b.final_price';
+		$youzan = new PlatformYouzan();
+	    $info = $youzan
+	              ->alias('b')
+	              ->field($field)
+		    //成本表里的创建人,也是线上商品的采购人,为了防止混淆,给creater取个别名
+		          ->leftJoin('good_basic a', 'a.spuCode=b.spuCode')
+	              ->where(['b.skuCode'=>$param['skuCode'],'b.is_del'=>0])->findOrEmpty();
+
+	    if($info->isEmpty())  $this->error('商品数据未找到');
+	   
+	        $info->brand_name =Brand::where('id',$info->brand_id)->value('brand_name','');
+			$info->unit_name =Unit::where('id',$info->good_unit)->value('unit','');
+			$info->cat_name =Cat::where('id',$info->cat_id)->value('search','');
+			$info->act_good_url =ActGoodurl::where(['act_good_id'=>$info->platform_youzan_id,'is_del'=>0])->value('act_good_url','');;
+	        $info->good_url =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('detail_url','');
+	        $info->origin_price =YzGood::where(['item_no'=>$info->skuCode,'is_del'=>0])->value('origin','');
+	        $info->specinfo =GoodSpec::where(['spuCode' => $info->spuCode, 'is_del' => 0])->with(['spec','Spec_info'])->field('spec_id,spec_value_id')->select();
+	    
+	    $info->good_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_img);
+	    $info->good_info_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_info_img);
+	    $info->good_thumb_img=str_replace($this->origin_img_host,$this->ssl_img_host,$info->good_thumb_img);
+	    $this->success('获取成功',$info);
+    }
+}

+ 14 - 0
app/api/model/ActGoodUrl.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ActGoodUrl extends Model
+{
+    //
+}

+ 14 - 0
app/api/model/Brand.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Brand extends Model
+{
+    //
+}

+ 14 - 0
app/api/model/Cat.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Cat extends Model
+{
+    //
+}

+ 20 - 0
app/api/model/GoodSpec.php

@@ -0,0 +1,20 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class GoodSpec extends Model
+{
+    public function spec(){
+		return $this->belongsTo(Specs::class,'spec_id')->bind(['spec_name']);
+	}
+	
+	public function SpecInfo(){
+		return $this->belongsTo(SpecValue::class,'spec_value_id')->bind(['spec_value_name'=>'spec_value']);
+	}
+}

+ 14 - 0
app/api/model/PlatformYouzan.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class PlatformYouzan extends Model
+{
+    //
+}

+ 14 - 0
app/api/model/SpecValue.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class SpecValue extends Model
+{
+    //
+}

+ 14 - 0
app/api/model/Specs.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Specs extends Model
+{
+    //
+}

+ 14 - 0
app/api/model/Unit.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\api\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Unit extends Model
+{
+    //
+}

+ 10 - 0
app/model/Base.php

@@ -0,0 +1,10 @@
+<?php
+
+
+namespace app\model;
+
+
+use think\Model;
+class Base  extends Model {
+
+}

+ 12 - 0
app/model/Good.php

@@ -0,0 +1,12 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\model;
+
+
+/**
+ * @mixin \think\Model
+ */
+class Good extends Base
+{
+}

+ 0 - 2
app/txx/controller/Good.php

@@ -48,8 +48,6 @@ class Good extends BaseController
 		if(empty($goodArr)) return json_show(1005,"未找到商品有效数据");
 		$actCode= $post['actCode']!=''? trim($post['actCode']):"";
 		if($actCode=='') return json_show(1004,"参数错误 actCode 不能为空");
-//	    $roundId= $post['roundId']!=''? trim($post['roundId']):"";
-//	    if($roundId=='') return json_show(1004,"参数错误 roundId 不能为空");
 		$act =new Act();
 		$isActExit=$act->where(['actCode'=>$actCode,"is_del"=>0])->find();
 		if($isActExit==false) return json_show(1005,"未找到活动有效数据");

+ 0 - 77
config/database.php

@@ -57,63 +57,6 @@ return [
 			// 开启字段缓存
 			'fields_cache' => false,
 		],
-//		"mysql2" => [
-//			'type' => env('database.type', 'mysql'),
-//			// 服务器地址
-//			'hostname' => env('database.hostname', '121.36.90.170'),
-//			// 数据库名
-//			'database' => env('database.database', 'cloudpivot'),
-//			// 用户名
-//			'username' => env('database.username', 'root'),
-//			// 密码
-//			'password' => env('database.password', 'test123456!@#$%'),
-//			// 端口
-//			'hostport' => env('database.hostport', '3306'),
-//			// 数据库连接参数
-//			'params' => [],
-//			// 数据库编码默认采用utf8
-//			'charset' => env('database.charset', 'utf8'),
-//		],
-//		'mysql3' => [
-//			// 数据库类型
-//			'type' => env('database.type', 'mysql'),
-//			// 服务器地址
-//			// 服务器地址
-//			// 服务器地址
-//			'hostname' => env('database.hostname', '192.168.0.205'),
-//			// 数据库名
-//			'database' => env('database.database', 'wyht_invoice'),
-//			// 用户名
-//			'username' => env('database.username', 'caxiao_invoice'),
-//			// 密码
-//			'password' => env('database.password', 'xrok0SgeKR7g'),
-//			// 端口
-//			'hostport' => env('database.hostport', '3306'),
-//			// 数据库连接参数
-//			'params' => [],
-//			// 数据库编码默认采用utf8
-//			'charset' => env('database.charset', 'utf8'),
-//			// 数据库表前缀
-//			'prefix' => env('database.prefix', 'cfp_'),
-//
-//			// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
-//			'deploy' => 0,
-//			// 数据库读写是否分离 主从式有效
-//			'rw_separate' => false,
-//			// 读写分离后 主服务器数量
-//			'master_num' => 1,
-//			// 指定从服务器序号
-//			'slave_no' => '',
-//			// 是否严格检查字段是否存在
-//			'fields_strict' => true,
-//			// 是否需要断线重连
-//			'break_reconnect' => false,
-//			// 监听SQL
-//			'trigger_sql' => env('app_debug', true),
-//			// 开启字段缓存
-//			'fields_cache' => false,
-//		],
-//		// 更多的数据库配置信息
 		//连接有赞对接项目的数据库
 		"mysql_yz" => [
 			'type' => env('database.type', 'mysql'),
@@ -133,25 +76,5 @@ return [
 			'charset' => env('database.charset', 'utf8'),
 			'prefix' => 'yz_',
 		],
-
-//		//用户账号数据库
-//		"mysql_sys" => [
-//			'type' => env('database.type', 'mysql'),
-//			// 服务器地址
-//			'hostname' => env('database.hostname', '192.168.0.205'),
-//			// 数据库名
-//			'database' => env('database.database', 'user_account'),
-//			// 用户名
-//			'username' => env('database.username', 'caxiao_invoice'),
-//			// 密码
-//			'password' => env('database.password', 'xrok0SgeKR7g'),
-//			// 端口
-//			'hostport' => env('database.hostport', '3306'),
-//			// 数据库连接参数
-//			'params' => [],
-//			// 数据库编码默认采用utf8
-//			'charset' => env('database.charset', 'utf8'),
-//			'prefix' => 'sys_',
-//		],
 	],
 ];