Express.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\model;
  13. use app\common\model\Express as ExpressModel;
  14. /**
  15. * 物流公司模型
  16. * Class Goods
  17. * @package app\store\model
  18. */
  19. class Express extends ExpressModel
  20. {
  21. /**
  22. * 添加新记录
  23. * @param array $data
  24. * @return bool|false
  25. */
  26. public function add(array $data): bool
  27. {
  28. $data['store_id'] = self::$storeId;
  29. return $this->save($data);
  30. }
  31. /**
  32. * 编辑记录
  33. * @param array $data
  34. * @return bool
  35. */
  36. public function edit(array $data): bool
  37. {
  38. return $this->save($data);
  39. }
  40. /**
  41. * 删除记录
  42. * @return bool
  43. */
  44. public function remove(): bool
  45. {
  46. // 判断当前物流公司是否已被订单使用
  47. $Order = new Order;
  48. if ($orderCount = $Order->where(['express_id' => $this['express_id']])->count()) {
  49. $this->error = '当前物流公司已被' . $orderCount . '个订单使用,不允许删除';
  50. return false;
  51. }
  52. return $this->delete();
  53. }
  54. /**
  55. * 根据物流公司名称获取ID集
  56. * @param array $expressNameArr
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public static function getExpressIds(array $expressNameArr): array
  63. {
  64. $list = (new static)->where('express_name', 'in', $expressNameArr)->select();
  65. $data = [];
  66. foreach ($list as $item) {
  67. $data[$item['express_name']] = $item['express_id'];
  68. }
  69. return $data;
  70. }
  71. }