DiscountLog.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/1
  6. * Time: 15:33
  7. */
  8. namespace app\common\services\operation;
  9. use app\common\models\MemberLevel;
  10. class DiscountLog extends OperationBase
  11. {
  12. public $modules = 'goods';
  13. public $type = 'update';
  14. protected function modifyDefault()
  15. {
  16. $this->setLog('mark', $this->model->goods_id);
  17. }
  18. /**
  19. * 获取模型需要记录的字段
  20. * @return mixed
  21. */
  22. protected function recordField()
  23. {
  24. return [
  25. //'level_discount_type' => ['field_name' => '折扣类型',1=>'会员等级'],
  26. //'discount_method' => ['field_name' => '折扣方式',1=>'折扣', 2=>'固定金额'],
  27. 'discount_value' => '会员等级折扣',
  28. ];
  29. }
  30. /**
  31. * 获取模型修改了哪些字段
  32. * @param object array
  33. * @return array
  34. */
  35. protected function modifyField()
  36. {
  37. $model = $this->model;
  38. foreach ($this->recordField() as $key => $item) {
  39. if ($model->isDirty($key)) {
  40. if ($key == 'discount_value') {
  41. $level_name = MemberLevel::where('id', $model->level_id)->value('level_name');
  42. $level_name = is_null($level_name) ? '普通会员': $level_name;
  43. $this->modify_fields['discount_value']['old_content'] = ['key'=> $model->discount_method,1=>'折扣方式:折扣', 2=>'折扣方式:固定金额'];
  44. $this->modify_fields['discount_value']['new_content'] = ['key'=> $model->discount_method ,1=>$level_name.'(等级折扣:'.$model->discount_value.'%)', 2=>$level_name.'(等级折扣:'.$model->discount_value.'元)'];
  45. }
  46. }
  47. }
  48. return $this->modify_fields;
  49. }
  50. }