StoreDescription.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 吴昊天
  5. * Date: 2020-03-16
  6. * Time: 12:35
  7. */
  8. namespace app\admin\model\store;
  9. use crmeb\basic\BaseModel;
  10. use crmeb\traits\ModelTrait;
  11. class StoreDescription extends BaseModel
  12. {
  13. /**
  14. * 模型名称
  15. * @var string
  16. */
  17. protected $name = 'store_product_description';
  18. use ModelTrait;
  19. /**
  20. * 获取详情
  21. * @param $product_id
  22. * @param int $type
  23. * @return mixed
  24. */
  25. public static function getDescription($product_id, $type = 0)
  26. {
  27. return self::where('product_id', $product_id)->where('type', $type)->value('description');
  28. }
  29. /**
  30. * 添加或者修改详情
  31. * @param string $description
  32. * @param int $product_id
  33. * @param int $type
  34. * @return bool|\think\Model|static
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public static function saveDescription(string $description = '', int $product_id = 0, int $type = 0)
  40. {
  41. $description = htmlspecialchars($description);
  42. if ($product_id) {
  43. $info = self::where(['product_id' => $product_id, 'type' => $type])->find();
  44. if ($info) {
  45. $info->description = $description;
  46. return $info->save();
  47. }
  48. }
  49. return self::create(compact('description', 'product_id', 'type'));
  50. }
  51. }