AdminMerchant.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. *
  4. *
  5. * @category xxx
  6. * @package PSR
  7. * @subpackage Documentation\API
  8. * @author xxx <xxx@xxx.com>
  9. * @license GPL https://xxx.com
  10. * @link https://xxx.com
  11. * @ctime: 2020/5/13 15:47
  12. */
  13. namespace App\Models;
  14. use App\Maps\CacheMap;
  15. use Carbon\Carbon;
  16. use Illuminate\Support\Facades\Cache;
  17. class AdminMerchant extends Model
  18. {
  19. const STATUS_OK = 1;
  20. const STATUS_PAUSE = 0;
  21. public static $statusMaps = [
  22. self::STATUS_OK => '正常',
  23. self::STATUS_PAUSE => '暂停',
  24. ];
  25. protected $guarded = [];
  26. /**
  27. * 通过id获取数据
  28. * @param $id
  29. * Author: Mead
  30. */
  31. public static function byId($id)
  32. {
  33. if (CacheMap::IS_OPEN_DB_CACHE) {
  34. return Cache::remember(CacheMap::DB . "AdminMerchantRepository:byIdGetModel:" . $id, Carbon::now()->addHours(24), function () use ($id) {
  35. return self::where('id', $id)->where('status', AdminMerchant::STATUS_OK)->first();
  36. });
  37. }
  38. return self::where('id', $id)->where('status', AdminMerchant::STATUS_OK)->first();
  39. }
  40. public static function byIdNoStatus($id)
  41. {
  42. if (CacheMap::IS_OPEN_DB_CACHE) {
  43. return Cache::remember(CacheMap::DB . "AdminMerchantRepository:byIdNoStatus:" . $id, Carbon::now()->addHours(24), function () use ($id) {
  44. return self::where('id', $id)->first();
  45. });
  46. }
  47. return self::where('id', $id)->first();
  48. }
  49. public function getOrderKey($v)
  50. {
  51. return strtoupper($v);
  52. }
  53. }