Technical.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class Technical extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'technical';
  9. public static function getTitle($uuid)
  10. {
  11. $data = self::where('uuid', $uuid)->whereNotNull('uuid')->find();
  12. return $data->title;
  13. }
  14. public static function getTitlebyuid($uid)
  15. {
  16. $data = self::where('uid', $uid)->find();
  17. return $data->title;
  18. }
  19. public static function getcityName($uuid)
  20. {
  21. $data = self::where('uuid', $uuid)->whereNotNull('uuid')->find();
  22. return $data->city_name;
  23. }
  24. public static function getTel($uuid)
  25. {
  26. $data = self::where('uuid', $uuid)->whereNotNull('uuid')->find();
  27. return $data->tel;
  28. }
  29. public static function getInfobyuid($uid)
  30. {
  31. $uuid = UuidRelation::getuuid($uid, 'technical');
  32. if (!empty($uuid)) {
  33. $data = Technical::where(['uuid' => $uuid])->find();
  34. if (!empty($data)) {
  35. $data = $data->toArray();
  36. } else {
  37. $data = Technical::where(['uid' => $uid])->find();
  38. if (!empty($data)) {
  39. $data = $data->toArray();
  40. if (!empty($uuid)) {
  41. Technical::where('id', $data['id'])->update(['uuid' => $uuid]);
  42. }
  43. }
  44. }
  45. }
  46. return $data;
  47. }
  48. public static function getInfo($uuid)
  49. {
  50. $data = self::where('uuid', $uuid)->whereNotNull('uuid')->find();
  51. if (!empty($data)) {
  52. $data = $data->toArray();
  53. }
  54. return $data;
  55. }
  56. public static function conversion($vo)
  57. {
  58. $vo['cate_ids'] = Category::getmultiple($vo['cate_ids']) ?? '无';
  59. $vo['level'] = TechnicalLevel::getTitle($vo['level']) ?? '初级';
  60. $vo['sid'] = Store::getTitle($vo['sid']) ?? '平台';
  61. if (!empty($vo['uuid'])) {
  62. $vo['username'] = Users::getusername($vo['uuid']);
  63. }
  64. $vo['touxiang'] = toimg($vo['touxiang']);
  65. if (!empty($vo['photoalbum'])) {
  66. $vo['photoalbum'] = toimg(explode(',', $vo['photoalbum'])[0]);
  67. }
  68. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  69. $vo['end_time'] = time_format($vo['end_time']) ?? '长期';
  70. return $vo;
  71. }
  72. public static function getpcarray($sid)
  73. {
  74. $data = self::field('uuid,title')->where(['weid' => weid(), 'sid' => (int)$sid, 'status' => 1])->select()->toArray();
  75. $datalist = [];
  76. foreach ($data as $key => $vo) {
  77. if (!empty($vo['uuid'])) {
  78. $datalist[$key]['val'] = $vo['uuid'];
  79. $datalist[$key]['key'] = $vo['title'];
  80. }
  81. }
  82. return $datalist;
  83. }
  84. public static function getstaff($sid, $cate_ids, $cityName)
  85. {
  86. $query = new self;
  87. if (!empty($cate_ids)) {
  88. foreach ((array) (explode(',', $cate_ids)) as $catevo) {
  89. if ($catevo) {
  90. $query->whereOr('cate_ids', 'find in set', $catevo);
  91. }
  92. }
  93. }
  94. $orderidsarray = $query->field('id')->select()->toArray();
  95. foreach ($orderidsarray as $ovo) {
  96. if (empty($orderids)) {
  97. $orderids = $ovo['id'];
  98. } else {
  99. $orderids = $orderids . "," . $ovo['id'];
  100. }
  101. }
  102. $resquery = self::field('id,city_name,level,uuid,cate_ids,title')->where('is_business', 1)->where('id', 'in', $orderids)->where(['weid' => weid(), 'city_name' => $cityName, 'status' => 1]);
  103. if (!empty($sid)) {
  104. $resquery->where(['sid' => (int)$sid]);
  105. }
  106. $data = $resquery->select()->toArray();
  107. return $data;
  108. }
  109. public static function getpcarraydetailed($sid, $cate_ids, $cityName)
  110. {
  111. $data = self::getstaff($sid, $cate_ids, $cityName);
  112. $datalist = [];
  113. foreach ($data as $key => $vo) {
  114. if (!empty($vo['uuid'])) {
  115. $strlevel = TechnicalLevel::getTitle($vo['level']) ?? '初级';
  116. $datalist[$key]['val'] = $vo['uuid'];
  117. $datalist[$key]['key'] = $vo['title'] . '--[' . $strlevel . ']' . '[已接单量:' . OrderStaff::ordercount($vo['uuid']) . '][可接服务:' . Category::getmultiple($vo['cate_ids']) . ']';
  118. }
  119. }
  120. return $datalist;
  121. }
  122. public static function gelist_bycitycate($orderInfo)
  123. {
  124. $where['weid'] = weid();
  125. $where['status'] = 1;
  126. $Configdata = Config::getconfig();
  127. if (empty($Configdata['locationscope'])) {
  128. $Configdata['locationscope'] = 3;
  129. }
  130. if ($Configdata['locationscope'] == 3) {
  131. $where['district_name'] = $orderInfo['shipping_district_name'];
  132. } else if ($Configdata['locationscope'] == 2) {
  133. $where['city_name'] = $orderInfo['shipping_city_name'];
  134. } else if ($Configdata['locationscope'] == 1) {
  135. $where['province_name'] = $orderInfo['shipping_province_name'];
  136. }
  137. $query = Technical::where($where);
  138. $query->where('cate_ids', 'find in set', $orderInfo['cate_ids']);
  139. $Sort = 'id desc';
  140. $data = $query->order($Sort)->select()->toArray();
  141. return $data;
  142. }
  143. public static function getdiy_bycat($cat = 0, $count = 4, $goodsSort = "all")
  144. {
  145. $where['weid'] = weid();
  146. $where['status'] = 1;
  147. if ($cat > 0) {
  148. if (!empty($cat)) {
  149. $where['category_id'] = Category::getsonid($cat);
  150. }
  151. }
  152. $query = Technical::where($where);
  153. $Sort = 'id desc';
  154. $data = $query->limit($count)
  155. ->order($Sort)->select()->toArray();
  156. return $data;
  157. }
  158. public static function setIncome($order_info)
  159. {
  160. $uuid = OrderStaff::getuuid($order_info['id']);
  161. if (!empty($uuid)) {
  162. $Technical = Technical::where(['uuid' => $uuid])->find();
  163. if (!empty($Technical)) {
  164. $Technical = $Technical->toArray();
  165. }
  166. if (!empty($Technical['status'])) {
  167. $percent = TechnicalLevel::getPercent($Technical['level']);
  168. if (empty($percent)) {
  169. $percent = Config::getconfig('technical')['return_percent'];
  170. }
  171. //如果是商户的师傅,分佣比较需要减去商户的佣金
  172. if (!empty($Technical['sid'])) {
  173. $Store = Store::find($Technical['sid']);
  174. if (!empty($Store)) {
  175. $Store = $Store->toArray();
  176. $storepercent = StoreCate::getPercent($Store['stid']);
  177. if (empty($storepercent)) {
  178. $storepercent = Config::getconfig('store')['return_percent'];
  179. }
  180. if (!empty($storepercent)) {
  181. $percent = $percent - $storepercent;
  182. }
  183. }
  184. }
  185. if ($percent > 0) {
  186. if (empty($order_info['cat_id'])) {
  187. $income = OrderGoods::getCommission($order_info, '', $percent);
  188. } else {
  189. $income = $order_info['total'];
  190. $income = ($income * percent_to_num($percent));
  191. }
  192. $return_percent = $percent;
  193. if ($income > 0) {
  194. if ($income > 0 && $income < 0.01) {
  195. $income = 0.01;
  196. }
  197. $TechnicalIncomelog = TechnicalIncomelog::where([
  198. 'uuid' => $uuid,
  199. 'weid' => $order_info['weid'],
  200. 'order_id' => $order_info['id'],
  201. ])->find();
  202. if (empty($TechnicalIncomelog)) {
  203. Technical::where('uuid', $uuid)->inc('income', $income)->update();
  204. Technical::where('uuid', $uuid)->inc('total_income', $income)->update();
  205. $incomedata['uuid'] = $uuid;
  206. $incomedata['ptype'] = 1;
  207. $incomedata['weid'] = $order_info['weid'];
  208. $incomedata['order_id'] = $order_info['id'];
  209. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  210. $incomedata['buyer_id'] = $order_info['uid'];
  211. $incomedata['income'] = $income;
  212. $incomedata['return_percent'] = floatval($return_percent);
  213. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  214. $incomedata['order_total'] = $order_info['total'];
  215. $incomedata['pay_time'] = $order_info['pay_time'];
  216. $incomedata['month_time'] = date('m', time());
  217. $incomedata['year_time'] = date('Y', time());
  218. $incomedata['order_status_id'] = 2; //已付款
  219. TechnicalIncomelog::create($incomedata);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }