ApiStaff.Class.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <?php
  2. namespace JinDouYun\Controller\Department;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Dao\BaseDao;
  5. use JinDouYun\Dao\Customer\DCustomerCardNum;
  6. use JinDouYun\Dao\Department\DStaffReflect;
  7. use JinDouYun\Dao\Shop\DShopRostering;
  8. use JinDouYun\Dao\UserCenter\DUserCenter;
  9. use JinDouYun\Model\Customer\MCustomer;
  10. use JinDouYun\Model\Customer\MCustomerCard;
  11. use JinDouYun\Model\Department\MStaff;
  12. use JinDouYun\Model\Department\MStaffStock;
  13. use JinDouYun\Model\Shop\MShopProject;
  14. use JinDouYun\Model\Shop\MShopRostering;
  15. use JinDouYun\Model\Shop\MShopSubscribe;
  16. use JinDouYun\Model\Shop\MShopTemplate;
  17. use JinDouYun\Model\System\MBasicSetup;
  18. use Mall\Framework\Core\ErrorCode;
  19. use Mall\Framework\Core\Ding;
  20. use Mall\Framework\Factory;
  21. class ApiStaff extends BaseController
  22. {
  23. private $obj;
  24. private $objCustomer;
  25. private $objCard;
  26. private $objRostering;
  27. private $objSub;
  28. private $objStaff;
  29. private $Mrostering;
  30. private $staff;
  31. private $Mstock;
  32. private $objDStaffRewardDesc;
  33. public function __construct($isCheckAcl = true, $isMustLogin = true, $checkToken = true, $getAreaCode = false, $checkShopToken = true, $checkSupplierToken = false)
  34. {
  35. parent::__construct($isCheckAcl, $isMustLogin, $checkToken, $getAreaCode, $checkShopToken, $checkSupplierToken);
  36. $shopToken = $this->request->param('SHOP-TOKEN');
  37. if (!empty($shopToken)) {
  38. self::getShopIdByShopToken($shopToken);
  39. }
  40. $this->obj = new MShopProject($this->onlineEnterpriseId, $this->onlineUserId);
  41. $this->objCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  42. $this->objCard = new MCustomerCard($this->onlineEnterpriseId);
  43. $this->objCardNum = new DCustomerCardNum('default');
  44. $this->objRostering = new MShopRostering($this->onlineEnterpriseId, $this->onlineUserId);
  45. $this->objSub = new MShopSubscribe($this->onlineEnterpriseId, $this->onlineUserId);
  46. $this->objStaff = new MStaff($this->onlineEnterpriseId, $this->onlineUserId);
  47. $this->Mrostering = new MShopRostering($this->onlineEnterpriseId, $this->onlineUserId);
  48. $this->staff = new MStaff($this->onlineEnterpriseId, $this->onlineUserId);
  49. $this->Mstock = new MStaffStock($this->onlineEnterpriseId, $this->onlineUserId);
  50. $this->objDStaffRewardDesc = new DUserCenter('default');
  51. $this->objDStaffRewardDesc->setTable('qianniao_staff_reward_desc_' . $this->onlineEnterpriseId);
  52. }
  53. /**
  54. *排班详情
  55. * @return void
  56. */
  57. public function scheduling_details()
  58. {
  59. $param = $this->request->getRawJson();
  60. // $user = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId, 'shopId' => $this->shopId])->getData();
  61. // if (!$user) parent::sendOutput('不是该店铺店员', 1);
  62. // $staff = $this->staff->getStaffInfo(['userCenterId' => $param['uid'], 'shopId' => $this->shopId])->getData();
  63. $uid = $this->onlineUserId;
  64. // $offset = $param['offset'] ? $param['offset'] : 0;
  65. // $limit = $param['limit'] ? $param['limit'] : 100;
  66. $month = $param['month'] ? $param['month'] : date('Y-m', time());
  67. $where = [];
  68. if ($month) {
  69. $where[] = ['time', 'like', '%' . $month . '%'];
  70. }
  71. if (isset($param['export'])) {
  72. $where['export'] = $param['export'];
  73. }
  74. // $where[] = ['shop_id', '=', $this->shopId];
  75. // $staff = $this->objStaff->getStaffData(['userCenterId' => $this->onlineUserId])->getData();
  76. // if (empty($staff)) parent::sendOutput('该用户不是店员', ErrorCode::$dberror);;
  77. $where[] = ['uid', '=', $param['staffId']];
  78. $rostering = $this->Mrostering->select($where, '*', 'time DESC');
  79. if ($rostering->isSuccess()) {
  80. $returnData = $rostering->getData();
  81. parent::sendOutput($returnData['data'], 0);
  82. } else {
  83. parent::sendOutput($rostering->getData(), ErrorCode::$dberror);
  84. }
  85. }
  86. /**
  87. * 服务列表列表
  88. */
  89. public function list()
  90. {
  91. if (empty($this->onlineUserId)) parent::sendOutput('未登录', ErrorCode::$dberror);
  92. $params = $this->request->params();
  93. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  94. $selectParams['limit'] = $pageParams['limit'];
  95. $selectParams['offset'] = $pageParams['offset'];
  96. $staff = $this->objStaff->getStaffData(['userCenterId' => $this->onlineUserId])->getData();
  97. if (empty($staff)) parent::sendOutput('该用户不是店员', ErrorCode::$dberror);
  98. $selectParams['uid'] = $staff['id'];
  99. if ($this->shopId) {
  100. $selectParams['shop_id'] = $this->shopId;
  101. }
  102. //昵称
  103. if (isset($params['nickname']) && !empty($params['nickname'])) {
  104. $selectParams['nickname'] = $params['nickname'];
  105. }
  106. //uid
  107. if (isset($params['uid']) && !empty($params['uid'])) {
  108. $selectParams['uid'] = $params['uid'];
  109. }
  110. if (isset($params['type']) && !empty($params['type'])) {
  111. $selectParams['type'] = $params['type'];
  112. }
  113. $selectParams['status'] = 1;
  114. // 时间
  115. if (isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])) {
  116. $response = [];
  117. $dt_start = strtotime($params['start_time']);
  118. $dt_end = strtotime($params['end_time']);
  119. while ($dt_start <= $dt_end) {
  120. array_push($response, date('Y-m-d', $dt_start));
  121. $dt_start = strtotime('+1 day', $dt_start);
  122. }
  123. $selectParams['time'] = $response;
  124. }
  125. $result = $this->objSub->list($selectParams);
  126. if ($result->isSuccess()) {
  127. $returnData = $result->getData();
  128. $pageData = [
  129. 'pageIndex' => $params['page'],
  130. 'pageSize' => $params['pageSize'],
  131. 'pageTotal' => $returnData['total'],
  132. ];
  133. parent::sendOutput($returnData['data'], 0, $pageData);
  134. } else {
  135. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  136. }
  137. }
  138. /**
  139. * 修改预约订单,修改服务员工
  140. * @return void
  141. */
  142. public function upSubscribe()
  143. {
  144. $id = $this->request->param('id');
  145. $staffId = $this->request->param('staffId');
  146. $subscribe = $this->objSub->details(['id' => $id])->getData();
  147. $staff = $this->objStaff->getStaffData(['userCenterId' => $this->onlineUserId])->getData();
  148. if (empty($staff)) parent::sendOutput('该用户不是店员', ErrorCode::$dberror);
  149. if ($subscribe['status'] == 1) parent::sendOutput('订单已完成', ErrorCode::$dberror);
  150. if ($subscribe['uid'] == $staffId) parent::sendOutput('服务人员未变动', ErrorCode::$dberror);
  151. $res = $this->objSub->update(['uid' => $staffId], $id);
  152. if ($res) {
  153. parent::sendOutput('修改成功');
  154. }
  155. parent::sendOutput($res->getData(), ErrorCode::$dberror);
  156. }
  157. /**
  158. * 新增项目
  159. * @return void
  160. */
  161. public function addProject()
  162. {
  163. $id = $this->request->param('id');
  164. $projectId = $this->request->param('projectId');
  165. $project = $this->obj->select([['id', 'in', $projectId]]);
  166. $subscribe = $this->objSub->details(['id' => $id])->getData();
  167. if ($subscribe['status'] == 1) parent::sendOutput('订单已完成', ErrorCode::$dberror);
  168. foreach ($project as $item) {
  169. $subscribe['to_price'] += $item['price'];
  170. $subscribe['cost_price'] += $item['cost_price'];
  171. $subscribe['stay_price'] += $item['price'];
  172. }
  173. $projectIDs = array_merge(explode(',', $subscribe['project']), explode(',', $projectId));
  174. $res = $this->objSub->update(['to_price' => $subscribe['to_price'], 'cost_price' => $subscribe['cost_price'], 'stay_price' => $subscribe['stay_price'], 'project' => implode(',', $projectIDs)], $id);
  175. if ($res) {
  176. parent::sendOutput('添加成功');
  177. }
  178. parent::sendOutput($res->getData(), ErrorCode::$dberror);
  179. }
  180. /**
  181. * 订单完成
  182. * @return void
  183. */
  184. public function complete()
  185. {
  186. $params = $this->request->getRawJson();
  187. if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError);
  188. $data = $this->objSub->details(['id' => $params['id']]);
  189. if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode());
  190. $data = $data->getData();
  191. if ($data['status'] == 1) parent::sendOutput('该订单已完成', 1005);
  192. $res = $this->objSub->update(['status' => 1, 'paid' => 1, 'completeTime' => time(), 'pay_price' => $data['pay_price'] + $data['stay_price']], $params['id']);
  193. if ($res->isSuccess()) {
  194. $this->staff->stock($data['uid']); // 发放员工股份
  195. $this->staff->recommend($data, $this->shopId); // 发放客户提成
  196. $this->staff->service($data, $this->shopId); // 发放员工提成
  197. parent::sendOutput('成功');
  198. } else {
  199. parent::sendOutput($res->getData(), $res->getErrorCode());
  200. }
  201. }
  202. /**
  203. * 所有员工
  204. * @return void
  205. */
  206. public function staffAll()
  207. {
  208. $params = $this->request->params();
  209. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  210. $selectParams['limit'] = $pageParams['limit'];
  211. $selectParams['offset'] = $pageParams['offset'];
  212. // $selectParams['shopId'] = $this->shopId;
  213. $result = $this->objStaff->getAllStaff($selectParams);
  214. if ($result->isSuccess()) {
  215. $returnData = $result->getData();
  216. $pageData = [
  217. 'pageIndex' => $params['page'],
  218. 'pageSize' => $params['pageSize'],
  219. 'pageTotal' => $returnData['total'],
  220. ];
  221. parent::sendOutput($returnData['data'], 0, $pageData);
  222. } else {
  223. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  224. }
  225. }
  226. /**
  227. * 申请提现
  228. */
  229. public function addReflectDetail()
  230. {
  231. $params = $this->request->getRawJson();
  232. if (empty($params)) {
  233. $this->sendOutput('参数为空', ErrorCode::$paramError);
  234. }
  235. $ReflectDetailDate = [
  236. 'staffId' => getArrayItem($params, 'staffId', ''),
  237. 'userCenterId' => $this->onlineUserId,
  238. 'reflectType' => getArrayItem($params, 'reflectType', ''),
  239. 'money' => getArrayItem($params, 'money', ''),
  240. 'reflectInfo' => getArrayItem($params, 'reflectInfo', []),
  241. 'reflectStatus' => getArrayItem($params, 'reflectStatus', 4),
  242. 'auditStatus' => getArrayItem($params, 'auditStatus', 1),
  243. ];
  244. foreach ($ReflectDetailDate as $key => $value) {
  245. if (empty($value) && $value !== 0) {
  246. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  247. }
  248. }
  249. $ReflectDetailDate['en_id'] = $this->onlineEnterpriseId;
  250. $ReflectDetailDate['reflectInfo'] = json_encode($ReflectDetailDate['reflectInfo']);
  251. $ReflectDetailDate['remark'] = getArrayItem($params, 'remark', '');
  252. $ReflectDetailDate['createTime'] = time();
  253. $result = $this->objStaff->addReflectDetail($ReflectDetailDate);
  254. if ($result->isSuccess()) {
  255. parent::sendOutput($result->getData());
  256. } else {
  257. parent::sendOutput($result->getData(), $result->getErrorCode());
  258. }
  259. }
  260. /**
  261. * 员工提现列表
  262. * @return void
  263. */
  264. public function getWithdrawal()
  265. {
  266. $params = $this->request->params();
  267. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  268. $limit = $pageParams['limit'];
  269. $offset = $pageParams['offset'];
  270. $selectParams['en_id'] = $this->onlineEnterpriseId;
  271. $selectParams['userCenterId'] = $this->onlineUserId;
  272. if (isset($params['auditStatus']) and !empty($params['auditStatus'])) {
  273. $selectParams['auditStatus'] = $params['auditStatus'];
  274. }
  275. if (isset($params['staffId']) and !empty($params['staffId'])) {
  276. $selectParams['staffId'] = $params['staffId'];
  277. }
  278. if (isset($params['reflectStatus']) and !empty($params['reflectStatus'])) {
  279. $selectParams['reflectStatus'] = $params['reflectStatus'];
  280. }
  281. if (isset($params['end']) and !empty($params['end']) && isset($params['start']) and !empty($params['start'])) {
  282. $selectParams[] = ['createTime', '>=', strtotime($params['start'])];
  283. $selectParams[] = ['createTime', '<=', strtotime($params['end'])];
  284. }
  285. $db = new DStaffReflect('default');
  286. $list = $db->select($selectParams, '*', 'id DESC', $limit, $offset);
  287. foreach ($list as &$item) {
  288. $item['reflectInfo'] = json_decode($item['reflectInfo']);
  289. }
  290. $count = $db->count($selectParams);
  291. $pageData = [
  292. 'pageIndex' => $params['page'],
  293. 'pageSize' => $params['pageSize'],
  294. 'pageTotal' => $count,
  295. ];
  296. parent::sendOutput($list, 0, $pageData);
  297. }
  298. /**
  299. * 更新排班详情
  300. * @return void
  301. * @throws \Exception
  302. */
  303. public function update_roster()
  304. {
  305. $id = $this->request->params();
  306. $time = date('Y-m-d', time());
  307. $db = new DShopRostering('default');
  308. $db->setTable('qianniao_shop_rostering_' . $id['id']);
  309. $list = $db->select([['time', '<', $time], ['status', '=', 0]]);
  310. $MTem = new MShopTemplate($id['id']);
  311. $Mstaff = new MStaff($id['id']);
  312. foreach ($list as &$item) {
  313. $staff = $Mstaff->getStaffInfo(['id' => $item['uid']])->getData();
  314. $time_slot = json_decode($item['time_slot']);
  315. $time_count = 0;
  316. foreach ($time_slot as $item) {
  317. $time_count += count($item);
  318. }
  319. $clock = json_decode($item['clock']);
  320. if (empty($clock)) {
  321. $db->update(['status' => -1], $item['id']);
  322. } else {
  323. $price = 0;
  324. foreach ($clock as $vo) {
  325. if ($vo->timeResult == 'Normal') {
  326. $tem_price = $MTem->details(['shift_id' => $item['template_id']])->getData();
  327. $price += $tem_price['single_time'];
  328. }
  329. }
  330. if ($price > 0) {
  331. $balance = $staff['reward'] + $price;
  332. $rewardTotal = $staff['rewardTotal'] + $price;
  333. $Mstaff->clockReward($price, $balance, $staff['userCenterId'], $staff['id'], $this->shopId, $rewardTotal);
  334. }
  335. if (count($time_slot) != count($clock)) {
  336. $db->update(['status' => -1], $item['id']);
  337. }
  338. }
  339. }
  340. }
  341. public function ExaminationRecord()
  342. {
  343. $params = $this->request->params();
  344. $db = new DShopRostering('default');
  345. $db->setTable('qianniao_shop_rostering_' . $this->onlineEnterpriseId);
  346. $list = $this->objStaff->getAllStaffData([['shopId', '>', 0]])->getData();
  347. foreach ($list as &$item) {
  348. $item['abnormal'] = 0;
  349. $item['no_clocking'] = 0;
  350. $item['late'] = 0;
  351. $item['early'] = 0;
  352. $item['normal'] = 0;
  353. $item['clock_in'] = 0;
  354. $rostering = $db->select([['time', 'like', '%' . $params['month'] . '%'], ['uid', '=', $item['id']]]);
  355. foreach ($rostering as $vo) {
  356. if ($vo['time'] < date('Y-m-d H:i:s', time())) {
  357. if ($vo['status'] == -1) {
  358. $item['abnormal'] += 1; //异常天数
  359. }
  360. $time_slot = json_decode($vo['time_slot']);
  361. $time_count = 0;
  362. foreach ($time_slot as $v) {
  363. $time_count += count($v);
  364. $item['clock_in'] += count($v);//应打卡次数
  365. }
  366. $clock = json_decode($vo['clock']);
  367. if ($clock) {
  368. foreach ($clock as $vs) {
  369. if ($vs->timeResult == 'Late') {
  370. $item['late'] += 1; //迟到次数
  371. }
  372. if ($vs->timeResult == 'Early') {
  373. $item['early'] += 1; // 早退次数
  374. }
  375. if ($vs->timeResult == 'Normal') {
  376. $item['normal'] += 1; // 正常打卡次数
  377. }
  378. }
  379. $item['no_clocking'] += $time_count - count($clock);//缺卡次数
  380. } else {
  381. $item['no_clocking'] += $time_count; //缺卡次数
  382. }
  383. }
  384. }
  385. }
  386. parent::sendOutput($list);
  387. }
  388. /**
  389. * 排班详情
  390. * @return void
  391. * @throws \Exception
  392. */
  393. public function ExaminationDetails()
  394. {
  395. $params = $this->request->params();
  396. $db = new DShopRostering('default');
  397. $db->setTable('qianniao_shop_rostering_' . $this->onlineEnterpriseId);
  398. $data = $this->objStaff->getStaffInfo([['shopId', '>', 0], ['id', '=', $params['staffId']]])->getData();
  399. $data['abnormal'] = 0;
  400. $data['no_clocking'] = 0;
  401. $data['late'] = 0;
  402. $data['early'] = 0;
  403. $data['normal'] = 0;
  404. $data['clock_in'] = 0;
  405. $rostering = $db->select([['time', 'like', '%' . $params['month'] . '%'], ['uid', '=', $data['id']]]);
  406. if ($rostering) {
  407. foreach ($rostering as $vo) {
  408. if ($vo['time'] < date('Y-m-d H:i:s', time())) {
  409. if ($vo['status'] == -1) {
  410. $data['abnormal'] += 1; //异常天数
  411. }
  412. $time_slot = json_decode($vo['time_slot']);
  413. $time_count = 0;
  414. foreach ($time_slot as $v) {
  415. $time_count += count($v);
  416. $data['clock_in'] += count($v);//应打卡次数
  417. }
  418. $clock = json_decode($vo['clock']);
  419. if ($clock) {
  420. foreach ($clock as $vs) {
  421. if ($vs->timeResult == 'Late') {
  422. $data['late'] += 1; //迟到次数
  423. }
  424. if ($vs->timeResult == 'Early') {
  425. $data['early'] += 1; // 早退次数
  426. }
  427. if ($vs->timeResult == 'Normal') {
  428. $data['normal'] += 1; // 正常打卡次数
  429. }
  430. }
  431. $data['no_clocking'] += $time_count - count($clock);//缺卡次数
  432. } else {
  433. $data['no_clocking'] += $time_count; //缺卡次数
  434. }
  435. }
  436. }
  437. }
  438. parent::sendOutput($data);
  439. }
  440. /**
  441. * 员工股份列表
  442. */
  443. public function stock_list()
  444. {
  445. $params = $this->request->params();
  446. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  447. $selectParams['limit'] = $pageParams['limit'];
  448. $selectParams['offset'] = $pageParams['offset'];
  449. $staff = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId])->getData();
  450. //uid
  451. if (isset($params['name']) && !empty($params['name'])) {
  452. $selectParams['name'] = $params['name'];
  453. }
  454. if (isset($params['pm']) && !empty($params['pm'])) {
  455. $selectParams['pm'] = $params['pm'];
  456. }
  457. $selectParams['staff_id'] = $staff['id'];
  458. $result = $this->Mstock->list($selectParams);
  459. if ($result->isSuccess()) {
  460. $returnData = $result->getData();
  461. $pageData = [
  462. 'pageIndex' => $params['page'],
  463. 'pageSize' => $params['pageSize'],
  464. 'pageTotal' => $returnData['total'],
  465. ];
  466. parent::sendOutput($returnData['data'], 0, $pageData);
  467. } else {
  468. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  469. }
  470. }
  471. /**
  472. * 股权提现
  473. * @return void
  474. */
  475. public function StockWithdrawal()
  476. {
  477. $params = $this->request->params();
  478. $staff = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId])->getData();
  479. if ($staff['use_stock'] < $params['number']) {
  480. parent::sendOutput('可用余额不足', ErrorCode::$dberror);
  481. }
  482. $dbConfig = new MBasicSetup($this->onlineEnterpriseId);
  483. $config = $dbConfig->getBasicField('stock_exchange')->getData();
  484. $money = $params['number'] * $config['stock_exchange'];// 实际兑换金额
  485. $res = $this->objStaff->exchange($params['number'], $money, $staff);
  486. if ($res) {
  487. parent::sendOutput('兑换成功');
  488. }
  489. parent::sendOutput('兑换失败');
  490. }
  491. /**
  492. * 员工转介绍
  493. * @return void
  494. */
  495. public function Referral()
  496. {
  497. $params = $this->request->params();
  498. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  499. $selectParams['limit'] = $pageParams['limit'];
  500. $selectParams['offset'] = $pageParams['offset'];
  501. $staff = $this->staff->getStaffInfo(['userCenterId' => $this->onlineUserId])->getData();
  502. $list = $this->objCustomer->select(['recommenderType' => 2, 'recommenderId' => $staff['id']], $selectParams['limit'], $selectParams['offset']);
  503. $count = $this->objCustomer->count(['recommenderType' => 2, 'recommenderId' => $staff['id']]);
  504. $list = !empty($list) ? $list : [];
  505. $data = [
  506. 'count' => $count
  507. ];
  508. parent::sendOutput($list, 0, $data);
  509. }
  510. /**
  511. * 全勤奖
  512. * @return void
  513. */
  514. public function attendance()
  515. {
  516. $staff = $this->objStaff->getAllStaff(['limit' => 10000, 'offset' => 0])->getData()['data'];
  517. $setting = new MBasicSetup($this->onlineEnterpriseId);
  518. $attendance = $setting->getBasicField('attendance')->getData(); //全勤奖
  519. $start = date('Y-m-01', strtotime('-1 month'));
  520. $end = date('Y-m-t', strtotime('-1 month'));
  521. $db = new DShopRostering('default');
  522. $db->setTable('qianniao_shop_rostering_'.$this->onlineEnterpriseId);
  523. foreach ($staff as $item)
  524. {
  525. $data = $db->select([['time', '>=', $start], ['time', '<=', $end], ['uid','=', $item['id']]]);
  526. if ($data){
  527. //上个月又排班
  528. $yc = $db->select([['time', '>=', $start], ['time', '<=', $end], ['uid','=', $item['id']], ['status', '=', -1]]);//查找上个月是否有异常打卡
  529. if (empty($yc)){
  530. $balance = $item['reward'] + $attendance['attendance'];
  531. //如果没有异常打卡发放全勤奖
  532. $insertRewardDesc = [
  533. 'userCenterId' => $item['userCenterId'],
  534. 'staffId' => $item['id'],
  535. 'shopId' => $item['shopId'],
  536. 'customerId' => 0,
  537. 'title' => '发放'.date('Y-m', strtotime('-1 month')).'全勤提成',
  538. 'amount' => $attendance['attendance'],
  539. 'originId' => 0,
  540. 'changeAmount' => $balance,
  541. 'type' => 5,
  542. 'source' => 4,
  543. 'createTime' => time(),
  544. 'updateTime' => time(),
  545. ];
  546. $this->objStaff->updateStaff(['reward' => $balance], ['id' => $item['id']]);
  547. $this->objDStaffRewardDesc->insert($insertRewardDesc);
  548. }
  549. }
  550. }
  551. echo '发放成功';
  552. }
  553. }