|
|
@@ -0,0 +1,120 @@
|
|
|
+<?php
|
|
|
+namespace backend\models;
|
|
|
+
|
|
|
+use Yii;
|
|
|
+
|
|
|
+/**
|
|
|
+ * This is the model class for table "crm_public_account".
|
|
|
+ *
|
|
|
+ * @property integer $id
|
|
|
+ * @property integer $add_time
|
|
|
+ * @property integer $is_close
|
|
|
+ * @property integer $is_used
|
|
|
+ * @property string $account
|
|
|
+ */
|
|
|
+class Public_account extends \yii\db\ActiveRecord
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @inheritdoc
|
|
|
+ */
|
|
|
+ public static function tableName()
|
|
|
+ {
|
|
|
+ return 'crm_public_account';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return \yii\db\Connection the database connection used by this AR class.
|
|
|
+ */
|
|
|
+ public static function getDb()
|
|
|
+ {
|
|
|
+ return Yii::$app->get('dbXcrm');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @inheritdoc
|
|
|
+ */
|
|
|
+ public function rules()
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ [['id', 'add_time','is_close','is_used'], 'number'],
|
|
|
+ [['account'], 'string'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array|bool|\yii\db\ActiveRecord[]
|
|
|
+ */
|
|
|
+ public function getAccountConfig()
|
|
|
+ {
|
|
|
+ $sql = "select account from crm_public_account where is_close = 0";
|
|
|
+ $res = static::findBySql($sql)->asArray()->all();
|
|
|
+ if(empty($res)){
|
|
|
+ return false;//没有开放的对公帐户
|
|
|
+ }
|
|
|
+ $sql = "select account from crm_public_account where is_close = 0 and is_used = 0 order by id desc limit 1";
|
|
|
+ $account_arr = static::findBySql($sql)->asArray()->all();
|
|
|
+ if(empty($account_arr)){
|
|
|
+ return $account_arr;
|
|
|
+ }else{
|
|
|
+ $sql = "update crm_public_account set is_used = 1 where is_close = 1";
|
|
|
+ Yii::$app->db->createCommand($sql)->execute();
|
|
|
+ static::getAccountConfig();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志列表数据
|
|
|
+ * @param array $post
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getList($post)
|
|
|
+ {
|
|
|
+ $result = ['code' => 0, 'data' => [], 'message' => ''];
|
|
|
+
|
|
|
+ $order = isset($post['order']) ? strtolower($post['order']) : '';
|
|
|
+ $orderBy = isset($post['orderBy']) ? strtolower($post['orderBy']) : 'desc';
|
|
|
+ $search = isset($post['search']) ? $post['search'] : '';
|
|
|
+
|
|
|
+ $start = isset($post['start']) ? (int) $post['start'] : 0;
|
|
|
+ $length = isset($post['length']) ? (int) $post['length'] : 20;
|
|
|
+ $draw = isset($post['draw']) ? $post['draw'] : 1;
|
|
|
+
|
|
|
+ $where = ['and'];
|
|
|
+ // 搜索
|
|
|
+ if ($search) {
|
|
|
+ $where[] = ['like', 'memo', $search];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 排序
|
|
|
+ $allowOrderColumn = ['id', 'admin_id', 'member_id', 'memo', 'memo_obj'];
|
|
|
+ if (in_array($order, $allowOrderColumn) && in_array($orderBy, ['asc', 'desc'])) {
|
|
|
+ if ($orderBy == 'asc') {
|
|
|
+ $orderCondition = [$order => SORT_ASC];
|
|
|
+ } else {
|
|
|
+ $orderCondition = [$order => SORT_DESC];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $orderCondition = ['id' => SORT_DESC];
|
|
|
+ }
|
|
|
+
|
|
|
+ $query = static::find();
|
|
|
+ $query->where($where)
|
|
|
+ ->orderBy($orderCondition);
|
|
|
+
|
|
|
+ $count = $query->count();
|
|
|
+ $query->offset($start)->limit($length);
|
|
|
+ $list = $query->asArray()->all();
|
|
|
+
|
|
|
+ $data['data'] = $list;
|
|
|
+ $data['draw'] = $draw;
|
|
|
+ $data['recordsFiltered'] = $count;
|
|
|
+ $data['recordsTotal'] = $count;
|
|
|
+
|
|
|
+ $result['data'] = $data;
|
|
|
+ $result['code'] = 1;
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|