UserPerformanceLogs.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace common\models;
  3. use common\helpers\Date;
  4. use Exception;
  5. /**
  6. * This is the model class for table "{{%USER_PERFORMANCE_LOGS}}".
  7. *
  8. * @property string ID
  9. * @property string USER_PERFORMANCE_ID
  10. * @property string ORDER_ID
  11. * @property double AMOUNTS
  12. * @property integer PERIOD_NUM
  13. * @property string CREATED_AT
  14. * @property string UPDATED_AT
  15. * @property string REMARK
  16. */
  17. class UserPerformanceLogs extends \common\components\ActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%USER_PERFORMANCE_LOGS}}';
  25. }
  26. /**
  27. * @inheritdoc
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['USER_PERFORMANCE_ID'], 'required'],
  33. [['AMOUNTS'], 'number'],
  34. [['UPDATED_AT', 'PERIOD_NUM'], 'integer'],
  35. [['ID'], 'string', 'max' => 32],
  36. ];
  37. }
  38. /**
  39. * @inheritdoc
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'ID' => 'ID',
  45. 'USER_PERFORMANCE_ID' => '奖金ID',
  46. 'AMOUNTS' => '金额',
  47. 'CREATED_AT' => '修改时间',
  48. ];
  49. }
  50. /**
  51. * @throws Exception
  52. */
  53. public static function changeAmountLogs($prpId, $amount, $periodNum, $orderId = '', $remark = '')
  54. {
  55. $id = Date::today('Ymd') . self::_random(10, 1);
  56. self::insertOne([
  57. 'ID' => $id,
  58. 'USER_PERFORMANCE_ID' => $prpId,
  59. 'ORDER_ID' => $orderId,
  60. 'AMOUNTS' => $amount,
  61. 'PERIOD_NUM' => $periodNum,
  62. 'REMARK' => $remark,
  63. 'CREATED_AT' => date('Y-m-d H:i:s', time()),
  64. 'UPDATED_AT' => date('Y-m-d H:i:s', time()),
  65. ]);
  66. }
  67. private static function _random($length, $numeric = 0) {
  68. $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
  69. $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
  70. $hash = '';
  71. $max = strlen($seed) - 1;
  72. for ($i = 0; $i < $length; $i++) {
  73. $hash .= $seed[mt_rand(0, $max)];
  74. }
  75. return $hash;
  76. }
  77. }