Supplier.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\common\model\supplier;
  3. use app\common\model\BaseModel;
  4. use think\facade\Cache;
  5. /**
  6. * 商家供应商模型
  7. */
  8. class Supplier extends BaseModel
  9. {
  10. protected $name = 'supplier';
  11. protected $pk = 'shop_supplier_id';
  12. /**
  13. * 关联应用表
  14. */
  15. public function app()
  16. {
  17. return $this->belongsTo('app\\common\\model\\app\\App', 'app_id', 'app_id');
  18. }
  19. /**
  20. * 关联logo
  21. */
  22. public function logo()
  23. {
  24. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'logo_id');
  25. }
  26. /**
  27. * 关联品牌类型
  28. */
  29. public function category()
  30. {
  31. return $this->hasOne('app\\common\\model\\supplier\\Category', 'category_id', 'category_id');
  32. }
  33. /**
  34. * 关联business
  35. */
  36. public function business()
  37. {
  38. return $this->hasOne('app\\common\\model\\file\\UploadFile', 'file_id', 'business_id');
  39. }
  40. /**
  41. * 关联超管
  42. */
  43. public function superUser()
  44. {
  45. return $this->hasOne('app\\common\\model\\supplier\\User', 'shop_supplier_id', 'shop_supplier_id')
  46. ->where('is_super','=', 1);
  47. }
  48. /**
  49. * 详情
  50. */
  51. public static function detail($shop_supplier_id, $with = [])
  52. {
  53. return (new static())->with($with)->find($shop_supplier_id);
  54. }
  55. /**
  56. * 累积供应商结算金额 (批量)
  57. */
  58. public function onBatchIncSupplierMoney($data)
  59. {
  60. foreach ($data as $supplierId => $supplierMoney) {
  61. $this->where(['shop_supplier_id' => $supplierId])
  62. ->inc('total_money', $supplierMoney)
  63. ->inc('money', $supplierMoney)
  64. ->update();
  65. }
  66. return true;
  67. }
  68. /**
  69. * 获取商家抖音推广口令
  70. * @param $shop_supplier_id 商家ID
  71. * @param int $app_id 平台ID
  72. * @return false|mixed|string
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public static function getDyLink($shop_supplier_id, $app_id=0){
  78. $data = Cache::get('supplier:dyLink:link_' . $app_id . '_' . $shop_supplier_id);
  79. if($data){
  80. return $data;
  81. }
  82. $where = ['shop_supplier_id'=> $shop_supplier_id];
  83. if($app_id){
  84. $where['app_id'] = $app_id;
  85. }
  86. $data = (new static())->where($where)->field('name,dy_name,dy_link')->find();
  87. $name = isset($data['name'])? $data['name'] : '';
  88. $dy_name = isset($data['dy_name'])? $data['dy_name'] : '';
  89. $dy_link = isset($data['dy_link'])? $data['dy_link'] : '';
  90. if(empty($dy_link)){
  91. return false;
  92. }
  93. $shop_name = $dy_name? $dy_name : $name;
  94. $link = rand(1,10)."【{$shop_name}的个人主页】点击打开{$dy_link} 或长按复制此条消息,打开抖音,查看TA的更多作品。";
  95. Cache::tag('cache')->set('supplier:dyLink:link_' . $app_id . '_' . $shop_supplier_id, $link, rand(10, 30));
  96. return $link;
  97. }
  98. }