StorePerfLog.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace common\models;
  3. /**
  4. * This is the model class for table "{{%STORE_PERF_LOG}}".
  5. *
  6. * @property string $ID
  7. * @property string $PERF_ORDER_ID PERF_ORDER表的ID字段值
  8. * @property string $USER_ID USER表用户ID
  9. * @property int $IS_STUDIO 是否是工作室 0 不是 1是
  10. * @property string $PV 业绩单PV
  11. * @property string $PERIOD_NUM 业绩期
  12. * @property int $CALC_MONTH 结算月份
  13. * @property int $CREATE_AT 创建时间
  14. */
  15. class StorePerfLog extends \common\components\ActiveRecord
  16. {
  17. /**
  18. * @inheritdoc
  19. */
  20. public static function tableName()
  21. {
  22. return '{{%STORE_PERF_LOG}}';
  23. }
  24. /**
  25. * @inheritdoc
  26. */
  27. public function rules()
  28. {
  29. return [
  30. [['USER_ID', 'IS_STUDIO', 'CREATED_AT'], 'required'],
  31. [['ID'], 'unique'],
  32. ];
  33. }
  34. /**
  35. * @inheritdoc
  36. */
  37. public function attributeLabels()
  38. {
  39. return [
  40. 'ID' => 'ID',
  41. 'PERF_ORDER_ID' => 'PERF_ORDER表的ID字段值',
  42. 'USER_ID' => 'USER表用户ID',
  43. 'IS_STUDIO' => '是否是工作室 0 不是 1是',
  44. 'PV' => '业绩单PV',
  45. 'PERIOD_NUM' => '业绩期',
  46. 'CALC_MONTH' => '结算月份',
  47. 'CREATE_AT' => '创建时间',
  48. ];
  49. }
  50. // 更新或者添加业绩数据
  51. /**
  52. * @param $periodNum 结算业绩期
  53. * @param $calcMonth 结算月
  54. * @param $userId 结算过程中的用户
  55. * @param $data 数据
  56. * @param $appendPv 往上找店铺,需要给店铺的PV值
  57. */
  58. public static function addOrUpdate($periodNum, $calcMonth, $userId, $data, $appendPv = 0) {
  59. $info = StorePerfLog::findUseDbCalc()
  60. ->select('ID')
  61. ->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM AND CALC_MONTH=:CALC_MONTH',
  62. [':USER_ID'=>$userId,':PERIOD_NUM' => $periodNum, ':CALC_MONTH' => $calcMonth]
  63. )
  64. ->asArray()
  65. ->one();
  66. if (empty($info)) {
  67. StorePerfLog::insertOne($data);
  68. } else {
  69. // 如果循环到此用户有业绩单,则将此用户的PV更新为自己业绩单的值
  70. if ($data['MONTH_PV'] > 0) {
  71. StorePerfLog::updateAll(['MONTH_PV' => $data['MONTH_PV']], 'ID=:ID', [':ID' => $info['ID']]);
  72. }
  73. }
  74. return true;
  75. }
  76. }