ExpressCompanyService.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use common\enums\StatusEnum;
  4. use common\components\Service;
  5. use common\helpers\ArrayHelper;
  6. use addons\TinyShop\common\models\common\ExpressCompany;
  7. /**
  8. * Class ExpressCompanyService
  9. * @package addons\TinyShop\services\common
  10. * @author jianyan74 <751393839@qq.com>
  11. */
  12. class ExpressCompanyService extends Service
  13. {
  14. /**
  15. * @param $id
  16. * @return array|\yii\db\ActiveRecord|null
  17. */
  18. public function findById($id)
  19. {
  20. return ExpressCompany::find()
  21. ->where(['id' => $id, 'status' => StatusEnum::ENABLED])
  22. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  23. ->one();
  24. }
  25. /**
  26. * @return array
  27. */
  28. public function getMapList()
  29. {
  30. return ArrayHelper::map($this->getList($this->getMerchantId()), 'id', 'title');
  31. }
  32. /**
  33. * @param $id
  34. * @return array|\yii\db\ActiveRecord|null
  35. */
  36. public function findByTitles($titles)
  37. {
  38. return ExpressCompany::find()
  39. ->where(['status' => StatusEnum::ENABLED])
  40. ->andWhere(['in', 'title', $titles])
  41. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  42. ->asArray()
  43. ->all();
  44. }
  45. /**
  46. * 获取默认物流
  47. *
  48. * @return array|null|\yii\db\ActiveRecord
  49. */
  50. public function getDefault($merchant_id)
  51. {
  52. return ExpressCompany::find()
  53. ->where(['is_default' => StatusEnum::ENABLED, 'status' => StatusEnum::ENABLED])
  54. ->andWhere(['merchant_id' => $merchant_id])
  55. ->asArray()
  56. ->one();
  57. }
  58. /**
  59. * 获取最后添加物流
  60. *
  61. * @return array|null|\yii\db\ActiveRecord
  62. */
  63. public function getLast($merchant_id)
  64. {
  65. return ExpressCompany::find()
  66. ->where(['status' => StatusEnum::ENABLED])
  67. ->andWhere(['merchant_id' => $merchant_id])
  68. ->orderBy('id desc')
  69. ->asArray()
  70. ->one();
  71. }
  72. /**
  73. * 获取列表
  74. *
  75. * @param $merchant_id
  76. * @param $select
  77. * @return array|\yii\db\ActiveRecord[]
  78. */
  79. public function getList($merchant_id, $select = ['*'])
  80. {
  81. return ExpressCompany::find()
  82. ->select($select)
  83. ->where(['status' => StatusEnum::ENABLED])
  84. ->andFilterWhere(['merchant_id' => $merchant_id])
  85. ->orderBy('is_default desc, sort asc, id desc')
  86. ->asArray()
  87. ->all();
  88. }
  89. }
粤ICP备19079148号