Express.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2025 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. return $this->save(['is_delete' => 1]);
  47. }
  48. /**
  49. * 根据物流公司名称获取ID集
  50. * @param array $expressNames
  51. * @return array
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public static function getExpressIds(array $expressNames): array
  57. {
  58. $list = (new static)->getListByExpressName($expressNames);
  59. $data = [];
  60. foreach ($list as $item) {
  61. $data[$item['express_name']] = $item['express_id'];
  62. }
  63. return $data;
  64. }
  65. /**
  66. * 根据物流公司名称获取列表记录
  67. * @param array $expressNames
  68. * @return Express[]|array|\think\Collection
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. private function getListByExpressName(array $expressNames)
  74. {
  75. return (new static)->where('express_name', 'in', $expressNames)
  76. ->where('is_delete', '=', 0)
  77. ->select();
  78. }
  79. }