|
@@ -3,7 +3,7 @@
|
|
|
namespace app\api\controller;
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
use think\Db;
|
|
use think\Db;
|
|
|
-use think\db\Expression;
|
|
|
|
|
|
|
+use think\Loader ;
|
|
|
use app\common\controller\Api;
|
|
use app\common\controller\Api;
|
|
|
use app\common\model\ProductLists;
|
|
use app\common\model\ProductLists;
|
|
|
use app\common\model\ProductMarket;
|
|
use app\common\model\ProductMarket;
|
|
@@ -11,10 +11,11 @@ use app\common\model\ProductOrder;
|
|
|
use app\common\model\ProductsModel;
|
|
use app\common\model\ProductsModel;
|
|
|
use app\common\model\ProductPopular;
|
|
use app\common\model\ProductPopular;
|
|
|
use app\api\logic\OrderLogic;
|
|
use app\api\logic\OrderLogic;
|
|
|
|
|
+use app\common\model\UserCollect;
|
|
|
|
|
|
|
|
class Product extends Api
|
|
class Product extends Api
|
|
|
{
|
|
{
|
|
|
- protected array $noNeedLogin = ['*'];
|
|
|
|
|
|
|
+ protected array $noNeedLogin = ['getPopularList'];
|
|
|
protected string $lan = '';
|
|
protected string $lan = '';
|
|
|
|
|
|
|
|
public function _initialize()
|
|
public function _initialize()
|
|
@@ -62,7 +63,40 @@ class Product extends Api
|
|
|
* type_id 分类
|
|
* type_id 分类
|
|
|
* key_val 商品名称搜索
|
|
* key_val 商品名称搜索
|
|
|
*/
|
|
*/
|
|
|
- public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
|
|
|
|
|
|
|
+ public function getTransferList(ProductMarket $productMarket, OrderLogic $orderLogic)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ $sort = $this->request->post('sort/d', '');
|
|
|
|
|
+ $type_id = $this->request->post('type_id/s', '');
|
|
|
|
|
+ $key_val = $this->request->post('key_val/s', '');
|
|
|
|
|
+ $order = 'a.price ASC';
|
|
|
|
|
+ if($sort == 1) $order = 'a.price DESC';
|
|
|
|
|
+ $map['product_market.status'] = $productMarket::Normal;
|
|
|
|
|
+ if(!empty($type_id)) $map['product_market.type_id'] = $type_id;
|
|
|
|
|
+ if(!empty($key_val)) $map['product_list.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
|
|
|
|
|
+
|
|
|
|
|
+ $list = $productMarket
|
|
|
|
|
+ ->alias('a')
|
|
|
|
|
+ ->join("product_list b", "a.product_id = b.id", "left")
|
|
|
|
|
+ ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
|
|
|
|
|
+ ->where('a.status', $productMarket::Normal)
|
|
|
|
|
+ ->where($map)
|
|
|
|
|
+ ->order($order)
|
|
|
|
|
+ ->paginate($this->pageSize);
|
|
|
|
|
+
|
|
|
|
|
+ $list = $this->getProductOrderList($list, $this->auth->id, true, $orderLogic);
|
|
|
|
|
+ $this->success('', $list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 寄售转让收藏列表
|
|
|
|
|
+ * sort: 0 默认排序 1价格从高到低 2价格从低到高
|
|
|
|
|
+ * type_id 分类
|
|
|
|
|
+ * key_val 商品名称搜索
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getTransferCollectList(ProductMarket $productMarket, OrderLogic $orderLogic)
|
|
|
{
|
|
{
|
|
|
$sort = $this->request->post('sort/d', '');
|
|
$sort = $this->request->post('sort/d', '');
|
|
|
$type_id = $this->request->post('type_id/s', '');
|
|
$type_id = $this->request->post('type_id/s', '');
|
|
@@ -74,20 +108,20 @@ class Product extends Api
|
|
|
if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
|
|
if(!empty($key_val)) $map['b.'.$this->lan.'_name'] = ['like', '%'.$key_val.'%'];
|
|
|
$list = $productMarket->alias('a')
|
|
$list = $productMarket->alias('a')
|
|
|
->join("product_list b", "a.product_id = b.id", "left")
|
|
->join("product_list b", "a.product_id = b.id", "left")
|
|
|
- ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id')
|
|
|
|
|
|
|
+ ->join("user_collect c", "c.market_id = a.id", "left")
|
|
|
|
|
+ ->field('a.id,'.'b.'.$this->lan.'_name as name,b.thum as img_url,a.price,a.product_id,a.type_id, count(c.market_id) as collect')
|
|
|
->where('a.status', $productMarket::Normal)
|
|
->where('a.status', $productMarket::Normal)
|
|
|
->where($map)
|
|
->where($map)
|
|
|
->order($order)
|
|
->order($order)
|
|
|
->paginate($this->pageSize);
|
|
->paginate($this->pageSize);
|
|
|
|
|
|
|
|
- foreach ($list as &$item) {
|
|
|
|
|
- $item['issue'] = $orderLogic::getProductIssue($item->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的
|
|
|
|
|
- $item['circulation'] = $productOrder::where('product_id', $item->product_id)->where('status', $productOrder::Paid)->count(); //流通: 所有用户的持有量
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $list = $this->getProductOrderList($list, $this->auth->id, false, $orderLogic);
|
|
|
$this->success('', $list);
|
|
$this->success('', $list);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
|
|
+ /**
|
|
|
* 寄售转让详情
|
|
* 寄售转让详情
|
|
|
* sort: 0 默认排序 1价格从高到低 2价格从低到高
|
|
* sort: 0 默认排序 1价格从高到低 2价格从低到高
|
|
|
* type_id 分类
|
|
* type_id 分类
|
|
@@ -95,22 +129,33 @@ class Product extends Api
|
|
|
*/
|
|
*/
|
|
|
public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
|
|
public function getTransferDetail(ProductMarket $productMarket, OrderLogic $orderLogic, ProductOrder $productOrder)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
$ids = $this->request->post('ids/d', '');
|
|
$ids = $this->request->post('ids/d', '');
|
|
|
$list = $productMarket->with('products,producttransfer')
|
|
$list = $productMarket->with('products,producttransfer')
|
|
|
->where('product_market.id', $ids)
|
|
->where('product_market.id', $ids)
|
|
|
->where('product_market.status', $productMarket::Normal)
|
|
->where('product_market.status', $productMarket::Normal)
|
|
|
->find();
|
|
->find();
|
|
|
-
|
|
|
|
|
if(empty($list)) $this->error('数据不存在');
|
|
if(empty($list)) $this->error('数据不存在');
|
|
|
|
|
|
|
|
$list->issue = $orderLogic::getProductIssue($list->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的
|
|
$list->issue = $orderLogic::getProductIssue($list->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的
|
|
|
- $list->circulation = $productOrder::where('product_id', $list->product_id)->where('status', $productOrder::Paid)->count(); //流通: 所有用户的持有量
|
|
|
|
|
|
|
+ $list->circulation = $orderLogic::getProductCirculation($list->product_id); //流通: 所有用户的持有量
|
|
|
$this->success('', $list);
|
|
$this->success('', $list);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ private static function getProductOrderList(object $list, int $uid, bool $isCollect, OrderLogic $orderLogic): object
|
|
|
|
|
+ {
|
|
|
|
|
+ if($list){
|
|
|
|
|
+ $userCollect = Loader::model('UserCollect');
|
|
|
|
|
+ foreach ($list as &$item) {
|
|
|
|
|
+ if($isCollect) $item['collect'] = $userCollect::where('user_id', $uid)->where('market_id', $item->id)->count();
|
|
|
|
|
+ $item['issue'] = $orderLogic::getProductIssue($item->product_id); //发行: 是产品的库存总量(卖出和没卖出的都算,最保险的计算方式是剩余库存量+所有用户的持有量;因为空投产品不是从库存出去的
|
|
|
|
|
+ $item['circulation'] = $orderLogic::getProductCirculation($item->product_id); //流通: 所有用户的持有量
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//获取分类
|
|
//获取分类
|
|
|
public function getPopularType()
|
|
public function getPopularType()
|