BalanceRecharge.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/17
  6. * Time: 下午4:10
  7. */
  8. namespace app\frontend\modules\finance\models;
  9. use \app\common\models\finance\BalanceRecharge as Recharge;
  10. use Illuminate\Database\Eloquent\Builder;
  11. class BalanceRecharge extends Recharge
  12. {
  13. //设置全局作用域
  14. public static function boot()
  15. {
  16. parent::boot();
  17. static::addGlobalScope('member_id',function (Builder $builder) {
  18. return $builder->where('member_id',\YunShop::app()->getMemberId());
  19. });
  20. }
  21. /**
  22. * 定义字段名
  23. *
  24. * @return array */
  25. public function atributeNames() {
  26. return [
  27. 'uniacid' => "公众号ID不能为空",
  28. 'member_id' => "会员ID不能为空",
  29. //'old_money' => '余额必须是有效的数字',
  30. 'money' => '充值金额必须是有效的数字,允许两位小数',
  31. 'new_money' => '计算后金额必须是有效的数字',
  32. 'type' => '未找到支付方式',
  33. 'ordersn' => '充值订单号不能为空',
  34. 'status' => '状态不能为空'
  35. ];
  36. }
  37. /**
  38. * 字段规则
  39. *
  40. * @return array */
  41. public function rules()
  42. {
  43. return [
  44. 'uniacid' => "required",
  45. 'member_id' => "required",
  46. //'old_money' => 'numeric',
  47. 'money' => 'numeric|regex:/^(?!0+(?:\.0+)?$)\d+(?:\.\d{1,2})?$/', //大于0,允许两位小数
  48. 'new_money' => 'numeric',
  49. //'type' => 'regex:/^[126789]$/', //只能匹配1,2 【1微信,2支付宝】
  50. 'type' => 'numeric',
  51. 'ordersn' => 'required',
  52. 'status' => 'required'
  53. ];
  54. }
  55. }