|
- <?php
- /**
- * 数据库表类 order_contacts
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm LoginController.php
- * Create By 2017/06/15 11:02 $
- */
-
- namespace common\models;
-
- use yii\db\ActiveRecord;
- use yii\db\Expression;
-
- /**
- * 数据库表类 order_contacts.
- * @property integer $id
- * @property integer $order_id
- * @property string $contacts_name
- * @property string $contacts_phone
- * @property string $contacts_ID
- * @property integer $contacts_type
- * @property string $update_time
- * @property string $create_time
- * @property integer $delete_flag
- * @property integer $bus_run_id
- */
- class OrderContacts extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'order_contacts';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['order_id', 'contacts_name'], 'required'],
- [['order_id', 'contacts_type', 'delete_flag', 'bus_run_id'], 'integer'],
- [['update_time', 'create_time'], 'safe'],
- [['contacts_name'], 'string', 'max' => 120],
- [['insurance_price'], 'number'],
- [['contacts_phone', 'contacts_ID'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'order_id' => 'Order ID',
- 'contacts_name' => 'Contacts Name',
- 'contacts_phone' => 'Contacts Phone',
- 'contacts_ID' => 'Contacts ID',
- 'contacts_type' => 'Contacts Type',
- 'update_time' => 'Update Time',
- 'create_time' => 'Create Time',
- 'delete_flag' => 'Delete Flag',
- 'bus_run_id' => 'Bus Run ID',
- 'insurance_price' => 'insurance_price'
- ];
- }
-
- /**
- * Des:获取订单拓展信息
- * Name: getRowByOrderId
- * @param $orderId
- * @return array
- * @author 倪宗锋
- */
- public function getRowByOrderId($orderId)
- {
- $where = [
- 'and',
- ['=', 'contacts_type', 1],
- ['=', 'order_id', $orderId]
- ];
- $return = $this->find()->select(['contacts_name', 'contacts_phone', 'contacts_ID', 'contacts_type', 'bus_run_id', 'order_id'])
- ->from(static::tableName())
- ->where($where)
- ->asArray(true)
- ->one();
- return $return;
- }
-
- /**
- * Function Description:插入联系人表
- * Function Name: insertContacts
- * @param $param_arr
- * @param $orderId
- *
- * @return bool
- *
- * @author 娄梦宁
- */
- public function insertContacts($param_arr, $orderId)
- {
- $values = [
- 'order_id' => $orderId,
- 'contacts_name' => $param_arr['contacts_name'],
- 'contacts_phone' => $param_arr['contacts_phone'],
- 'contacts_ID' => empty($param_arr['contacts_ID']) ? '' : $param_arr['contacts_ID'],
- 'bus_run_id' => empty($param_arr['run_id']) ? 0 : $param_arr['run_id'],
- 'create_time' => date('Y-m-d H:i:s'),
- ];
- $this->attributes = $values;
- $res = $this->insert();
- if (!$res) {
- return false;
- }
- return true;
- }
-
- /**
- * Function Description:获取投保人数
- * Function Name: getContactsNum
- * @param $order_id
- *
- * @return int|string
- *
- * @author 李健
- */
- public function getContactsNum($order_id)
- {
- $where = ['and'];
- $where[] = ['=', 'order_id', $order_id];
- $where[] = ['=', 'contacts_type', 2];
- $where[] = ['=', 'delete_flag', 0];
- $res = self::find()->from(self::tableName())->where($where)->count();
- return $res;
- }
-
-
- /**
- * Des:保险 统计
- * Name: getInsuranceCnt
- * @param $order_ids
- * @return array|null|ActiveRecord
- * @author 倪宗锋
- */
- public function getInsuranceCnt($order_ids)
- {
- $where = ['and'];
- $where[] = ['in', 'order_id', $order_ids];
- $where[] = ['=', 'contacts_type', 2];
- $where[] = ['=', 'delete_flag', 0];
- $select = [
- 'cnt' => new Expression("count(1)"),
- 'unit_price' => 'insurance_price',
- 'prod_name' => new Expression("'乘意险'")
- ];
- $res = self::find()->select($select)
- ->where($where)
- ->having(['!=', 'cnt', '0'])
- ->asArray()
- ->all();
- if (empty($res[0])) {
- return [];
- }
- return $res;
- }
-
- /**
- * Function Description:添加受保人信息
- * Function Name: addInsuredPeople
- * @param $param
- * @param $orderId
- * @return bool
- * @author 田玲菲
- */
- public function addInsuredPeople($param, $orderId)
- {
- $values = [
- 'order_id' => $orderId,
- 'contacts_name' => $param['contacts_name'],
- 'contacts_ID' => empty($param['contacts_ID']) ? '' : $param['contacts_ID'],
- 'bus_run_id' => empty($param['run_id']) ? 0 : $param['run_id'],
- 'create_time' => date('Y-m-d H:i:s'),
- 'contacts_type' => 2,
- 'insurance_price' => $param['insurance_price']
- ];
- $clone=clone $this;
- $clone->attributes = $values;
- $res = $clone->insert();
- if (!$res) {
- return false;
- }
- return true;
- }
-
-
- /**
- * Function Description:查询受保人信息
- * Function Name: getInsuredPeople
- * @param $orderId
- * @return array|ActiveRecord[]
- * @author 田玲菲
- */
- public function getInsuredPeople($orderId)
- {
- $select = [
- 'contacts_name',
- 'contacts_ID',
- ];
- $where = ['and'];
- $where[] = ['=', 'delete_flag', 0];
- $where[] = ['=', 'order_id', $orderId];
- $where[] = ['=', 'contacts_type', 2];
- $result = self::find()->from(self::tableName())->select($select)->where($where)->asArray()->all();
- return $result;
- }
-
- /**
- * Function Description:添加乘车人信息
- * Function Name: addInsuredPeople
- * @param $param
- * @param $orderId
- * @return bool
- * @author 倪宗锋
- */
- public function addPassAngerPeople($param, $orderId)
- {
- $values = [
- 'order_id' => $orderId,
- 'contacts_name' => $param['contacts_name'],
- 'contacts_ID' => empty($param['contacts_ID']) ? '' : $param['contacts_ID'],
- 'bus_run_id' => empty($param['run_id']) ? 0 : $param['run_id'],
- 'create_time' => date('Y-m-d H:i:s'),
- 'contacts_type' => 3
- ];
- $this->attributes = $values;
- $res = $this->insert();
- if (!$res) {
- return false;
- }
- return true;
- }
-
- /**
- * Function Description:查询乘车人信息
- * Function Name: getInsuredPeople
- * @param $orderId
- * @return array
- * @author 倪宗锋
- */
- public function getPassAngerPeople($orderId)
- {
- $select = [
- 'contacts_name',
- 'contacts_ID',
- ];
- $where = ['and'];
- $where[] = ['=', 'delete_flag', 0];
- $where[] = ['=', 'order_id', $orderId];
- $where[] = ['=', 'contacts_type', 3];
- $result = self::find()->from(self::tableName())->select($select)->where($where)->asArray()->all();
- return $result;
- }
- }
|