PointSetLog.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/3
  6. * Time: 13:55
  7. */
  8. namespace app\common\services\operation;
  9. class PointSetLog extends OperationBase
  10. {
  11. public $modules = 'finance';
  12. public $type = 'point';
  13. protected function modifyDefault()
  14. {
  15. if (isset($this->model['type'])) {
  16. $this->setLog('mark', $this->model['type']);
  17. } else {
  18. $this->setLog('mark', 'point.set');
  19. }
  20. }
  21. protected function special()
  22. {
  23. }
  24. /**
  25. * 获取模型需要记录的字段
  26. * @return mixed
  27. */
  28. protected function recordField()
  29. {
  30. return [
  31. 'point_transfer' => ['field_name'=>'积分转让', 0=>'关闭', 1=>'开启' ],
  32. 'point_deduct' => ['field_name'=>'积分抵扣', 0=>'关闭', 1=>'开启' ],
  33. 'point_rollback' => ['field_name'=>'积分抵扣', 0=>'关闭', 1=>'开启' ],
  34. 'point_freight' => ['field_name'=>'积分抵扣运费', 0=>'关闭', 1=>'开启' ],
  35. 'money' => '积分抵扣比例(元)',
  36. 'money_max' => '积分商品最高抵扣%',
  37. 'give_point' => '购买商品赠送积分',
  38. 'enough_money_and_enough_point' => '消费赠送',
  39. ];
  40. }
  41. /**
  42. * 获取模型修改了哪些字段
  43. * @param object array
  44. * @return array
  45. */
  46. protected function modifyField()
  47. {
  48. $model = $this->model;
  49. $keys = array_keys($this->recordField());
  50. array_push($keys, 'enough_money', 'enough_point');
  51. $old = array_only($model['old'], $keys);
  52. $new = array_only($model['new'], $keys);
  53. if (empty($old) || empty($new)) {
  54. return [];
  55. }
  56. if (($old['enough_money'] != $new['enough_money']) || ($old['enough_point'] != $new['enough_point']) ) {
  57. $this->modify_fields['enough_money_and_enough_point']['old_content'] = '单笔订单满'.$old['enough_money'].'元 赠送'.$old['enough_point'].'积分';
  58. $this->modify_fields['enough_money_and_enough_point']['new_content'] = '单笔订单满'.$new['enough_money'].'元 赠送'.$new['enough_point'].'积分';
  59. }
  60. foreach ($this->recordField() as $key => $item) {
  61. if ($old[$key] != $new[$key]) {
  62. $this->modify_fields[$key]['old_content'] = $old[$key];
  63. $this->modify_fields[$key]['new_content'] = $new[$key];
  64. }
  65. }
  66. return $this->modify_fields;
  67. }
  68. }