ExpressListForm.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Delivery;
  9. use app\models\Express;
  10. use app\models\Sender;
  11. use yii\base\Model;
  12. class ExpressListForm extends Model
  13. {
  14. /**
  15. * 获取面单列表
  16. * @return array|\yii\db\ActiveRecord[]
  17. */
  18. public static function getList()
  19. {
  20. $query = Delivery::find()->alias('d')
  21. ->leftJoin(['s' => Sender::tableName()], 'd.id=s.delivery_id')
  22. ->where(['d.is_delete' => 0]);
  23. if (get_supplier_id()) {
  24. $query->andWhere(['d.supplier_id' => get_supplier_id(), 'type' => 1]);
  25. } else {
  26. $query->andWhere(['d.store_id' => get_store_id(), 'type' => 0]);
  27. }
  28. $list = $query->select(['d.*', 's.company', 's.name', 's.tel', 's.mobile', 's.post_code', 's.province', 's.city', 's.exp_area', 's.address', 's.company'])
  29. ->orderBy(['d.id' => SORT_DESC])
  30. ->asArray()->all();
  31. foreach ($list as &$val) {
  32. $val['express_name'] = Express::findOne($val['express_id'])->name;
  33. }
  34. return $list;
  35. }
  36. /**
  37. * 获取面单详情
  38. * @return array|\yii\db\ActiveRecord[]
  39. */
  40. public static function getEdit($id)
  41. {
  42. $query = Delivery::find()->alias('d')
  43. ->leftJoin(['s' => Sender::tableName()], 'd.id=s.delivery_id')
  44. ->where(['d.is_delete' => 0, 'd.id' => $id])
  45. ->select(['d.*', 's.company', 's.name', 's.tel', 's.mobile', 's.post_code', 's.province', 's.city', 's.exp_area', 's.address', 's.company']);
  46. if (get_supplier_id()) {
  47. $query->andWhere(['d.supplier_id' => get_supplier_id()]);
  48. } else {
  49. $query->andWhere(['d.store_id' => get_store_id()]);
  50. }
  51. return $query->asArray()->one();
  52. }
  53. }