Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

275 wiersze
7.8 KiB

  1. <?php
  2. /**
  3. * 数据库表类 order_contacts
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm LoginController.php
  13. * Create By 2017/06/15 11:02 $
  14. */
  15. namespace common\models;
  16. use yii\db\ActiveRecord;
  17. use yii\db\Expression;
  18. /**
  19. * 数据库表类 order_contacts.
  20. * @property integer $id
  21. * @property integer $order_id
  22. * @property string $contacts_name
  23. * @property string $contacts_phone
  24. * @property string $contacts_ID
  25. * @property integer $contacts_type
  26. * @property string $update_time
  27. * @property string $create_time
  28. * @property integer $delete_flag
  29. * @property integer $bus_run_id
  30. */
  31. class OrderContacts extends ActiveRecord
  32. {
  33. /**
  34. * @inheritdoc
  35. */
  36. public static function tableName()
  37. {
  38. return 'order_contacts';
  39. }
  40. /**
  41. * @inheritdoc
  42. */
  43. public function rules()
  44. {
  45. return [
  46. [['order_id', 'contacts_name'], 'required'],
  47. [['order_id', 'contacts_type', 'delete_flag', 'bus_run_id'], 'integer'],
  48. [['update_time', 'create_time'], 'safe'],
  49. [['contacts_name'], 'string', 'max' => 120],
  50. [['insurance_price'], 'number'],
  51. [['contacts_phone', 'contacts_ID'], 'string', 'max' => 20],
  52. ];
  53. }
  54. /**
  55. * @inheritdoc
  56. */
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'order_id' => 'Order ID',
  62. 'contacts_name' => 'Contacts Name',
  63. 'contacts_phone' => 'Contacts Phone',
  64. 'contacts_ID' => 'Contacts ID',
  65. 'contacts_type' => 'Contacts Type',
  66. 'update_time' => 'Update Time',
  67. 'create_time' => 'Create Time',
  68. 'delete_flag' => 'Delete Flag',
  69. 'bus_run_id' => 'Bus Run ID',
  70. 'insurance_price' => 'insurance_price'
  71. ];
  72. }
  73. /**
  74. * Des:获取订单拓展信息
  75. * Name: getRowByOrderId
  76. * @param $orderId
  77. * @return array
  78. * @author 倪宗锋
  79. */
  80. public function getRowByOrderId($orderId)
  81. {
  82. $where = [
  83. 'and',
  84. ['=', 'contacts_type', 1],
  85. ['=', 'order_id', $orderId]
  86. ];
  87. $return = $this->find()->select(['contacts_name', 'contacts_phone', 'contacts_ID', 'contacts_type', 'bus_run_id', 'order_id'])
  88. ->from(static::tableName())
  89. ->where($where)
  90. ->asArray(true)
  91. ->one();
  92. return $return;
  93. }
  94. /**
  95. * Function Description:插入联系人表
  96. * Function Name: insertContacts
  97. * @param $param_arr
  98. * @param $orderId
  99. *
  100. * @return bool
  101. *
  102. * @author 娄梦宁
  103. */
  104. public function insertContacts($param_arr, $orderId)
  105. {
  106. $values = [
  107. 'order_id' => $orderId,
  108. 'contacts_name' => $param_arr['contacts_name'],
  109. 'contacts_phone' => $param_arr['contacts_phone'],
  110. 'contacts_ID' => empty($param_arr['contacts_ID']) ? '' : $param_arr['contacts_ID'],
  111. 'bus_run_id' => empty($param_arr['run_id']) ? 0 : $param_arr['run_id'],
  112. 'create_time' => date('Y-m-d H:i:s'),
  113. ];
  114. $this->attributes = $values;
  115. $res = $this->insert();
  116. if (!$res) {
  117. return false;
  118. }
  119. return true;
  120. }
  121. /**
  122. * Function Description:获取投保人数
  123. * Function Name: getContactsNum
  124. * @param $order_id
  125. *
  126. * @return int|string
  127. *
  128. * @author 李健
  129. */
  130. public function getContactsNum($order_id)
  131. {
  132. $where = ['and'];
  133. $where[] = ['=', 'order_id', $order_id];
  134. $where[] = ['=', 'contacts_type', 2];
  135. $where[] = ['=', 'delete_flag', 0];
  136. $res = self::find()->from(self::tableName())->where($where)->count();
  137. return $res;
  138. }
  139. /**
  140. * Des:保险 统计
  141. * Name: getInsuranceCnt
  142. * @param $order_ids
  143. * @return array|null|ActiveRecord
  144. * @author 倪宗锋
  145. */
  146. public function getInsuranceCnt($order_ids)
  147. {
  148. $where = ['and'];
  149. $where[] = ['in', 'order_id', $order_ids];
  150. $where[] = ['=', 'contacts_type', 2];
  151. $where[] = ['=', 'delete_flag', 0];
  152. $select = [
  153. 'cnt' => new Expression("count(1)"),
  154. 'unit_price' => 'insurance_price',
  155. 'prod_name' => new Expression("'乘意险'")
  156. ];
  157. $res = self::find()->select($select)
  158. ->where($where)
  159. ->having(['!=', 'cnt', '0'])
  160. ->asArray()
  161. ->all();
  162. if (empty($res[0])) {
  163. return [];
  164. }
  165. return $res;
  166. }
  167. /**
  168. * Function Description:添加受保人信息
  169. * Function Name: addInsuredPeople
  170. * @param $param
  171. * @param $orderId
  172. * @return bool
  173. * @author 田玲菲
  174. */
  175. public function addInsuredPeople($param, $orderId)
  176. {
  177. $values = [
  178. 'order_id' => $orderId,
  179. 'contacts_name' => $param['contacts_name'],
  180. 'contacts_ID' => empty($param['contacts_ID']) ? '' : $param['contacts_ID'],
  181. 'bus_run_id' => empty($param['run_id']) ? 0 : $param['run_id'],
  182. 'create_time' => date('Y-m-d H:i:s'),
  183. 'contacts_type' => 2,
  184. 'insurance_price' => $param['insurance_price']
  185. ];
  186. $clone=clone $this;
  187. $clone->attributes = $values;
  188. $res = $clone->insert();
  189. if (!$res) {
  190. return false;
  191. }
  192. return true;
  193. }
  194. /**
  195. * Function Description:查询受保人信息
  196. * Function Name: getInsuredPeople
  197. * @param $orderId
  198. * @return array|ActiveRecord[]
  199. * @author 田玲菲
  200. */
  201. public function getInsuredPeople($orderId)
  202. {
  203. $select = [
  204. 'contacts_name',
  205. 'contacts_ID',
  206. ];
  207. $where = ['and'];
  208. $where[] = ['=', 'delete_flag', 0];
  209. $where[] = ['=', 'order_id', $orderId];
  210. $where[] = ['=', 'contacts_type', 2];
  211. $result = self::find()->from(self::tableName())->select($select)->where($where)->asArray()->all();
  212. return $result;
  213. }
  214. /**
  215. * Function Description:添加乘车人信息
  216. * Function Name: addInsuredPeople
  217. * @param $param
  218. * @param $orderId
  219. * @return bool
  220. * @author 倪宗锋
  221. */
  222. public function addPassAngerPeople($param, $orderId)
  223. {
  224. $values = [
  225. 'order_id' => $orderId,
  226. 'contacts_name' => $param['contacts_name'],
  227. 'contacts_ID' => empty($param['contacts_ID']) ? '' : $param['contacts_ID'],
  228. 'bus_run_id' => empty($param['run_id']) ? 0 : $param['run_id'],
  229. 'create_time' => date('Y-m-d H:i:s'),
  230. 'contacts_type' => 3
  231. ];
  232. $this->attributes = $values;
  233. $res = $this->insert();
  234. if (!$res) {
  235. return false;
  236. }
  237. return true;
  238. }
  239. /**
  240. * Function Description:查询乘车人信息
  241. * Function Name: getInsuredPeople
  242. * @param $orderId
  243. * @return array
  244. * @author 倪宗锋
  245. */
  246. public function getPassAngerPeople($orderId)
  247. {
  248. $select = [
  249. 'contacts_name',
  250. 'contacts_ID',
  251. ];
  252. $where = ['and'];
  253. $where[] = ['=', 'delete_flag', 0];
  254. $where[] = ['=', 'order_id', $orderId];
  255. $where[] = ['=', 'contacts_type', 3];
  256. $result = self::find()->from(self::tableName())->select($select)->where($where)->asArray()->all();
  257. return $result;
  258. }
  259. }