|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
-
- namespace app\admin\model;
-
- use think\Model;
-
- class SmsLog extends Model
- {
-
- public function getAll($param, $page, $pageSize)
- {
- unset($param['page']);
- unset($param['pageSize']);
- foreach ($param as $k => $v) {
- if ($param[$k] === '' || $param[$k] === null) {
- unset($param[$k]);
- }
- }
- $where = [];
- if (isset($param['create_time_start'])) {
- $where[] = ['s.create_time', 'between', [$param['create_time_start'], $param['create_time_end']]];
- unset($param['create_time_start']);
- unset($param['create_time_end']);
- }
- if (isset($param['keyword'])) {
- $where[] = ['c.name|c.phone', 'like', '%' . $param['keyword'] . '%'];
- }
- if (isset($param['status'])) {
- $where[] = ['s.status', '=', $param['status']];
- }
- $field = 's.*,FROM_UNIXTIME(s.create_time) as create_time';
- $Customer_model = new \app\admin\model\Customer();
- $result = $this->alias('s')->join($Customer_model->getTable() . ' c', 's.customer_id = c.id')->field($field)->where($where)->with(['getCustomerOneData', 'getDistrictOneData', 'getUserOneData'])->select();
- $total = $this->alias('s')->join($Customer_model->getTable() . ' c', 's.customer_id = c.id')->where($where)->count();
- foreach ($result as $k => $v) {
- switch ($v['status']) {
- case 0:
- $result[$k]['status'] = '正常';
- break;
- case 1:
- $result[$k]['status'] = '失败';
- break;
- }
- }
- return ['rows' => $result, 'total' => $total];
- }
-
- public function getDistrictOneData()
- {
- return $this->hasOne(\app\admin\model\District::class, 'adcode', 'city_id')->bind(['city_name' => 'name']);
- }
-
- public function getCustomerOneData()
- {
- return $this->hasOne(\app\admin\model\Customer::class, 'id', 'customer_id')->bind(['customer_name' => 'name', 'sex' => 'sex', 'phone' => 'phone', 'city_id' => 'city_id', 'user_id' => 'user_id']);
- }
-
- public function getUserOneData()
- {
- return $this->hasOne(\app\admin\model\User::class, 'id', 'user_id')->bind(['username' => 'username']);
- }
-
- // public function read($param)
- // {
- // $result = $this->where($this->getPk(), $param[$this->getPk()])->find();
- // if (isset($result[$this->getPk()])) {
- // return $result->toArray();
- // } else {
- // return [];
- // }
- // }
-
- }
|