| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- /**
- * 短信服务
- * @author wesmiler
- */
- namespace app\index\service;
- use \app\index\model\GoodsModel;
- class Goods
- {
- /**
- * 验证预售商品是否已存在
- * @param $productId 预售商品原始ID
- * @return bool|mixed
- */
- public static function checkGoodsExists($productId){
- if(empty($productId)){
- return false;
- }
- return GoodsModel::where(['product_id'=> $productId])->value('id');
- }
- /**
- * 获取列表
- * @param $params
- * @param int $pageSize
- * @param string $field
- * @param string $order
- * @return $this
- * @throws \think\exception\DbException
- */
- public static function getList($params, $pageSize = 15, $field = '', $order = '')
- {
- $statusArr = [1,2,3];
- $status = isset($params['status'])? intval($params['status']) : 0;
- if($status){
- $statusArr = [$status];
- }
- $currencys = ['CNY'=> '¥','USD'=>'$'];
- $order = $order ? $order : 'start_date desc,created_at desc,id desc';
- $field = $field ? $field : 'id,title,full_title,product_id,thumb,current_price,discounted,currency,start_date,publish_date,publish_type,created_at,status';
- return GoodsModel::whereIn('status', $statusArr)
- ->field($field)
- ->order($order)
- ->paginate($pageSize)
- ->each(function ($item, $k) use($currencys) {
- $startTime = isset($item['start_date'])? strtotime($item['start_date']) : '';
- $publishTime = isset($item['publish_date'])? strtotime($item['publish_date']) : '';
- if(time()>= $startTime && time() <= $startTime+7200){
- $item['status'] = 2;
- }else if(time()<$startTime){
- $item['status'] = 1;
- }else{
- $item['status'] = 3;
- }
- $item['publish_type'] = isset($item['publish_type'])? strtolower($item['publish_type']) : '';
- $item['thumb'] = isset($item['thumb']) ? cmf_get_image_preview_url($item['thumb']) : '';
- $item['publish_date'] = $publishTime ? date('m月d日 H:i', $publishTime) : '未公布';
- $item['start_date'] = $startTime ? date('m月d日 H:i', $startTime) : '未公布';
- $currencyKey = isset($item['currency'])? trim($item['currency']): '';
- $item['currency'] = isset($currencys[$currencyKey])? $currencys[$currencyKey] : '';
- return $item;
- });
- }
- }
|