UserBuying.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\common\model;
  3. use EasyWeChat\Kernel\Support\Str;
  4. use think\Model;
  5. //用户求购出售
  6. class UserBuying extends Model
  7. {
  8. protected $name = "user_buying";
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'create_time';
  13. protected $updateTime = 'update_time';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'create_time_text',
  18. 'update_time_text'
  19. ];
  20. const DefaultAdders =0; //默认地址
  21. const TakeAdders =1; //收货地址
  22. const Waiting = 0;
  23. const Shipped = 1;
  24. const Finish = 2;
  25. /*
  26. * 订单状态 0代发货 1已发货 2完成
  27. */
  28. public $order_status = [
  29. '-1' => '全部',
  30. self::Waiting => '待发货',
  31. self::Shipped => '已发货',
  32. self::Finish => '完成'
  33. ];
  34. //出售记录
  35. public static function getCreateUserBuying(int $uid, int $orderId, int $fromId, float $amount)
  36. {
  37. $fee = bcmul(config('market_transfer.serve_fee'), $amount, 2);
  38. $income = bcsub($amount, $fee, 2);
  39. self::create([
  40. 'user_id' => $uid,
  41. 'order_id' => $orderId,
  42. 'from_id' => $fromId,
  43. 'amount' => $amount,
  44. 'fee' => $fee,
  45. 'income' => $income,
  46. ]);
  47. return $income;
  48. }
  49. public function getCreateTimeTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  52. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  53. }
  54. public function getUpdateTimeTextAttr($value, $data)
  55. {
  56. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  57. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  58. }
  59. protected function setCreateTimeAttr($value)
  60. {
  61. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  62. }
  63. protected function setUpdateTimeAttr($value)
  64. {
  65. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  66. }
  67. }