Deposit.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace backend\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "crm_deposit".
  6. *
  7. * @property integer $id
  8. * @property integer $type
  9. * @property integer $member_id
  10. * @property string $amount
  11. * @property string $rmb
  12. * @property string $rate
  13. * @property string $memo
  14. * @property integer $in_time
  15. * @property string $pay_name
  16. * @property integer $login
  17. * @property string $admin_name
  18. */
  19. class Deposit extends \yii\db\ActiveRecord
  20. {
  21. /**
  22. * @inheritdoc
  23. */
  24. public static function tableName()
  25. {
  26. return 'crm_deposit';
  27. }
  28. /**
  29. * @return \yii\db\Connection the database connection used by this AR class.
  30. */
  31. public static function getDb()
  32. {
  33. return Yii::$app->get('dbXcrm');
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['type', 'member_id', 'amount', 'rmb', 'rate', 'in_time', 'pay_name', 'login', 'order_sn'], 'required'],
  42. [['type', 'member_id', 'in_time', 'login'], 'integer'],
  43. [['amount', 'rmb', 'rate'], 'number'],
  44. [['memo', 'pay_name', 'admin_name', 'order_sn'], 'string', 'max' => 255],
  45. ];
  46. }
  47. /**
  48. * @inheritdoc
  49. */
  50. public function attributeLabels()
  51. {
  52. return [
  53. 'id' => '主键ID',
  54. 'type' => '出金类型',
  55. 'member_id' => '代理商ID',
  56. 'amount' => '金额',
  57. 'rmb' => '人民币数',
  58. 'rate' => '汇率',
  59. 'memo' => '备注',
  60. 'in_time' => '创建时间',
  61. 'pay_name' => '支付方式',
  62. 'login' => '登录ID',
  63. 'admin_name' => '操作人',
  64. 'order_sn' => '支付订单号',
  65. ];
  66. }
  67. /**
  68. * 统计入金金额
  69. * @param int $type
  70. * @return mixed
  71. */
  72. public static function sumDepositByType($type)
  73. {
  74. return static::find()->where(['type' => $type])->sum('amount');
  75. }
  76. /**
  77. * @param int $id
  78. * @return array|null|\yii\db\ActiveRecord|Deposit
  79. */
  80. public static function findById($id)
  81. {
  82. return static::find()->where(['id' => $id])->limit(1)->one();
  83. }
  84. }