Freight.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\service\products;
  10. use app\admin\service\Service;
  11. use app\common\models\goods\Freight as FreightModel;
  12. class Freight extends Service {
  13. public static function getList($data){
  14. return [
  15. "count"=>FreightModel::count(),
  16. "data"=>FreightModel::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray()
  17. ];
  18. }
  19. /**
  20. * 详情
  21. * @param $id
  22. * @return array[]
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\DbException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. */
  27. public static function detail($id){
  28. return [ "data"=>FreightModel::where("id",$id)->find() ?? [] ];
  29. }
  30. /**
  31. * 保存数据
  32. * @param array $data
  33. * @return FreightModel|bool|\think\Model
  34. */
  35. public static function save($data=[]){
  36. if(FreightModel::where("id",$data["id"])->count()){
  37. return FreightModel::where("id",$data["id"])->save($data);
  38. }else{
  39. return FreightModel::create($data);
  40. }
  41. }
  42. /**
  43. * 删除
  44. * @param $id
  45. * @return bool
  46. */
  47. public static function delete($id){
  48. return FreightModel::where("id",$id)->delete();
  49. }
  50. /**
  51. * 更新字段值
  52. * @return FreightModel
  53. */
  54. public static function setFields(){
  55. $data = self::getFields();
  56. return FreightModel::where("id",$data["id"])->update([$data["name"]=>$data["value"]]);
  57. }
  58. }