Order.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\promotion;
  10. use app\common\service\promotion\Order as OrderService;
  11. use app\admin\model\promotion\PromotionOrder as PromotionOrderModel;
  12. class Order extends OrderService {
  13. /**
  14. * 列表
  15. * @param $data
  16. * @return array
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\DbException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. */
  21. public static function getList($data){
  22. $count = PromotionOrderModel::withSearch("name",['name'=>$data['key']["title"]??''])->count();
  23. $result = PromotionOrderModel::withSearch("name",['name'=>$data['key']["title"]??''])->page($data["page"]??1,$data["limit"]??10)->order("id","desc")->select()->toArray();
  24. foreach($result as $key=>$item){
  25. $result[$key]['type'] = self::getActivityType($item["type"]);
  26. }
  27. return [ "count"=>$count, "data"=>$result ];
  28. }
  29. /**
  30. * 详情
  31. * @param $id
  32. * @return array[]
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public static function detail($id){
  38. return [
  39. "type"=>self::getActivityType(),
  40. "data"=>PromotionOrderModel::where("id",$id)->find()??[]
  41. ];
  42. }
  43. public static function save($data){
  44. $data["start_time"] = strtotime($data["start_time"]);
  45. $data["end_time"] = strtotime($data["end_time"]);
  46. if($data["start_time"] > $data["end_time"]){
  47. throw new \Exception("开始时间不能小于结束时间",0);
  48. }
  49. if(PromotionOrderModel::where('id',$data["id"])->count()){
  50. PromotionOrderModel::where('id',$data["id"])->save($data);
  51. }else{
  52. PromotionOrderModel::create($data);
  53. }
  54. }
  55. /**
  56. * 删除
  57. * @param $id
  58. * @return bool
  59. */
  60. public static function delete($id){
  61. return PromotionOrderModel::where("id",$id)->delete();
  62. }
  63. }