123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\admin\model\system;
- use app\admin\model\order\StoreOrder;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- use crmeb\services\PHPExcelService;
- /**
- * 门店自提 model
- * Class SystemStore
- * @package app\admin\model\system
- */
- class SystemStoreSender extends BaseModel
- {
- use ModelTrait;
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'system_store_sender';
- public static function verificWhere()
- {
- return self::where('is_show', 1)->where('is_del', 0);
- }
- /**
- * 获取门店信息
- * @param int $id
- * @return array|\think\Model|null
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getStoreDispose($id = 0, $store_id = 0)
- {
- if ($id)
- $storeInfo = self::verificWhere()->where('id', $id)->find();
- else
- // $storeInfo = self::verificWhere()->find();
- $storeInfo = [];
- if ($storeInfo) {
- if ($store_id && $store_id != $storeInfo) {
- goto end;
- }
- $storeInfo['store'] = SystemStore::get($storeInfo['store_id'])->toArray();
- } else {
- end:
- $storeInfo['id'] = 0;
- $storeInfo['store'] = [];
- }
- return $storeInfo;
- }
- /**
- * 获取门店列表
- * @param $where
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getStoreList($where)
- {
- $model = new self();
- if (isset($where['store_id']) && $where['store_id'] != '') {
- $model = $model->where('store_id', $where['store_id']);
- }
- if (isset($where['name']) && $where['name'] != '') {
- $model = $model->where('id|name', 'like', '%' . $where['name'] . '%');
- }
- if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
- $model = $model->where($data);
- }
- $count = $model->count();
- $data = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
- $item['store'] = SystemStore::get($item['store_id'])->value('name');
- });
- if ($where['excel'] == 1) {
- $export = [];
- foreach ($data as $index => $item) {
- $export[] = [
- $item['name'],
- $item['store'],
- $item['phone'],
- ];
- }
- PHPExcelService::setExcelHeader(['配送员姓名', '所属门店', '配送员电话'])
- ->setExcelTile('配送员导出', '配送员信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
- ->setExcelContent($export)
- ->ExcelSave();
- }
- return compact('count', 'data');
- }
- /**
- * 获取连表查询条件
- * @param $type
- * @return array
- */
- public static function setData($type)
- {
- switch ((int)$type) {
- case 1:
- $data = ['is_show' => 1, 'is_del' => 0];
- break;
- case 2:
- $data = ['is_show' => 0, 'is_del' => 0];
- break;
- case 3:
- $data = ['is_del' => 1];
- break;
- };
- return isset($data) ? $data : [];
- }
- public static function dropList()
- {
- $model = new self();
- $model = $model->where('is_del', 0);
- $list = $model->select()
- ->toArray();
- return $list;
- }
- }
|