StoreOrderProfitsharing.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store\order;
  12. use app\common\model\BaseModel;
  13. use app\common\model\system\merchant\Merchant;
  14. class StoreOrderProfitsharing extends BaseModel
  15. {
  16. const TYPE_NAME = ['order' => '订单支付', 'presell' => '尾款支付'];
  17. const STATUS_NAME = [0 => '待分账', 1 => '已分账', -1 => '已退款', -2 => '退款失败'];
  18. public static function tablePk(): string
  19. {
  20. return 'profitsharing_id';
  21. }
  22. public static function tableName(): string
  23. {
  24. return 'store_order_profitsharing';
  25. }
  26. public function getTypeNameAttr()
  27. {
  28. return self::TYPE_NAME[$this->getAttr('type')];
  29. }
  30. public function getStatusNameAttr()
  31. {
  32. return self::STATUS_NAME[$this->status];
  33. }
  34. public function order()
  35. {
  36. return $this->hasOne(StoreOrder::class, 'order_id', 'order_id');
  37. }
  38. public function merchant()
  39. {
  40. return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
  41. }
  42. public function getProfitsharingParmas()
  43. {
  44. return [
  45. 'transaction_id' => $this->transaction_id,
  46. 'sub_mchid' => $this->merchant->sub_mchid,
  47. 'out_order_no' => $this->profitsharing_sn,
  48. 'receivers' => [
  49. [
  50. 'amount' => bcsub($this->profitsharing_price, $this->profitsharing_mer_price, 2),
  51. 'body' => '订单分账',
  52. 'receiver_account' => systemConfig('wechat_service_merid'),
  53. ]
  54. ]
  55. ];
  56. }
  57. public function getProfitsharingFinishParmas()
  58. {
  59. return [
  60. 'sub_mchid' => $this->merchant->sub_mchid,
  61. 'transaction_id' => $this->order->transaction_id,
  62. 'out_order_no' => $this->profitsharing_sn,
  63. 'description' => '订单分账',
  64. ];
  65. }
  66. }