Deliver.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\Deliver as DeliverModel;
  12. use app\common\models\Area as AreaModel;
  13. class Deliver extends Service {
  14. /**
  15. * 获取列表数据
  16. * @param $data
  17. * @return array
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\DbException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. */
  22. public static function getList($data){
  23. return [
  24. "count"=>DeliverModel::count(),
  25. "data"=>DeliverModel::page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray()
  26. ];
  27. }
  28. /**
  29. * 详情
  30. * @param $id
  31. * @return array
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public static function detail($id){
  37. $row = DeliverModel::where("id",$id)->find();
  38. $province = AreaModel::where(['pid' => 0])->select()->toArray();
  39. $city = $area = [];
  40. if(!empty($row["province"])){
  41. $city = AreaModel::where(['pid' => $row["province"]])->select()->toArray();
  42. }
  43. if(!empty($row["city"])){
  44. $area = AreaModel::where(['pid' => $row["city"]])->select()->toArray();
  45. }
  46. return [ "province"=>$province, "city"=>$city, "area"=>$area, "data"=>$row??[] ];
  47. }
  48. /**
  49. * 保存数据
  50. * @param $data
  51. * @return DeliverModel|bool|\think\Model
  52. */
  53. public static function save($data){
  54. $data["is_default"] = isset($data["is_default"]) && is_numeric($data["is_default"]) ? $data["is_default"] : 0;
  55. if($data["is_default"] == 1){
  56. DeliverModel::where("1=1")->update(["is_default" => 0]);
  57. }
  58. if(DeliverModel::where("id",$data["id"])->count()){
  59. return DeliverModel::where("id",$data["id"])->save($data);
  60. }else{
  61. return DeliverModel::create($data);
  62. }
  63. }
  64. /**
  65. * 删除
  66. * @param $id
  67. * @return bool
  68. */
  69. public static function delete($id){
  70. return DeliverModel::where("id",$id)->delete();
  71. }
  72. }