Goods.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * 短信服务
  4. * @author wesmiler
  5. */
  6. namespace app\index\service;
  7. use \app\index\model\GoodsModel;
  8. class Goods
  9. {
  10. /**
  11. * 验证预售商品是否已存在
  12. * @param $productId 预售商品原始ID
  13. * @return bool|mixed
  14. */
  15. public static function checkGoodsExists($productId){
  16. if(empty($productId)){
  17. return false;
  18. }
  19. return GoodsModel::where(['product_id'=> $productId])->value('id');
  20. }
  21. /**
  22. * 获取列表
  23. * @param $params
  24. * @param int $pageSize
  25. * @param string $field
  26. * @param string $order
  27. * @return $this
  28. * @throws \think\exception\DbException
  29. */
  30. public static function getList($params, $pageSize = 15, $field = '', $order = '')
  31. {
  32. $statusArr = [1,2,3];
  33. $status = isset($params['status'])? intval($params['status']) : 0;
  34. if($status){
  35. $statusArr = [$status];
  36. }
  37. $currencys = ['CNY'=> '¥','USD'=>'$'];
  38. $order = $order ? $order : 'start_date desc,created_at desc,id desc';
  39. $field = $field ? $field : 'id,title,full_title,product_id,thumb,current_price,discounted,currency,start_date,publish_date,publish_type,created_at,status';
  40. return GoodsModel::whereIn('status', $statusArr)
  41. ->field($field)
  42. ->order($order)
  43. ->paginate($pageSize)
  44. ->each(function ($item, $k) use($currencys) {
  45. $startTime = isset($item['start_date'])? strtotime($item['start_date']) : '';
  46. $publishTime = isset($item['publish_date'])? strtotime($item['publish_date']) : '';
  47. if(time()>= $startTime && time() <= $startTime+7200){
  48. $item['status'] = 2;
  49. }else if(time()<$startTime){
  50. $item['status'] = 1;
  51. }else{
  52. $item['status'] = 3;
  53. }
  54. $item['publish_type'] = isset($item['publish_type'])? strtolower($item['publish_type']) : '';
  55. $item['thumb'] = isset($item['thumb']) ? cmf_get_image_preview_url($item['thumb']) : '';
  56. $item['publish_date'] = $publishTime ? date('m月d日 H:i', $publishTime) : '未公布';
  57. $item['start_date'] = $startTime ? date('m月d日 H:i', $startTime) : '未公布';
  58. $currencyKey = isset($item['currency'])? trim($item['currency']): '';
  59. $item['currency'] = isset($currencys[$currencyKey])? $currencys[$currencyKey] : '';
  60. return $item;
  61. });
  62. }
  63. }