Owner.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Builder;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsToMany;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. /**
  8. * @method static orderBy(string $string, string $string1)
  9. */
  10. use App\Traits\ModelTimeFormat;
  11. use App\Traits\ModelLogChanging;
  12. use Illuminate\Support\Facades\DB;
  13. class Owner extends Model
  14. {
  15. use ModelLogChanging;
  16. use ModelTimeFormat;
  17. public $fillable = [
  18. 'name', //名称
  19. 'code', //代码
  20. 'checking_count', //审核数量
  21. 'deleted_at', //删除时间
  22. "customer_id", //客户ID
  23. "tax_rate_id", //税率
  24. "linkman", //联系人
  25. "phone_number", //联系电话
  26. "user_owner_group_id", //项目组ID
  27. "waring_line_on", //月单量预警
  28. "description", //描述
  29. "warehouse_id", //仓库ID
  30. "user_workgroup_id", //仓库小组(工作组)
  31. "relevance", //关联模型的JSON数组
  32. 'subjection', //主体公司
  33. 'is_tax_exist', //是否必填税率
  34. 'model_sequence', //调箱序列(优先级匹配)
  35. 'is_check_asn', //是否校验ASN(收货时检查此项)
  36. 'owner_group_id', // 所属组别
  37. 'is_manual_back', // 是否开启货主订单一键回传
  38. 'interval_time', // 回传间隔时间(分钟为单位)
  39. 'last_manual_back_time', // 上次回传时间
  40. ];
  41. //relevance说明 0:仓储 1:作业 2:快递 3:物流 4:直发 5:系统 存储示例:["0","1"]存在仓储与作业计费
  42. protected $casts = [
  43. "relevance" => "array"
  44. ];
  45. const subjection=[
  46. 0=>'',
  47. 1 => "宝时物流",
  48. 2 => "宝时供应链",
  49. ];
  50. const IS_CHECK_ASN=[
  51. 0 => "否",
  52. 1 => "是"
  53. ];
  54. const IS_MANUAL_BACK=[
  55. 0 => "否",
  56. 1 => "是"
  57. ];
  58. /**
  59. * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
  60. *
  61. */
  62. public function getIncreasedCheckingCount()
  63. {
  64. $this['checking_count']=$this['checking_count']+1;
  65. $this->update();
  66. return $this['checking_count'];
  67. }
  68. public function paperBoxes(): BelongsToMany
  69. {
  70. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  71. }
  72. public function users(): BelongsToMany
  73. {
  74. return $this->belongsToMany('\App\User', 'owner_user', 'owner_id', 'user_id');
  75. }
  76. public function orderTrackingOwner(){
  77. return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
  78. }
  79. public function contracts()
  80. { //合同
  81. return $this->hasMany(OwnerContract::class,"owner_id","id");
  82. }
  83. public function order(){
  84. return $this->hasOne(Order::class,'owner_id','id');
  85. }
  86. public function customer()
  87. { //客户
  88. return $this->hasOne(Customer::class,"id","customer_id");
  89. }
  90. public function userOwnerGroup()
  91. { //项目组
  92. return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
  93. }
  94. public function userWorkGroup()
  95. { //工作组
  96. return $this->belongsTo(UserWorkgroup::class,"user_workgroup_id","id");
  97. }
  98. public function ownerAreaReport()
  99. { //面积报表
  100. return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
  101. }
  102. public function departmentObligationOwner()
  103. { //部门职能关联
  104. return $this->hasMany(DepartmentObligationOwner::class,"owner_id","id")
  105. ->selectRaw('obligation_code,obligation_id,owner_id,department_id,max(valid_time)')
  106. ->groupBy('obligation_id','owner_id','department_id')
  107. ->whereNull('failure_time');
  108. }
  109. public function ownerStoragePriceModels()
  110. { //仓储计费
  111. $query = OwnerStoragePriceModel::query()->select("target_id")
  112. ->whereNotNull("operation")->where("operation","!=","")
  113. ->whereNotNull("target_id")->where("target_id","!=","");
  114. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id")
  115. ->whereNotIn("id",$query)->where(function(Builder $query){
  116. $query->where("operation","!=","D")->orWhereNull("operation");
  117. });
  118. }
  119. public function ownerPriceOperations()
  120. { //作业计费
  121. $query = OwnerPriceOperation::query()->select("target_id")
  122. ->whereNotNull("operation")->where("operation","!=","")
  123. ->whereNotNull("target_id")->where("target_id","!=","");
  124. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id")
  125. ->whereNotIn("id",$query)->where(function(Builder $query){
  126. $query->where("operation","!=","D")->orWhereNull("operation");
  127. });
  128. }
  129. public function ownerPriceExpresses()
  130. { //快递计费
  131. $query = OwnerPriceExpress::query()->select("target_id")
  132. ->whereNotNull("operation")->where("operation","!=","")
  133. ->whereNotNull("target_id")->where("target_id","!=","");
  134. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id")
  135. ->whereNotIn("id",$query)->where(function(Builder $query){
  136. $query->where("operation","!=","D")->orWhereNull("operation");
  137. });
  138. }
  139. public function ownerPriceLogistics()
  140. { //物流计费
  141. $query = OwnerPriceLogistic::query()->select("target_id")
  142. ->whereNotNull("operation")->where("operation","!=","")
  143. ->whereNotNull("target_id")->where("target_id","!=","");
  144. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id")
  145. ->whereNotIn("id",$query)->where(function(Builder $query){
  146. $query->where("operation","!=","D")->orWhereNull("operation");
  147. });
  148. }
  149. public function ownerPriceDirectLogistics()
  150. { //直发车计费
  151. $query = OwnerPriceDirectLogistic::query()->select("target_id")
  152. ->whereNotNull("operation")->where("operation","!=","")
  153. ->whereNotNull("target_id")->where("target_id","!=","");
  154. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id")
  155. ->whereNotIn("id",$query)->where(function(Builder $query){
  156. $query->where("operation","!=","D")->orWhereNull("operation");
  157. });
  158. }
  159. public function ownerPriceSystem()
  160. { //系统计费
  161. $query = OwnerPriceSystem::query()->select("target_id")
  162. ->whereNotNull("operation")->where("operation","!=","")
  163. ->whereNotNull("target_id")->where("target_id","!=","");
  164. return $this->hasOne(OwnerPriceSystem::class,"owner_id","id")
  165. ->whereNotIn("id",$query)->where(function(Builder $query){
  166. $query->where("operation","!=","D")->orWhereNull("operation");
  167. });
  168. }
  169. public function warehouse()
  170. { //仓库
  171. return $this->belongsTo(Warehouse::class,"warehouse_id","id");
  172. }
  173. public function ownerMaterials()
  174. { //耗材
  175. return $this->hasMany(OwnerMaterial::class,"owner_id","id");
  176. }
  177. public function taxRate()
  178. { //税率
  179. return $this->belongsTo(TaxRate::class);
  180. }
  181. public function storageAudit()
  182. { //审核的仓储模型
  183. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner")
  184. ->select(DB::raw(1))->whereNotNull("operation")
  185. ->where("operation","!=","")->groupBy("owner_id");
  186. }
  187. public function operationAudit()
  188. { //审核的作业模型
  189. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner")
  190. ->select(DB::raw(1))->whereNotNull("operation")
  191. ->where("operation","!=","")->groupBy("owner_id");
  192. }
  193. public function expressAudit()
  194. { //审核的快递模型
  195. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner")
  196. ->select(DB::raw(1))->whereNotNull("operation")
  197. ->where("operation","!=","")->groupBy("owner_id");
  198. }
  199. public function logisticAudit()
  200. { //审核的物流模型
  201. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner")
  202. ->select(DB::raw(1))->whereNotNull("operation")
  203. ->where("operation","!=","")->groupBy("owner_id");
  204. }
  205. public function directLogisticAudit()
  206. { //审核的直发模型
  207. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner")
  208. ->select(DB::raw(1))->whereNotNull("operation")
  209. ->where("operation","!=","")->groupBy("owner_id");
  210. }
  211. public function systemAudit()
  212. { //审核的直发模型
  213. return $this->hasOne(OwnerPriceSystem::class,"owner_id","id")
  214. ->select(DB::raw(1))->whereNotNull("operation")
  215. ->where("operation","!=","");
  216. }
  217. public function ownerSundryFeeDetail(): HasMany
  218. {
  219. return $this->hasMany(OwnerSundryFeeDetail::class);
  220. }
  221. public function roles()
  222. { //角色
  223. return $this->belongsToMany(Role::class);
  224. }
  225. }