Technical.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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['certificate_ids'] = TechnicalCertificate::getmultiple($vo['certificate_ids']) ?? '无';
  60. $vo['level'] = TechnicalLevel::getTitle($vo['level']) ?? '初级';
  61. $vo['sid'] = Store::getTitle($vo['sid']) ?? '平台';
  62. if (!empty($vo['uuid'])) {
  63. $vo['username'] = Users::getusername($vo['uuid']);
  64. }
  65. $vo['touxiang'] = toimg($vo['touxiang']);
  66. if (!empty($vo['photoalbum'])) {
  67. $vo['photoalbum'] = toimg(explode(',', $vo['photoalbum'])[0]);
  68. }
  69. $vo['region_name'] = $vo['province_name'] . $vo['city_name'] . $vo['district_name'];
  70. $vo['end_time'] = time_format($vo['end_time']) ?? '长期';
  71. $vo = RegisterField::conversion($vo);
  72. return $vo;
  73. }
  74. public static function getpcarray($sid)
  75. {
  76. $data = self::field('uuid,title')->where(['weid' => weid(), 'sid' => (int)$sid, 'status' => 1])->select()->toArray();
  77. $datalist = [];
  78. foreach ($data as $key => $vo) {
  79. if (!empty($vo['uuid'])) {
  80. $datalist[$key]['val'] = $vo['uuid'];
  81. $datalist[$key]['key'] = $vo['title'];
  82. }
  83. }
  84. return $datalist;
  85. }
  86. public static function getstaff($sid, $cate_ids, $cityName)
  87. {
  88. $query = new self;
  89. if (!empty($cate_ids)) {
  90. foreach ((array) (explode(',', $cate_ids)) as $catevo) {
  91. if ($catevo) {
  92. $query->whereOr('cate_ids', 'find in set', $catevo);
  93. }
  94. }
  95. }
  96. $orderidsarray = $query->field('id')->select()->toArray();
  97. foreach ($orderidsarray as $ovo) {
  98. if (empty($orderids)) {
  99. $orderids = $ovo['id'];
  100. } else {
  101. $orderids = $orderids . "," . $ovo['id'];
  102. }
  103. }
  104. $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]);
  105. if (!empty($sid)) {
  106. $resquery->where(['sid' => (int)$sid]);
  107. }
  108. $data = $resquery->select()->toArray();
  109. return $data;
  110. }
  111. public static function getpcarraydetailed($sid, $cate_ids, $cityName)
  112. {
  113. $data = self::getstaff($sid, $cate_ids, $cityName);
  114. $datalist = [];
  115. foreach ($data as $key => $vo) {
  116. if (!empty($vo['uuid'])) {
  117. $strlevel = TechnicalLevel::getTitle($vo['level']) ?? '初级';
  118. $datalist[$key]['val'] = $vo['uuid'];
  119. $datalist[$key]['key'] = $vo['title'] . '--[' . $strlevel . ']' . '[已接单量:' . OrderStaff::ordercount($vo['uuid']) . '][可接服务:' . Category::getmultiple($vo['cate_ids']) . ']';
  120. }
  121. }
  122. return $datalist;
  123. }
  124. public static function gelist_bycitycate($orderInfo)
  125. {
  126. $where['weid'] = weid();
  127. $where['status'] = 1;
  128. $Configdata = Config::getconfig();
  129. if (empty($Configdata['locationscope'])) {
  130. $Configdata['locationscope'] = 3;
  131. }
  132. if ($Configdata['locationscope'] == 3) {
  133. $where['district_name'] = $orderInfo['shipping_district_name'];
  134. } else if ($Configdata['locationscope'] == 2) {
  135. $where['city_name'] = $orderInfo['shipping_city_name'];
  136. } else if ($Configdata['locationscope'] == 1) {
  137. $where['province_name'] = $orderInfo['shipping_province_name'];
  138. }
  139. $query = Technical::where($where);
  140. $query->where('cate_ids', 'find in set', $orderInfo['cate_ids']);
  141. $Sort = 'id desc';
  142. $data = $query->order($Sort)->select()->toArray();
  143. return $data;
  144. }
  145. public static function getdiy_bycat($cat = 0, $count = 4, $Sort = "all", $ocid = 0)
  146. {
  147. $where['weid'] = weid();
  148. $where['status'] = 1;
  149. if ($cat > 0) {
  150. if (!empty($cat)) {
  151. $where['category_id'] = Category::getsonid($cat);
  152. }
  153. }
  154. $query = Technical::where($where);
  155. if ($ocid) {
  156. $query->where(function ($q) use ($ocid) {
  157. $Operatingcity = Operatingcity::find($ocid);
  158. if (!empty($Operatingcity)) {
  159. $Operatingcity = $Operatingcity->toArray();
  160. if (empty($Operatingcity['areatype'])) {
  161. $Operatingcity['areatype'] = 3;
  162. }
  163. if ($Operatingcity['areatype'] == 3) {
  164. $q->where('district_name', $Operatingcity['district_name'])->whereOr('district_name', '');
  165. } elseif ($Operatingcity['areatype'] == 2) {
  166. $q->where('city_name', $Operatingcity['city_name'])->whereOr('city_name', '');
  167. } elseif ($Operatingcity['areatype'] == 1) {
  168. $q->where('province_name', $Operatingcity['province_name'])->whereOr('province_name', '');
  169. }
  170. }
  171. });
  172. }
  173. if ($Sort == "all") {
  174. $Sort = 'sort asc,id desc';
  175. } elseif ($Sort == "sales") {
  176. $Sort = 'service_times desc';
  177. } elseif ($Sort == "price") {
  178. $Sort = 'create_time asc';
  179. }
  180. $data = $query->limit($count)
  181. ->order($Sort)->select()->toArray();
  182. return $data;
  183. }
  184. public static function setIncome($order_info)
  185. {
  186. $uuid = OrderStaff::getuuid($order_info['id']);
  187. if (!empty($uuid)) {
  188. $Technical = Technical::where(['uuid' => $uuid])->find();
  189. if (!empty($Technical)) {
  190. $Technical = $Technical->toArray();
  191. }
  192. if (!empty($Technical['status'])) {
  193. $percent = TechnicalLevel::getPercent($Technical['level']);
  194. if (empty($percent)) {
  195. $percent = Config::getconfig('technical')['return_percent'];
  196. }
  197. //如果是商户的师傅,分佣比较需要减去商户的佣金
  198. if (!empty($Technical['sid'])) {
  199. $Store = Store::find($Technical['sid']);
  200. if (!empty($Store)) {
  201. $Store = $Store->toArray();
  202. $storepercent = StoreCate::getPercent($Store['stid']);
  203. if (empty($storepercent)) {
  204. $storepercent = Config::getconfig('store')['return_percent'];
  205. }
  206. if (!empty($storepercent)) {
  207. $percent = $percent - $storepercent;
  208. }
  209. }
  210. }
  211. if ($percent > 0) {
  212. if (empty($order_info['cat_id'])) {
  213. $income = OrderGoods::getCommission($order_info, '', $percent);
  214. } else {
  215. $income = $order_info['total'];
  216. $income = ($income * percent_to_num($percent));
  217. }
  218. $return_percent = $percent;
  219. if ($income > 0) {
  220. if ($income > 0 && $income < 0.01) {
  221. $income = 0.01;
  222. }
  223. $TechnicalIncomelog = TechnicalIncomelog::where([
  224. 'uuid' => $uuid,
  225. 'weid' => $order_info['weid'],
  226. 'order_id' => $order_info['id'],
  227. ])->find();
  228. if (empty($TechnicalIncomelog)) {
  229. Technical::where('uuid', $uuid)->inc('income', $income)->update();
  230. Technical::where('uuid', $uuid)->inc('total_income', $income)->update();
  231. $incomedata['uuid'] = $uuid;
  232. $incomedata['ptype'] = 1;
  233. $incomedata['weid'] = $order_info['weid'];
  234. $incomedata['order_id'] = $order_info['id'];
  235. $incomedata['order_num_alias'] = $order_info['order_num_alias'];
  236. $incomedata['buyer_id'] = $order_info['uid'];
  237. $incomedata['income'] = $income;
  238. $incomedata['return_percent'] = floatval($return_percent);
  239. $incomedata['percentremark'] = $order_info['total'] . '% x' . $percent . '%';
  240. $incomedata['order_total'] = $order_info['total'];
  241. $incomedata['pay_time'] = $order_info['pay_time'];
  242. $incomedata['month_time'] = date('m', time());
  243. $incomedata['year_time'] = date('Y', time());
  244. $incomedata['order_status_id'] = 2; //已付款
  245. TechnicalIncomelog::create($incomedata);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }